stress_at_work_analysis/test/test_database.py

34 lines
966 B
Python
Raw Normal View History

2020-12-24 14:08:31 +01:00
import unittest
2020-12-24 14:29:47 +01:00
2020-12-24 16:06:23 +01:00
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
2020-12-24 14:11:58 +01:00
2020-12-31 14:33:44 +01:00
from config.models import LightSensor, Participant
2020-12-24 16:06:23 +01:00
from setup import db_uri
2020-12-24 14:08:31 +01:00
class DatabaseConnection(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.engine = create_engine(db_uri, echo=True)
Session = sessionmaker(bind=cls.engine)
cls.session = Session()
@classmethod
def tearDownClass(cls) -> None:
cls.engine.dispose()
cls.session.close()
2020-12-24 14:08:31 +01:00
def test_connection(self):
2020-12-24 16:06:23 +01:00
with self.engine.connect() as connection:
self.assertIsNotNone(connection)
connection.close()
def test_get_participant(self):
participant_0 = self.session.query(Participant).first()
self.assertIsNotNone(participant_0)
def test_get_light_data(self):
light_0 = self.session.query(Participant).join(LightSensor).first()
self.assertIsNotNone(light_0)