Files
notifications-admin/tests/conftest.py
Rebecca Law abe1d8ae17 108536234: created users and roles data and domain model.
You will need to run the /scripts/bootstrap.sh to create the database for test and the app.
2015-11-25 15:29:12 +00:00

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()