mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-12 16:14:56 -05:00
You will need to run the /scripts/bootstrap.sh to create the database for test and the app.
40 lines
940 B
Python
40 lines
940 B
Python
import pytest
|
|
from sqlalchemy.schema import MetaData, DropConstraint
|
|
|
|
from app import create_app, db
|
|
from app.models import Roles
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def notifications_admin(request):
|
|
app = create_app('test')
|
|
ctx = app.app_context()
|
|
ctx.push()
|
|
|
|
def teardown():
|
|
ctx.pop()
|
|
|
|
request.addfinalizer(teardown)
|
|
return app
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def notifications_admin_db(notifications_admin, request):
|
|
metadata = MetaData(db.engine)
|
|
metadata.reflect()
|
|
for table in metadata.tables.values():
|
|
for fk in table.foreign_keys:
|
|
db.engine.execute(DropConstraint(fk.constraint))
|
|
metadata.drop_all()
|
|
|
|
# Create the tables based on the current model
|
|
db.create_all()
|
|
|
|
# Add base data here
|
|
role = Roles(id=1, role='test_role')
|
|
db.session.add(role)
|
|
db.session.commit()
|
|
db.session.flush()
|
|
db.session.expunge_all()
|
|
db.session.commit()
|