-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from xsnippet/decouple
Use DI to inject database/conf where needed
- Loading branch information
Showing
14 changed files
with
182 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Some pytest fixtures used around the code.""" | ||
|
||
import picobox | ||
import pkg_resources | ||
import pytest | ||
|
||
from xsnippet.api.application import create_app | ||
from xsnippet.api.conf import get_conf | ||
from xsnippet.api.database import create_connection | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def testconf(): | ||
path = pkg_resources.resource_filename('xsnippet.api', 'default.conf') | ||
conf = get_conf(path) | ||
conf['auth'] = {'secret': 'SWORDFISH'} | ||
|
||
# This flag exist to workaround permissions (which we currently lack of) | ||
# and test PUT/PATCH requests to the snippet. Once permissions are | ||
# implemented and the hack is removed from @checkpermissions decorator | ||
# in resources/snippets.py - this silly flag must be thrown away. | ||
conf['test'] = {'sudo': True} | ||
return conf | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
async def testdatabase(request, loop, testconf): | ||
database = create_connection(testconf) | ||
|
||
# Python 3.5 does not support yield statement inside coroutines, hence we | ||
# cannot use yield fixtures here and are forced to use finalizers instead. | ||
request.addfinalizer(lambda: loop.run_until_complete(database.client.drop_database(database))) | ||
return database | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
async def testapp(request, test_client, testconf, testdatabase): | ||
box = picobox.Box() | ||
box.put('conf', testconf) | ||
box.put('database', testdatabase) | ||
|
||
scope = picobox.push(box) | ||
scope.__enter__() | ||
|
||
# Python 3.5 does not support yield statement inside coroutines, hence we | ||
# cannot use yield fixtures here and are forced to use finalizers instead. | ||
# This is especially weird as Picobox provides convenient context manager | ||
# and no plain functions, that's why manual triggering is required. | ||
request.addfinalizer(lambda: scope.__exit__(None, None, None)) | ||
return await test_client(create_app()) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.