2023-01-09 22:56:46 +01:00
|
|
|
from app.dependencies import db
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
from ...fake_data import create_groups, create_project_supervisors, create_year_group
|
|
|
|
from ...utils import _test_case_client_without_response, assert_model_changes
|
|
|
|
|
2023-01-09 22:56:46 +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_group = create_year_group()
|
|
|
|
amount_of_project_supervisors = 3
|
2023-01-14 17:38:03 +01:00
|
|
|
project_supervisors = create_project_supervisors(
|
|
|
|
year_group, amount_of_project_supervisors
|
|
|
|
)
|
2023-01-09 22:56:46 +01:00
|
|
|
groups = create_groups(year_group, 6)
|
|
|
|
|
|
|
|
for i in range(1, 4):
|
|
|
|
for _ in range(i):
|
|
|
|
gr = groups.pop()
|
|
|
|
gr.project_supervisor_id = project_supervisors[i - 1].id
|
|
|
|
db.session.commit()
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
url = f"/api/students/registrations/{year_group.id}/?per_page=10"
|
|
|
|
data = _test_case_client_without_response(client, url, None, 200, method="get")
|
|
|
|
assert data.get("max_pages") == 1
|
|
|
|
project_supervisors_data = data.get("project_supervisors")
|
2023-01-09 22:56:46 +01:00
|
|
|
assert len(project_supervisors_data) == amount_of_project_supervisors
|
|
|
|
|
|
|
|
for ps, expected_available_groups in zip(project_supervisors, [2, 1, 0]):
|
2023-01-14 17:38:03 +01:00
|
|
|
ps_dict = list(
|
|
|
|
filter(lambda p: p.get("email") == ps.email, project_supervisors_data)
|
|
|
|
)[0]
|
|
|
|
assert ps_dict.get("available_groups") == expected_available_groups
|