stress_at_work_analysis/test/test_database.py

37 lines
1.1 KiB
Python

import unittest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config.models import LightSensor, Participant
from features.communication import get_call_data
from setup import db_uri
class DatabaseConnection(unittest.TestCase):
def setUp(self):
self.engine = create_engine(db_uri, echo=True)
Session = sessionmaker(bind=self.engine)
self.session = Session()
def tearDown(self):
self.engine.dispose()
self.session.close()
def test_connection(self):
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)
def test_get_calls_data(self):
calls = get_call_data(["nokia_0000003"])
self.assertIsNotNone(calls)