1
1
import json
2
2
import os
3
3
4
- from tests import bunq_test
5
- from bunq .sdk .model .generated import object_
6
- from bunq .sdk .model .generated import endpoint
7
4
from bunq .sdk .json .converter import json_to_class
5
+ from bunq .sdk .model .generated import endpoint
6
+ from bunq .sdk .model .generated import object_
7
+ from tests import bunq_test
8
8
9
9
10
10
class TestNotificationUrl (bunq_test .BunqSdkTestCase ):
@@ -52,6 +52,15 @@ class TestNotificationUrl(bunq_test.BunqSdkTestCase):
52
52
# Model root key.
53
53
_KEY_NOTIFICATION_URL_MODEL = 'NotificationUrl'
54
54
55
+ # Model modules constants.
56
+ _MODEL_MODULES = [
57
+ object_ ,
58
+ endpoint ,
59
+ ]
60
+
61
+ # File mode constants.
62
+ _FILE_MODE_READ = 'r'
63
+
55
64
def execute_notification_url_test (self ,
56
65
file_path ,
57
66
class_name ,
@@ -74,17 +83,29 @@ def execute_notification_url_test(self,
74
83
self .assertIsNotNone (expected_model )
75
84
self .assertIsNotNone (referenced_model )
76
85
self .assertTrue (
77
- self .assertInstanceOfReferencedObject (
78
- referenced_model ,
79
- class_name
80
- )
81
- or
82
- self .assertInstanceOfReferencedEndpoint (
86
+ self .isModelReference (
83
87
referenced_model ,
84
88
class_name
85
89
)
86
90
)
87
91
92
+ @classmethod
93
+ def isModelReference (cls , referenced_model , class_name ):
94
+ model_class = cls .getModelClassOrNone (class_name )
95
+
96
+ if model_class is None :
97
+ return False
98
+
99
+ return isinstance (referenced_model , model_class )
100
+
101
+ @classmethod
102
+ def getModelClassOrNone (cls , class_name ):
103
+ for module_ in cls ._MODEL_MODULES :
104
+ if hasattr (module_ , class_name ):
105
+ return getattr (module_ , class_name )
106
+
107
+ return None
108
+
88
109
@staticmethod
89
110
def assertInstanceOfReferencedObject (referenced_model , class_name ):
90
111
try :
@@ -109,12 +130,12 @@ def getNotificationUrl(self, file_path):
109
130
base_path = os .path .dirname (__file__ )
110
131
file_path = os .path .abspath (os .path .join (base_path , file_path ))
111
132
112
- with open (file_path , 'r' ) as f :
133
+ with open (file_path , self . _FILE_MODE_READ ) as f :
113
134
json_string = f .read ()
114
135
json_object = json .loads (json_string )
115
- json_string = json .dumps (json_object [
116
- self ._KEY_NOTIFICATION_URL_MODEL
117
- ] )
136
+ json_string = json .dumps (
137
+ json_object [ self ._KEY_NOTIFICATION_URL_MODEL ]
138
+ )
118
139
119
140
self .assertTrue (
120
141
self ._KEY_NOTIFICATION_URL_MODEL in json_object
0 commit comments