2023-01-09 22:32:58 +01:00
|
|
|
from app.base.mode import ModeGroups
|
|
|
|
from app.dependencies import db
|
|
|
|
from app.students.models import YearGroupStudents
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
from ...fake_data import create_student, create_year_group
|
|
|
|
from ...utils import _test_case_client, _test_case_client_without_response
|
|
|
|
|
|
|
|
valid_data = {"first_name": "Dominic", "last_name": "Mozart", "index": 123_345}
|
2023-01-09 22:32:58 +01:00
|
|
|
|
|
|
|
year_group_data = [
|
2023-01-14 17:38:03 +01:00
|
|
|
{"name": "2022/2023", "mode": ModeGroups.STATIONARY.value},
|
|
|
|
{"name": "2021/2022", "mode": ModeGroups.STATIONARY.value},
|
|
|
|
{"name": "2023/2024", "mode": ModeGroups.NON_STATIONARY.value},
|
|
|
|
{"name": "1997/1998", "mode": ModeGroups.NON_STATIONARY.value},
|
2023-01-09 22:32:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_year_group_for_specific_student(test_app_with_context) -> None:
|
|
|
|
with test_app_with_context.test_client() as client:
|
|
|
|
year_groups = [create_year_group(data) for data in year_group_data]
|
|
|
|
student = create_student(valid_data)
|
|
|
|
for yg in year_groups[:-1]:
|
2023-01-14 17:38:03 +01:00
|
|
|
db.session.add(
|
|
|
|
YearGroupStudents(year_group_id=yg.id, student_index=student.index)
|
|
|
|
)
|
2023-01-09 22:32:58 +01:00
|
|
|
db.session.commit()
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
url = f"/api/students/year-group/?per_page=10&index={student.index}"
|
|
|
|
data = _test_case_client_without_response(client, url, None, 200, method="get")
|
|
|
|
assert data.get("max_pages") == 1
|
|
|
|
assert len(data.get("year_groups")) == len(year_groups) - 1
|
2023-01-09 22:32:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_year_group_if_student_doesnt_exist(test_app_with_context) -> None:
|
|
|
|
with test_app_with_context.test_client() as client:
|
2023-01-14 17:38:03 +01:00
|
|
|
_test_case_client(
|
|
|
|
client,
|
|
|
|
"/api/students/year-group/?per_page=10&index=23",
|
|
|
|
None,
|
|
|
|
"Not found student!",
|
|
|
|
404,
|
|
|
|
method="get",
|
|
|
|
key="error",
|
|
|
|
)
|