-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
38 lines (28 loc) · 1.06 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from unittest import TestCase
from alembic import command as alembic_command
from alembic.config import Config as AlembicConfig
from api_boilerplate.app import create_app
from api_boilerplate.utils.db import wait_for_db
class BaseTestCase(TestCase):
pass
class AppContextTestCase(BaseTestCase):
def setUp(self) -> None:
super().setUp()
self.app = create_app()
self.client = self.app.test_client()
class DbContextTestCase(AppContextTestCase):
def setUp(self) -> None:
super().setUp()
# wait for a db connection and then run upgrade
wait_for_db(
db_tcp_addr=os.environ['API_BOILERPLATE_DB_PORT_3306_TCP_ADDR'],
db_tcp_port=int(os.environ[
'API_BOILERPLATE_DB_PORT_3306_TCP_PORT'
]),
)
# ensure all tables are refreshed
with self.app.app_context():
alembic_config = AlembicConfig('alembic.ini')
alembic_command.downgrade(alembic_config, 'base')
alembic_command.upgrade(alembic_config, 'head')