mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
109526036: Persist the verify code to the db.
The codes are hashed and saved to the db. The code is marked as used once a valid code is submitted. The code is valid for 1 hour. The codes are no longer saved to the session.
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from _pytest.monkeypatch import monkeypatch
|
||||
from sqlalchemy.schema import MetaData, DropConstraint
|
||||
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.models import Roles
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope='session')
|
||||
def notifications_admin(request):
|
||||
app = create_app('test')
|
||||
|
||||
ctx = app.app_context()
|
||||
ctx.push()
|
||||
|
||||
@@ -19,22 +24,34 @@ def notifications_admin(request):
|
||||
return app
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope='session')
|
||||
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()
|
||||
Migrate(notifications_admin, 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)
|
||||
|
||||
# Create the tables based on the current model
|
||||
db.create_all()
|
||||
with notifications_admin.app_context():
|
||||
upgrade(config, 'head')
|
||||
|
||||
# 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()
|
||||
def teardown():
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
db.engine.execute("drop table alembic_version")
|
||||
db.get_engine(notifications_admin).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)
|
||||
|
||||
Reference in New Issue
Block a user