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
|
2020-12-31 14:29:35 +01:00
|
|
|
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):
|
2021-02-02 15:44:53 +01:00
|
|
|
@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()
|
2020-12-31 14:29:35 +01:00
|
|
|
|
|
|
|
def test_get_participant(self):
|
2021-01-05 17:00:45 +01:00
|
|
|
participant_0 = self.session.query(Participant).first()
|
|
|
|
self.assertIsNotNone(participant_0)
|
2020-12-31 14:29:35 +01:00
|
|
|
|
|
|
|
def test_get_light_data(self):
|
|
|
|
light_0 = self.session.query(Participant).join(LightSensor).first()
|
|
|
|
self.assertIsNotNone(light_0)
|