mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
reformat
This commit is contained in:
@@ -10,14 +10,14 @@ from app import create_app
|
||||
from app.dao.provider_details_dao import get_provider_details_by_identifier
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@pytest.fixture(scope="session")
|
||||
def notify_app():
|
||||
app = Flask('test')
|
||||
app = Flask("test")
|
||||
create_app(app)
|
||||
return app
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@pytest.fixture(scope="session")
|
||||
def notify_api(notify_app):
|
||||
for error_handlers in notify_app.error_handler_spec.values():
|
||||
error_handlers.pop(500, None)
|
||||
@@ -38,33 +38,34 @@ def notify_api(notify_app):
|
||||
ctx.pop()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def client(notify_api):
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@pytest.fixture(scope="session")
|
||||
def _notify_db(notify_api):
|
||||
"""
|
||||
Manages the connection to the database. Generally this shouldn't be used, instead you should use the
|
||||
`notify_db_session` fixture which also cleans up any data you've got left over after your test run.
|
||||
"""
|
||||
with notify_api.app_context() as app_context:
|
||||
db = app_context.app.extensions['sqlalchemy']
|
||||
assert 'test_notification_api' in db.engine.url.database, 'dont run tests against main db'
|
||||
db = app_context.app.extensions["sqlalchemy"]
|
||||
assert (
|
||||
"test_notification_api" in db.engine.url.database
|
||||
), "dont run tests against main db"
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
ALEMBIC_CONFIG = os.path.join(BASE_DIR, 'migrations')
|
||||
config = Config(ALEMBIC_CONFIG + '/alembic.ini')
|
||||
config.set_main_option('script_location', ALEMBIC_CONFIG)
|
||||
ALEMBIC_CONFIG = os.path.join(BASE_DIR, "migrations")
|
||||
config = Config(ALEMBIC_CONFIG + "/alembic.ini")
|
||||
config.set_main_option("script_location", ALEMBIC_CONFIG)
|
||||
config.set_main_option(
|
||||
'sqlalchemy.url',
|
||||
app_context.app.config['SQLALCHEMY_DATABASE_URI']
|
||||
"sqlalchemy.url", app_context.app.config["SQLALCHEMY_DATABASE_URI"]
|
||||
)
|
||||
|
||||
# Run migrations on the test database.
|
||||
upgrade(config, 'head')
|
||||
upgrade(config, "head")
|
||||
|
||||
yield db
|
||||
|
||||
@@ -72,17 +73,17 @@ def _notify_db(notify_api):
|
||||
db.engine.dispose()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sms_providers(_notify_db):
|
||||
"""
|
||||
In production we randomly choose which provider to use based on their priority. To guarantee tests run the same each
|
||||
time, make sure we always choose sns. You'll need to override them in your tests if you wish to do something
|
||||
different.
|
||||
"""
|
||||
get_provider_details_by_identifier('sns').priority = 100
|
||||
get_provider_details_by_identifier("sns").priority = 100
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def notify_db_session(_notify_db, sms_providers):
|
||||
"""
|
||||
This fixture clears down all non static data after your test run. It yields the sqlalchemy session variable
|
||||
@@ -94,19 +95,21 @@ def notify_db_session(_notify_db, sms_providers):
|
||||
|
||||
_notify_db.session.remove()
|
||||
for tbl in reversed(_notify_db.metadata.sorted_tables):
|
||||
if tbl.name not in ["provider_details",
|
||||
"key_types",
|
||||
"branding_type",
|
||||
"job_status",
|
||||
"provider_details_history",
|
||||
"template_process_type",
|
||||
"notifications_all_time_view",
|
||||
"notification_status_types",
|
||||
"organization_types",
|
||||
"service_permission_types",
|
||||
"auth_type",
|
||||
"invite_status_type",
|
||||
"service_callback_type"]:
|
||||
if tbl.name not in [
|
||||
"provider_details",
|
||||
"key_types",
|
||||
"branding_type",
|
||||
"job_status",
|
||||
"provider_details_history",
|
||||
"template_process_type",
|
||||
"notifications_all_time_view",
|
||||
"notification_status_types",
|
||||
"organization_types",
|
||||
"service_permission_types",
|
||||
"auth_type",
|
||||
"invite_status_type",
|
||||
"service_callback_type",
|
||||
]:
|
||||
_notify_db.engine.execute(tbl.delete())
|
||||
_notify_db.session.commit()
|
||||
|
||||
@@ -130,7 +133,7 @@ def os_environ():
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
# Copied from https://gist.github.com/pfctdayelise/5719730
|
||||
idparametrize = metafunc.definition.get_closest_marker('idparametrize')
|
||||
idparametrize = metafunc.definition.get_closest_marker("idparametrize")
|
||||
if idparametrize:
|
||||
argnames, testdata = idparametrize.args
|
||||
ids, argvalues = zip(*sorted(testdata.items()))
|
||||
@@ -171,4 +174,4 @@ class Matcher:
|
||||
return self.key(other)
|
||||
|
||||
def __repr__(self):
|
||||
return '<Matcher: {}>'.format(self.description)
|
||||
return "<Matcher: {}>".format(self.description)
|
||||
|
||||
Reference in New Issue
Block a user