add functional tests of registrations endpoint for students view

This commit is contained in:
dominik24c 2023-01-09 22:56:46 +01:00
parent 02677ca511
commit 945def46d8
3 changed files with 32 additions and 5 deletions

View File

@ -17,13 +17,13 @@ def create_year_group(data: dict = None) -> YearGroup:
return yg return yg
def create_project_supervisors(yg: YearGroup, amount: int) -> List[ProjectSupervisorFactory]: def create_project_supervisors(yg: YearGroup, amount: int, limit_group: int = 3) -> List[ProjectSupervisorFactory]:
ps = [ProjectSupervisorFactory() for _ in range(amount)] ps = [ProjectSupervisorFactory() for _ in range(amount)]
db.session.add_all(ps) db.session.add_all(ps)
db.session.commit() db.session.commit()
db.session.add_all( db.session.add_all(
[YearGroupProjectSupervisorsFactory(limit_group=3, year_group_id=yg.id, project_supervisor_id=p.id) for p in [YearGroupProjectSupervisorsFactory(limit_group=limit_group, year_group_id=yg.id, project_supervisor_id=p.id)
ps]) for p in ps])
db.session.commit() db.session.commit()
return ps return ps

View File

@ -0,0 +1,27 @@
from ...utils import _test_case_client_without_response, assert_model_changes
from ...fake_data import create_year_group, create_project_supervisors, create_groups
from app.dependencies import db
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
project_supervisors = create_project_supervisors(year_group, amount_of_project_supervisors)
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()
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')
assert len(project_supervisors_data) == amount_of_project_supervisors
for ps, expected_available_groups in zip(project_supervisors, [2, 1, 0]):
ps_dict = list(filter(lambda p: p.get('email') == ps.email, project_supervisors_data))[0]
assert ps_dict.get('available_groups') == expected_available_groups

View File

@ -1,5 +1,5 @@
from ...utils import _test_case_client, _test_case_client_without_response, assert_model_changes from ...utils import _test_case_client, _test_case_client_without_response
from ...fake_data import create_year_group, create_students, create_student from ...fake_data import create_year_group, create_student
from app.base.mode import ModeGroups from app.base.mode import ModeGroups
from app.dependencies import db from app.dependencies import db
from app.students.models import YearGroupStudents from app.students.models import YearGroupStudents