diff --git a/syncortexGA/models/timetable_model.py b/syncortexGA/models/timetable_model.py index aa5b391..c8db99e 100644 --- a/syncortexGA/models/timetable_model.py +++ b/syncortexGA/models/timetable_model.py @@ -77,7 +77,6 @@ class Course(BaseModel): has_lab: bool = False lab_slot: Optional[TimeSlot] = None lab_room_id: Optional[int] = None - lab_instructor_id: Optional[int] = None session_pattern: Optional[SessionPattern] = None @model_validator(mode="after") @@ -95,6 +94,23 @@ def validate_course(cls, model): return model +class CourseOffering(BaseModel): + """ + Represents the offering of a course by an instructor for a specific subgroup. + Allows multiple instructors to offer the same course to different subgroups, + and a single instructor to teach the same course in multiple subgroups. + + Attributes: + course_id (int): Identifier of the course being offered. + instructor_id (int): Identifier of the instructor teaching the course. + sub_group (int): Sub-group number within the course offering. Default is 1. + """ + + course_id: int + instructor_id: int + sub_group: int = 1 # Default subgroup is 1 + + # ========== Student ========== class Student(BaseModel): """Represents a student belonging to a specific group.""" diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index a3f577a..f2d2a9c 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -6,6 +6,7 @@ AlternatingSessionPattern, SessionPattern, Course, + CourseOffering, Student, StudentGroup, Instructor, @@ -329,3 +330,33 @@ def test_timetable_valid(): def test_timetable_empty(): timetable = Timetable(sessions=[]) assert timetable.sessions == [] + + +def test_course_offering_valid_defaults(): + offering = CourseOffering(course_id=10, instructor_id=5) + assert offering.course_id == 10 + assert offering.instructor_id == 5 + assert offering.sub_group == 1 # Default value + + +def test_course_offering_valid_with_subgroup(): + offering = CourseOffering(course_id=20, instructor_id=7, sub_group=3) + assert offering.course_id == 20 + assert offering.instructor_id == 7 + assert offering.sub_group == 3 + + +def test_course_offering_invalid_missing_course_id(): + with pytest.raises(ValidationError): + CourseOffering(instructor_id=1) + + +def test_course_offering_invalid_missing_instructor_id(): + with pytest.raises(ValidationError): + CourseOffering(course_id=1) + + +def test_course_offering_invalid_sub_group_type(): + # sub_group should be int + with pytest.raises(ValidationError): + CourseOffering(course_id=1, instructor_id=1, sub_group="two")