Skip to content

Commit

Permalink
move get_test_dbconf to be a shared test helper. use in both metadata…
Browse files Browse the repository at this point in the history
… and ui_backend service tests
  • Loading branch information
saikonen authored and savingoyal committed Oct 27, 2021
1 parent 74bea7c commit a065407
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
14 changes: 1 addition & 13 deletions services/metadata_service/tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from aiohttp import web
from services.data.postgres_async_db import AsyncPostgresDB
from services.utils import DBConfiguration
from services.utils.tests import get_test_dbconf
from services.metadata_service.api.admin import AuthApi
from services.metadata_service.api.flow import FlowApi
from services.metadata_service.api.run import RunApi
Expand All @@ -22,18 +22,6 @@
# Test fixture helpers begin


def get_test_dbconf():
"Returns a DBConfiguration suitable for the test environment, or exits pytest completely upon failure"
db_conf = DBConfiguration()

if db_conf.dsn != "dbname=test user=test host=db_test port=5432 password=test":
pytest.exit("The test suite should only be run in a test environment. \n \
Configured database host is not suited for running tests. \n \
expected DSN to be: dbname=test user=test host=db_test port=5432 password=test")

return db_conf


def init_app(loop, aiohttp_client, queue_ttl=30):
app = web.Application()

Expand Down
6 changes: 3 additions & 3 deletions services/ui_backend_service/tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from services.ui_backend_service.data.db import AsyncPostgresDB
from services.ui_backend_service.data.cache.store import CacheStore
from services.utils import DBConfiguration
from services.utils.tests import get_test_dbconf

from services.ui_backend_service.api import (
FlowApi, RunApi, StepApi, TaskApi,
Expand Down Expand Up @@ -43,7 +43,7 @@ def init_app(loop, aiohttp_client, queue_ttl=30):

# init a db adapter explicitly to be used for the api requests.
# Skip all creation processes, these are handled with migration service and init_db
db_conf = DBConfiguration(timeout=1)
db_conf = get_test_dbconf()
db = AsyncPostgresDB(name='api')
loop.run_until_complete(db._init(db_conf=db_conf, create_tables=False, create_triggers=False))

Expand All @@ -69,7 +69,7 @@ def init_app(loop, aiohttp_client, queue_ttl=30):


async def init_db(cli):
db_conf = DBConfiguration(timeout=1)
db_conf = get_test_dbconf()

# Make sure migration scripts are applied
migration_db = MigrationAsyncPostgresDB.get_instance()
Expand Down
16 changes: 16 additions & 0 deletions services/utils/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from services.utils import DBConfiguration
import pytest


def get_test_dbconf():
"""
Returns a DBConfiguration suitable for the test environment, or exits pytest completely upon failure
"""
db_conf = DBConfiguration(timeout=1)

if db_conf.dsn != "dbname=test user=test host=db_test port=5432 password=test":
pytest.exit("The test suite should only be run in a test environment. \n \
Configured database host is not suited for running tests. \n \
expected DSN to be: dbname=test user=test host=db_test port=5432 password=test")

return db_conf

0 comments on commit a065407

Please sign in to comment.