mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 17:52:26 -05:00
Ideally all the primary keys in the db would be UUID in order to guarantee unique ids across distributed dbs. This updates the services.id to a UUID. All the tables with a foreign key to the services.id are also updated. The endpoints no longer state a data type of the <service_id> path param. All the tests are updated to reflect this update. The thing to pay attention to is the 0011_uuid_service_id.py migration script. This commit must go with a commit on the notifications_admin app to keep things working. There will be a small outage until both deploys have happened.
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
import pytest
|
|
import mock
|
|
import os
|
|
from config import configs
|
|
from alembic.command import upgrade
|
|
from alembic.config import Config
|
|
from flask.ext.migrate import Migrate, MigrateCommand
|
|
from flask.ext.script import Manager
|
|
from sqlalchemy.schema import MetaData
|
|
from app import create_app, db
|
|
from app import models
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
def notify_api(request):
|
|
app = create_app('test')
|
|
ctx = app.app_context()
|
|
ctx.push()
|
|
|
|
def teardown():
|
|
ctx.pop()
|
|
|
|
request.addfinalizer(teardown)
|
|
return app
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
def notify_db(notify_api, request):
|
|
Migrate(notify_api, db)
|
|
Manager(db, MigrateCommand)
|
|
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)
|
|
|
|
with notify_api.app_context():
|
|
upgrade(config, 'head')
|
|
|
|
def teardown():
|
|
db.session.remove()
|
|
db.engine.execute("drop sequence services_id_seq cascade")
|
|
db.drop_all()
|
|
db.engine.execute("drop table alembic_version")
|
|
db.get_engine(notify_api).dispose()
|
|
|
|
request.addfinalizer(teardown)
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
def notify_db_session(request):
|
|
def teardown():
|
|
db.session.remove()
|
|
for tbl in reversed(meta.sorted_tables):
|
|
if tbl.fullname not in ['roles']:
|
|
db.engine.execute(tbl.delete())
|
|
|
|
meta = MetaData(bind=db.engine, reflect=True)
|
|
request.addfinalizer(teardown)
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
def notify_config(notify_api):
|
|
notify_api.config['NOTIFY_API_ENVIRONMENT'] = 'test'
|
|
notify_api.config.from_object(configs['test'])
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
def os_environ(request):
|
|
env_patch = mock.patch('os.environ', {})
|
|
request.addfinalizer(env_patch.stop)
|
|
|
|
return env_patch.start()
|