This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |