Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
tests student #58
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarraga committed Mar 13, 2024
1 parent c876f94 commit 70760b0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions backend/tests/test_student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# test_student.py
import unittest

from test_main import SessionLocal, test_engine

from db.extensions import Base
from domain.logic.student import create_student, get_all_students, get_student
from domain.logic.subject import add_student_to_subject, create_subject, get_subjects_of_student


class TestStudent(unittest.TestCase):
def setUp(self) -> None:
Base.metadata.drop_all(test_engine)
Base.metadata.create_all(test_engine)
self.session = SessionLocal()

def tearDown(self) -> None:
self.session.rollback()
self.session.close()

def test_create_and_get_student(self) -> None:
student = create_student(self.session, "Test Student", "[email protected]")
retrieved_student = get_student(self.session, student.id)
self.assertEqual(student.id, retrieved_student.id)

def test_get_all_students(self) -> None:
create_student(self.session, "Test Student 1", "[email protected]")
create_student(self.session, "Test Student 2", "[email protected]")
self.assertEqual(len(get_all_students(self.session)), 2)

def test_add_student_to_subject(self) -> None:
student = create_student(self.session, "Test Student", "[email protected]")
subject = create_subject(self.session, "Test Subject")
add_student_to_subject(self.session, student.id, subject.id)
subjects_of_student = get_subjects_of_student(self.session, student.id)
self.assertIn(subject.id, [subject.id for subject in subjects_of_student])


if __name__ == "__main__":
unittest.main()

0 comments on commit 70760b0

Please sign in to comment.