Inject dependencies into tornado app

This commit is contained in:
richard-dds
2018-06-18 10:44:06 -04:00
parent 6eb71cfe63
commit 64c71c0aa7
6 changed files with 65 additions and 12 deletions

0
tests/__init__.py Normal file
View File

View 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
View 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