mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
use sqlalchemy hooks rather than pyscopg2
seems to play nicer with docker?
This commit is contained in:
@@ -30,6 +30,6 @@ fi
|
|||||||
pycodestyle .
|
pycodestyle .
|
||||||
display_result $? 1 "Code style check"
|
display_result $? 1 "Code style check"
|
||||||
|
|
||||||
# run with six concurrent threads
|
# run with four concurrent threads
|
||||||
py.test --cov=app --cov-report=term-missing tests/ --junitxml=test_results.xml -n 6
|
py.test --cov=app --cov-report=term-missing tests/ --junitxml=test_results.xml -n 4
|
||||||
display_result $? 2 "Unit tests"
|
display_result $? 2 "Unit tests"
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ from alembic.command import upgrade
|
|||||||
from alembic.config import Config
|
from alembic.config import Config
|
||||||
from flask_migrate import Migrate, MigrateCommand
|
from flask_migrate import Migrate, MigrateCommand
|
||||||
from flask_script import Manager
|
from flask_script import Manager
|
||||||
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
|
|
||||||
import boto3
|
import boto3
|
||||||
import psycopg2
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
from app import create_app, db
|
from app import create_app, db
|
||||||
|
|
||||||
@@ -48,19 +47,24 @@ def client(notify_api):
|
|||||||
|
|
||||||
|
|
||||||
def create_test_db(database_uri):
|
def create_test_db(database_uri):
|
||||||
database_name = database_uri.split('/')[-1]
|
# get the
|
||||||
system_db = psycopg2.connect(dbname='postgres')
|
db_uri_parts = database_uri.split('/')
|
||||||
system_db.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
|
postgres_db_uri = '/'.join(db_uri_parts[:-1] + ['postgres'])
|
||||||
cursor = system_db.cursor()
|
|
||||||
|
|
||||||
|
postgres_db = sqlalchemy.create_engine(
|
||||||
|
postgres_db_uri,
|
||||||
|
echo=False,
|
||||||
|
isolation_level='AUTOCOMMIT',
|
||||||
|
client_encoding='utf8'
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
cursor.execute('CREATE DATABASE {}'.format(database_name))
|
result = postgres_db.execute(sqlalchemy.sql.text('CREATE DATABASE {}'.format(db_uri_parts[-1])))
|
||||||
except psycopg2.ProgrammingError:
|
result.close()
|
||||||
# database "test_notification_api_x..." already exists
|
except sqlalchemy.exc.ProgrammingError:
|
||||||
|
# database "test_notification_api_master" already exists
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
postgres_db.dispose()
|
||||||
system_db.close()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
|||||||
Reference in New Issue
Block a user