Inject dependencies into tornado app
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@@ -1,9 +1,19 @@
|
||||
import pytest
|
||||
|
||||
from atst.app import make_app, make_config
|
||||
from atst.app import make_app, make_deps, make_config
|
||||
from tests.mocks import MockApiClient
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
TEST_DEPS = {
|
||||
'authz_client': MockApiClient('authz'),
|
||||
'requests_client': MockApiClient('requests'),
|
||||
'authnid_client': MockApiClient('authnid'),
|
||||
}
|
||||
|
||||
config = make_config()
|
||||
return make_app(config)
|
||||
deps = make_deps(config)
|
||||
deps.update(TEST_DEPS)
|
||||
|
||||
return make_app(config, deps)
|
||||
|
32
tests/mocks.py
Normal file
32
tests/mocks.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import tornado.gen
|
||||
from tornado.httpclient import HTTPRequest, HTTPResponse
|
||||
|
||||
|
||||
class MockApiClient(object):
|
||||
def __init__(self, service):
|
||||
self.service = service
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def get(self, path, **kwargs):
|
||||
return self._get_response('GET', path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def put(self, path, **kwargs):
|
||||
return self._get_response('PUT', path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def patch(self, path, **kwargs):
|
||||
return self._get_response('PATCH', path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def post(self, path, **kwargs):
|
||||
return self._get_response('POST', path)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def delete(self, path, **kwargs):
|
||||
return self._get_response('DELETE', path)
|
||||
|
||||
def _get_response(self, verb, path):
|
||||
response = HTTPResponse(request=HTTPRequest(path, verb), code=200)
|
||||
setattr(response, 'json', {})
|
||||
return response
|
Reference in New Issue
Block a user