Skip to content

Commit a7d72c9

Browse files
committed
refactor catalog
1 parent 3938d76 commit a7d72c9

File tree

2 files changed

+284
-310
lines changed

2 files changed

+284
-310
lines changed

tests/base_test.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,54 @@ def mocked_login_post(*args, **kwargs):
118118

119119
@six.add_metaclass(abc.ABCMeta)
120120
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 {}.\nDid 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+
121169
def setUp(self):
122170
file_data = dedent(
123171
"""[default]

0 commit comments

Comments
 (0)