2023-01-09 22:56:46 +01:00
|
|
|
from app.dependencies import db
|
2023-01-16 21:59:49 +01:00
|
|
|
from app.students.models import Group
|
2023-01-09 22:56:46 +01:00
|
|
|
|
2023-01-16 21:59:49 +01:00
|
|
|
from ...utils import _test_case_client_without_response, create_many_models, create_one_model
|
|
|
|
from ...factory import GroupFactory, YearGroupFactory, ProjectSupervisorFactory
|
2023-01-14 17:38:03 +01:00
|
|
|
|
2023-01-09 22:56:46 +01:00
|
|
|
|
2023-01-16 21:59:49 +01:00
|
|
|
def test_list_available_groups(test_app_with_context) -> None:
|
2023-01-09 22:56:46 +01:00
|
|
|
with test_app_with_context.test_client() as client:
|
2023-01-16 21:59:49 +01:00
|
|
|
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
|
2023-01-09 22:56:46 +01:00
|
|
|
db.session.commit()
|
|
|
|
|
2023-01-16 21:59:49 +01:00
|
|
|
data = _test_case_client_without_response(
|
|
|
|
client,
|
|
|
|
f"/api/students/registrations/{yg.id}/?per_page=10",
|
|
|
|
None,
|
|
|
|
200,
|
|
|
|
method="get",
|
|
|
|
)
|
|
|
|
project_supervisors = [*ps1, *ps2]
|
2023-01-14 17:38:03 +01:00
|
|
|
project_supervisors_data = data.get("project_supervisors")
|
2023-01-16 21:59:49 +01:00
|
|
|
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
|
2023-01-09 22:56:46 +01:00
|
|
|
|