Added sqlalchemy-utils and put methods in to

create and delete the test_notifications_api db
before and after the tests run.
This commit is contained in:
Anastasia Gradova
2024-04-10 19:57:53 -06:00
parent feaa4e0592
commit 0bb80c9d22
3 changed files with 39 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import pytest
from alembic.command import upgrade
from alembic.config import Config
from flask import Flask
from sqlalchemy_utils import database_exists, create_database, drop_database
from app import create_app
from app.dao.provider_details_dao import get_provider_details_by_identifier
@@ -52,9 +53,10 @@ def _notify_db(notify_api):
"""
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"
# Check if test_notification_api exists, if not, create
if not database_exists(db.engine.url):
create_database(db.engine.url)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ALEMBIC_CONFIG = os.path.join(BASE_DIR, "migrations")
@@ -70,6 +72,9 @@ def _notify_db(notify_api):
yield db
db.session.remove()
# Check if test_notification_api exists, if so, drop
if database_exists(db.engine.url):
drop_database(db.engine.url)
db.engine.dispose()