Skip to content

Commit ea6fa26

Browse files
author
Kevin Hellemun
committed
Added base test class. (#40)
1 parent 5647827 commit ea6fa26

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

tests/model/generated/object/__init__.py

Whitespace-only changes.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import json
2+
import os
3+
4+
from tests import bunq_test
5+
from bunq.sdk.model.generated import object_
6+
from bunq.sdk.model.generated import endpoint
7+
from bunq.sdk.json.converter import json_to_class
8+
9+
10+
class TestNotificationUrl(bunq_test.BunqSdkTestCase):
11+
# Getter string constants
12+
_GET_PAYMENT = 'Payment'
13+
_GET_BUNQ_ME_TAB = 'BunqMeTab'
14+
_GET_CHAT_MESSAGE_ANNOUNCEMENT = 'ChatMessageAnnouncement'
15+
_GET_DRAFT_PAYMENT = 'DraftPayment'
16+
_GET_MASTER_CARD_ACTION = 'MasterCardAction'
17+
_GET_MONETARY_ACCOUNT_BANK = 'MonetaryAccountBank'
18+
_GET_PAYMENT_BATCH = 'PaymentBatch'
19+
_GET_REQUEST_INQUIRY = 'RequestInquiry'
20+
_GET_REQUEST_RESPONSE = 'RequestResponse'
21+
_GET_SCHEDULE_PAYMENT = 'ScheduledPayment'
22+
_GET_SCHEDULE_INSTANCE = 'ScheduledInstance'
23+
_GET_SHARE_INVITE_BANK_INQUIRY = 'ShareInviteBankInquiry'
24+
_GET_SHARE_INVITE_BANK_RESPONSE = 'ShareInviteBankResponse'
25+
26+
# Assertion errors
27+
_ASSERT_SHOULD_NOT_REACH_THIS_CODE_ERROR = \
28+
'Something super weird just happen'
29+
_ASSERT_JSON_DECODE_ERROR = \
30+
'Might be that the JSON file is not a valid json.'
31+
_ASSERT_OBJECT_IS_NULL_ERROR = 'Object seems to be null.'
32+
33+
# Model json paths constants.
34+
BASE_PATH_JSON_MODEL = '../../../assets/NotficationUrlJsons'
35+
JSON_PATH_MUTATION_MODEL = BASE_PATH_JSON_MODEL + '/Mutation.json'
36+
JSON_PATH_BUNQ_ME_TAB_MODEL = BASE_PATH_JSON_MODEL + '/BunqMeTab.json'
37+
JSON_PATH_CHAT_MESSAGE_ANNOUNCEMENT_MODEL = \
38+
BASE_PATH_JSON_MODEL + '/ChatMessageAnnouncement.json'
39+
JSON_PATH_DRAFT_PAYMENT_MODEL = BASE_PATH_JSON_MODEL + '/DraftPayment.json'
40+
JSON_PATH_MASTER_CARD_ACTION_MODEL = \
41+
BASE_PATH_JSON_MODEL + '/MasterCardAction.json'
42+
JSON_PATH_MONETARY_ACCOUNT_BANK_MODEL = \
43+
BASE_PATH_JSON_MODEL + '/MonetaryAccountBank.json'
44+
JSON_PATH_PAYMENT_BATCH_MODEL = \
45+
BASE_PATH_JSON_MODEL + '/PaymentBatch.json'
46+
JSON_PATH_REQUEST_INQUIRY_MODEL = \
47+
BASE_PATH_JSON_MODEL + '/RequestInquiry.json'
48+
JSON_PATH_REQUEST_RESPONSE_MODEL = \
49+
BASE_PATH_JSON_MODEL + '/RequestResponse.json'
50+
JSON_PATH_SCHEDULE_PAYMENT_MODEL = \
51+
BASE_PATH_JSON_MODEL + '/ScheduledPayment.json'
52+
JSON_PATH_SCHEDULE_INSTANCE_MODEL = \
53+
BASE_PATH_JSON_MODEL + '/ScheduledInstance.json'
54+
JSON_PATH_SHARE_INVITE_BANK_INQUIRY_MODEL = \
55+
BASE_PATH_JSON_MODEL + '/ShareInviteBankInquiry.json'
56+
JSON_PATH_SHARE_INVITE_BANK_RESPONSE_MODEL = \
57+
BASE_PATH_JSON_MODEL + '/ShareInviteBankResponse.json'
58+
59+
# Model root key.
60+
_KEY_NOTIFICATION_URL_MODEL = 'NotificationUrl'
61+
62+
def execute_test(self, file_path, class_name, getter_name):
63+
"""
64+
:type file_path: str
65+
:type class_name: str
66+
:type getter_name: str
67+
68+
:return: None
69+
"""
70+
71+
notification_url = self.getNotificationUrl(file_path)
72+
self.assertIsNotNone(notification_url)
73+
self.assertIsNotNone(notification_url.object_)
74+
75+
expected_model = getattr(notification_url.object_, getter_name)
76+
referenced_model = notification_url.object_.get_referenced_object()
77+
78+
self.assertIsNotNone(expected_model)
79+
self.assertIsNotNone(referenced_model)
80+
self.assertTrue(
81+
self.assertInstanceOfReferencedObject(
82+
referenced_model,
83+
class_name
84+
)
85+
or
86+
self.assertInstanceOfReferencedEndpoint(
87+
referenced_model,
88+
class_name
89+
)
90+
)
91+
92+
@staticmethod
93+
def assertInstanceOfReferencedObject(referenced_model, class_name):
94+
try:
95+
return isinstance(referenced_model, getattr(object_, class_name))
96+
except AttributeError:
97+
return False
98+
99+
@staticmethod
100+
def assertInstanceOfReferencedEndpoint(referenced_model, class_name):
101+
try:
102+
return isinstance(referenced_model, getattr(endpoint, class_name))
103+
except AttributeError:
104+
return False
105+
106+
def getNotificationUrl(self, file_path):
107+
"""
108+
:type file_path: str
109+
110+
:rtype: object_.NotificationUrl
111+
"""
112+
113+
base_path = os.path.dirname(__file__)
114+
file_path = os.path.abspath(os.path.join(base_path, file_path))
115+
116+
with open(file_path, 'r') as f:
117+
json_string = f.read()
118+
json_object = json.loads(json_string)
119+
json_string = json.dumps(json_object[
120+
self._KEY_NOTIFICATION_URL_MODEL
121+
])
122+
123+
self.assertTrue(
124+
self._KEY_NOTIFICATION_URL_MODEL in json_object
125+
)
126+
127+
return json_to_class(
128+
object_.NotificationUrl,
129+
json_string
130+
)
131+

0 commit comments

Comments
 (0)