File tree Expand file tree Collapse file tree 2 files changed +284
-310
lines changed Expand file tree Collapse file tree 2 files changed +284
-310
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,54 @@ def mocked_login_post(*args, **kwargs):
118
118
119
119
@six .add_metaclass (abc .ABCMeta )
120
120
class BaseTestCase (unittest .TestCase ):
121
+
122
+ _http_get_handlers = {}
123
+ _http_post_handlers = {}
124
+
125
+ @classmethod
126
+ def httpPostHandlers (cls , * args , ** kwargs ):
127
+ return BaseTestCase ._http_post_handlers [args [0 ]]
128
+
129
+ @classmethod
130
+ def httpGetHandlers (cls , * args , ** kwargs ):
131
+ try :
132
+ handler = BaseTestCase ._http_get_handlers [args [0 ]]
133
+ except KeyError as e :
134
+ raise Exception (
135
+ "Handler not found for GET {}.\n Did you register a handler with BaseTestCase.registerHttpGetHandler?" .format (
136
+ args [0 ]
137
+ )
138
+ )
139
+
140
+ if isinstance (handler , Exception ):
141
+ raise handler
142
+ else :
143
+ return handler
144
+
145
+ @classmethod
146
+ def registerHttpPostHandler (cls , url , response ):
147
+ BaseTestCase ._http_post_handlers [url ] = response
148
+
149
+ @classmethod
150
+ def registerHttpGetHandler (cls , url , response ):
151
+ BaseTestCase ._http_get_handlers [url ] = response
152
+
153
+ @classmethod
154
+ def setUpClass (cls ):
155
+ # Register the login handler
156
+ BaseTestCase .registerHttpPostHandler (
157
+ "https://127.0.0.1:8080/api/v1/login" ,
158
+ MockResponse (
159
+ json_data = {},
160
+ status_code = 200 ,
161
+ headers = {
162
+ "location" : (
163
+ "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
164
+ )
165
+ },
166
+ ),
167
+ )
168
+
121
169
def setUp (self ):
122
170
file_data = dedent (
123
171
"""[default]
You can’t perform that action at this time.
0 commit comments