system-pri/backend/tests/functional_tests/students/test_registrations.py

56 lines
1.9 KiB
Python

from app.dependencies import db
from app.students.models import Group
from ...factory import GroupFactory, ProjectSupervisorFactory, YearGroupFactory
from ...utils import (
_test_case_client_without_response,
create_many_models,
create_one_model,
)
def test_list_available_groups(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
yg = create_one_model(YearGroupFactory)
amount = 6
limit_group_1 = 4
limit_group_2 = 2
groups = create_many_models(amount, GroupFactory, year_group_id=yg.id)
ps1 = create_many_models(
amount // 2,
ProjectSupervisorFactory,
year_group_id=yg.id,
limit_group=limit_group_1,
)
ps2 = create_many_models(
amount // 2,
ProjectSupervisorFactory,
year_group_id=yg.id,
limit_group=limit_group_2,
)
for g, ps in zip(groups, [*ps1, *ps2]):
g.project_supervisor_id = ps.id
db.session.commit()
data = _test_case_client_without_response(
client,
f"/api/students/registrations/{yg.id}/?per_page=10",
None,
200,
method="get",
)
project_supervisors = [*ps1, *ps2]
project_supervisors_data = data.get("project_supervisors")
assert data.get("max_pages") == 1
assert len(project_supervisors_data) == amount
for ps_data in project_supervisors_data:
for ps_obj in project_supervisors:
if ps_data["email"] == ps_obj.email:
assert ps_data["available_groups"] == (
ps_obj.limit_group
- Group.query.filter(
Group.project_supervisor_id == ps_obj.id
).count()
)
continue