Add MockRequestsClient
This commit is contained in:
parent
26176bc0a2
commit
92086a898f
@ -1,14 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from atst.app import make_app, make_deps, make_config
|
||||
from tests.mocks import MockApiClient
|
||||
from tests.mocks import MockApiClient, MockRequestsClient
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
TEST_DEPS = {
|
||||
'authz_client': MockApiClient('authz'),
|
||||
'requests_client': MockApiClient('requests'),
|
||||
'requests_client': MockRequestsClient('requests'),
|
||||
'authnid_client': MockApiClient('authnid'),
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,35 @@ class MockApiClient(ApiClient):
|
||||
def delete(self, path, **kwargs):
|
||||
return self._get_response('DELETE', path)
|
||||
|
||||
def _get_response(self, verb, path):
|
||||
def _get_response(self, verb, path, code=200, json=None):
|
||||
response = HTTPResponse(
|
||||
request=HTTPRequest(path, verb),
|
||||
code=200,
|
||||
code=code,
|
||||
headers={'Content-Type': 'application/json'})
|
||||
return self.adapt_response(response)
|
||||
|
||||
setattr(response, 'ok', 200 <= code < 300)
|
||||
if json:
|
||||
setattr(response, 'json', json)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
class MockRequestsClient(MockApiClient):
|
||||
@tornado.gen.coroutine
|
||||
def get(self, path, **kwargs):
|
||||
json = {
|
||||
'id': '66b8ef71-86d3-48ef-abc2-51bfa1732b6b',
|
||||
'creator': '49903ae7-da4a-49bf-a6dc-9dff5d004238',
|
||||
'body': {}
|
||||
}
|
||||
return self._get_response('GET', path, 200, json=json)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self, path, **kwargs):
|
||||
json = {
|
||||
'id': '66b8ef71-86d3-48ef-abc2-51bfa1732b6b',
|
||||
'creator': '49903ae7-da4a-49bf-a6dc-9dff5d004238',
|
||||
'body': {}
|
||||
}
|
||||
return self._get_response('POST', path, 202, json=json)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user