update and add functional tests for project supervisor endpoints

This commit is contained in:
dominik24c 2023-01-16 22:51:52 +01:00
parent f4f9072c3f
commit fe06023f82
12 changed files with 516 additions and 99 deletions

View File

@ -14,7 +14,7 @@ def update_project_grade_sheet(
ProjectSupervisor.id == project_supervisor_id
).first()
if project_supervisor is None:
abort(404, "ProjectSupervisor doesn't exist!")
abort(404, "Not found project supervisor!")
####################################
if len(data) == 0:
abort(400, "You passed empty data!")

View File

@ -148,13 +148,13 @@ def list_enrollments_for_project_supervisor(
.first()
)
if project_supervisor is None:
abort(404, "ProjectSupervisor doesn't exist!")
abort(404, "Not found project supervisor!")
################
examination_schedule = ExaminationSchedule.query.filter(
ExaminationSchedule.id == examination_schedule_id
).first()
if examination_schedule is None:
abort(404, "Examination schedule doesn't exist!")
abort(404, "Not found examination schedule!")
if examination_schedule.open_enrollments != EnrollmentsMode.INIT.value:
abort(400, "Enrollments has started or closed! You have been delayed!")
@ -180,14 +180,14 @@ def list_created_term_of_defences_by_coordinator_for_project_supervisor(
.first()
)
if project_supervisor is None:
abort(404, "ProjectSupervisor doesn't exist!")
abort(404, "Not found project supervisor!")
################
es = ExaminationSchedule.query.filter(
ExaminationSchedule.id == examination_schedule_id,
ExaminationSchedule.year_group_id,
).first()
if es is None:
abort(404, "Examination schedule doesn't exist!")
abort(404, "Not found examination schedule!")
# list of your free times first enrollment
td = (

View File

@ -28,7 +28,7 @@ def detail_project_grade_sheet(group_id: int, query: dict) -> dict:
ProjectSupervisor.id == project_supervisor_id
).first()
if project_supervisor is None:
abort(404, "ProjectSupervisor doesn't exist!")
abort(404, "Not found project supervisor!")
####################################
term = query.get("term")
group = Group.query.filter(

View File

@ -13,7 +13,7 @@ from app.examination_schedule.models import (
TermOfDefence,
)
from app.project_supervisor.models import ProjectSupervisor
from app.students.models import Group, Student, YearGroup, ProjectGradeSheet
from app.students.models import Group, ProjectGradeSheet, Student, YearGroup
class YearGroupFactory(alchemy.SQLAlchemyModelFactory):
@ -83,11 +83,11 @@ class TermOfDefenceFactory(alchemy.SQLAlchemyModelFactory):
start_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30)
+ datetime.timedelta(n * 30)
)
end_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30 + 30)
+ datetime.timedelta(n * 30 + 30)
)
@ -98,11 +98,26 @@ class TemporaryAvailabilityFactory(alchemy.SQLAlchemyModelFactory):
start_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30)
+ datetime.timedelta(n * 30)
)
end_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30 + 30)
+ datetime.timedelta(n * 30 + 30)
)
class TemporaryAvailabilityFactory(alchemy.SQLAlchemyModelFactory):
class Meta:
model = TemporaryAvailability
sqlalchemy_session = db.session
start_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30)
)
end_date = Sequence(
lambda n: datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc)
+ datetime.timedelta(n * 30 + 30)
)

View File

@ -18,7 +18,7 @@ from ...utils import (
assert_model_changes,
create_many_models,
create_one_model,
get_data_of_term_of_defence
get_data_of_term_of_defence,
)
@ -48,7 +48,7 @@ def test_delete_term_of_defence(test_app_with_context) -> None:
def test_delete_term_of_defence_if_term_of_defence_or_examination_schedule_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
_test_case_client(
@ -118,7 +118,7 @@ def test_create_many_term_of_defences(test_app_with_context) -> None:
def test_create_many_term_of_defences_with_invalid_id_of_chairman(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -142,7 +142,7 @@ def test_create_many_term_of_defences_with_invalid_id_of_chairman(
def test_create_many_term_of_defences_if_examination_schedule_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -165,7 +165,7 @@ def test_create_many_term_of_defences_if_examination_schedule_doesnt_exist(
def test_create_many_term_of_defences_if_project_supervisors_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -186,7 +186,7 @@ def test_create_many_term_of_defences_if_project_supervisors_doesnt_exist(
def test_create_many_term_of_defences_with_invalid_duration_time(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -211,7 +211,7 @@ def test_create_many_term_of_defences_with_invalid_duration_time(
def test_create_many_term_of_defences_if_start_date_is_greater_than_end_date(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -236,7 +236,7 @@ def test_create_many_term_of_defences_if_start_date_is_greater_than_end_date(
def test_create_many_term_of_defences_with_invalid_date_range(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -288,7 +288,7 @@ def test_update_term_of_defence(test_app_with_context) -> None:
def test_update_term_of_defence_with_invalid_id_of_chairman(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -313,7 +313,7 @@ def test_update_term_of_defence_with_invalid_id_of_chairman(
def test_update_term_of_defence_if_examination_schedule_or_term_of_defence_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
data = get_data_of_term_of_defence(150)
@ -331,7 +331,7 @@ def test_update_term_of_defence_if_examination_schedule_or_term_of_defence_doesn
def test_update_term_of_defence_if_project_supervisors_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -352,7 +352,7 @@ def test_update_term_of_defence_if_project_supervisors_doesnt_exist(
def test_update_term_of_defence_with_invalid_duration_time(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -377,7 +377,7 @@ def test_update_term_of_defence_with_invalid_duration_time(
def test_update_term_of_defence_if_start_date_is_greater_than_end_date(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -446,7 +446,7 @@ def test_list_temporary_availabilities(test_app_with_context) -> None:
def test_list_temporary_availabilities_if_examination_schedule_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = "/api/coordinator/enrollments/43/temporary-availabilities/"
@ -483,7 +483,7 @@ def test_list_of_assigned_group_to_term_of_defences(test_app_with_context) -> No
def test_list_of_assigned_group_to_term_of_defences_if_examination_schedule_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = "/api/coordinator/enrollments/43/assigned-group-to-term-of-defences/"
@ -517,7 +517,7 @@ def test_set_new_group_to_term_of_defence(test_app_with_context) -> None:
def test_set_new_group_to_term_of_defence_if_examination_schedule_or_term_of_defence_dont_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = "/api/coordinator/enrollments/34/term-of-defence/4/group/"
@ -533,7 +533,7 @@ def test_set_new_group_to_term_of_defence_if_examination_schedule_or_term_of_def
def test_set_new_group_to_term_of_defence_if_group_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -553,7 +553,8 @@ def test_set_new_group_to_term_of_defence_if_group_doesnt_exist(
def test_set_new_group_to_term_of_defence_if_group_has_already_assigned_to_term_of_defence(
test_app_with_context) -> None:
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id)
@ -597,7 +598,7 @@ def test_delete_group_to_term_of_defence(test_app_with_context) -> None:
def test_delete_group_to_term_of_defence_if_examination_schedule_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = "/api/coordinator/enrollments/3/term-of-defence/1/group/"
@ -635,7 +636,7 @@ def test_update_group_for_term_of_defence(test_app_with_context) -> None:
def test_update_group_for_term_of_defence_if_examination_schedule_or_term_of_defence_dont_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = "/api/coordinator/enrollments/34/term-of-defence/4/group/"
@ -651,7 +652,7 @@ def test_update_group_for_term_of_defence_if_examination_schedule_or_term_of_def
def test_update_group_for_term_of_defence_if_group_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)

View File

@ -0,0 +1,101 @@
from app.base.mode import EnrollmentsMode
from ...factory import (
ExaminationScheduleFactory,
ProjectSupervisorFactory,
TemporaryAvailabilityFactory,
YearGroupFactory,
)
from ...utils import (
_test_case_client,
_test_case_client_without_response,
create_many_models,
create_one_model,
)
def test_list_enrollments_for_project_supervisor(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
ps2 = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id)
create_many_models(
7,
TemporaryAvailabilityFactory,
examination_schedule_id=ex.id,
project_supervisor_id=ps2.id,
)
amount = 5
create_many_models(
amount,
TemporaryAvailabilityFactory,
examination_schedule_id=ex.id,
project_supervisor_id=ps.id,
)
url = f"/api/project_supervisor/{ex.id}/temporary-availabilities/?id={ps.id}"
data = _test_case_client_without_response(client, url, None, 200, method="get")
assert len(data.get("free_times")) == amount
def test_list_enrollments_for_project_supervisor_if_examination_schedule_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
url = f"/api/project_supervisor/3/temporary-availabilities/?id={ps.id}"
_test_case_client(
client,
url,
None,
"Not found examination schedule!",
404,
method="get",
key="error",
)
def test_list_enrollments_for_project_supervisor_if_project_supervisor_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
url = f"/api/project_supervisor/3/temporary-availabilities/?id=3"
_test_case_client(
client,
url,
None,
"Not found project supervisor!",
404,
method="get",
key="error",
)
def test_list_enrollments_for_project_supervisor_if_enrollments_is_not_open_yet(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
create_many_models(
7,
TemporaryAvailabilityFactory,
examination_schedule_id=ex.id,
project_supervisor_id=ps.id,
)
url = f"/api/project_supervisor/{ex.id}/temporary-availabilities/?id={ps.id}"
_test_case_client(
client,
url,
None,
"Enrollments has started or closed! You have been delayed!",
400,
method="get",
key="error",
)

View File

@ -0,0 +1,229 @@
from app.dependencies import db
from ...factory import (
GroupFactory,
ProjectGradeSheetFactory,
ProjectSupervisorFactory,
YearGroupFactory,
)
from ...utils import (
_test_case_client,
_test_case_client_without_response,
assert_model_changes,
create_one_model,
)
terms = [1, 2]
terms_uri = ["first-term", "second-term"]
data_1 = {
"documentation_for_clients_1": 0,
"documentation_for_developers_1": 4,
"documentation_license_1": 4,
"documentation_project_vision_1": 4,
"documentation_requirements_1": 3,
"group_work_contact_with_client_1": 3,
"group_work_devops_1": 0,
"group_work_division_of_work_1": 4,
"group_work_management_of_risk_1": 4,
"group_work_management_of_source_code_1": 4,
"group_work_regularity_1": 4,
"group_work_work_methodology_1": 4,
"presentation_answers_to_questions_from_committee_1": 4,
"presentation_required_content_1": 4,
"presentation_showing_1": 4,
"presentation_was_compatible_1": 3,
"products_project_acceptance_criteria_1": 4,
"products_project_access_to_application_1": 0,
"products_project_access_to_test_application_1": 0,
"products_project_complexity_of_product_1": 4,
"products_project_expected_functionality_1": 4,
"products_project_has_been_implemented_1": 0,
"products_project_is_useful_1": 4,
"products_project_promises_well_1": 4,
"products_project_prototype_1": 3,
"products_project_security_issues_1": 0,
"products_project_technology_1": 4,
"products_project_tests_1": 0,
}
data_2 = {
"documentation_for_clients_2": 3,
"documentation_for_developers_2": 4,
"documentation_license_2": 4,
"documentation_project_vision_2": 0,
"documentation_requirements_2": 4,
"group_work_contact_with_client_2": 3,
"group_work_devops_2": 4,
"group_work_division_of_work_2": 4,
"group_work_management_of_risk_2": 4,
"group_work_management_of_source_code_2": 4,
"group_work_regularity_2": 4,
"group_work_work_methodology_2": 4,
"presentation_answers_to_questions_from_committee_2": 0,
"presentation_required_content_2": 0,
"presentation_showing_2": 0,
"presentation_was_compatible_2": 0,
"products_project_acceptance_criteria_2": 3,
"products_project_access_to_application_2": 0,
"products_project_access_to_test_application_2": 0,
"products_project_complexity_of_product_2": 4,
"products_project_expected_functionality_2": 4,
"products_project_has_been_implemented_2": 3,
"products_project_is_useful_2": 3,
"products_project_promises_well_2": 0,
"products_project_prototype_2": 0,
"products_project_security_issues_2": 0,
"products_project_technology_2": 4,
"products_project_tests_2": 4,
}
def test_detail_project_grade_sheet(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
project_supervisor = create_one_model(
ProjectSupervisorFactory, year_group_id=yg.id
)
group = create_one_model(
GroupFactory,
year_group_id=yg.id,
project_supervisor_id=project_supervisor.id,
)
pgs = create_one_model(ProjectGradeSheetFactory, group_id=group.id)
data = _test_case_client_without_response(
client,
f"/api/project_supervisor/project-grade-sheet/group/{group.id}/?term={term}&id={project_supervisor.id}",
None,
200,
method="get",
)
assert_model_changes(pgs, data)
def test_detail_project_grade_sheet_if_project_supervisor_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/3/?term={term}&id=2",
None,
"Not found project supervisor!",
404,
method="get",
key="error",
)
def test_detail_project_grade_sheet_if_you_try_get_not_your_group(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
project_supervisor = create_one_model(
ProjectSupervisorFactory, year_group_id=yg.id
)
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/3/?term={term}&id={project_supervisor.id}",
None,
"Group doesn't exist or you are not project supervisor of that group!",
400,
method="get",
key="error",
)
def test_update_project_grade_sheet_for_both_term(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
for term, data, attr_name, expected_points in zip(
terms_uri,
[data_1, data_2],
["points_for_first_term", "points_for_second_term"],
[93, 68.1],
):
yg = create_one_model(YearGroupFactory)
project_supervisor = create_one_model(
ProjectSupervisorFactory, year_group_id=yg.id
)
group = create_one_model(
GroupFactory,
year_group_id=yg.id,
project_supervisor_id=project_supervisor.id,
)
pgs = create_one_model(ProjectGradeSheetFactory, group_id=group.id)
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/{group.id}/{term}/?id={project_supervisor.id}",
data,
"Your project grade sheet was updated!",
200,
method="patch",
)
assert_model_changes(pgs, data)
assert getattr(group, attr_name) == expected_points
def test_update_project_grade_sheet_for_both_term_if_project_grade_sheet_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term, data in zip(terms_uri, [data_1, data_2]):
yg = create_one_model(YearGroupFactory)
project_supervisor = create_one_model(
ProjectSupervisorFactory, year_group_id=yg.id
)
group = create_one_model(
GroupFactory,
year_group_id=yg.id,
project_supervisor_id=project_supervisor.id,
)
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/{group.id}/{term}/?id={project_supervisor.id}",
data,
"Not found project grade sheet!",
404,
method="patch",
key="error",
)
def test_update_project_grade_sheet_for_both_term_if_try_update_project_grade_sheet_for_not_your_group(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term, data in zip(terms_uri, [data_1, data_2]):
yg = create_one_model(YearGroupFactory)
project_supervisor = create_one_model(
ProjectSupervisorFactory, year_group_id=yg.id
)
group = create_one_model(GroupFactory, year_group_id=yg.id)
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/{group.id}/{term}/?id={project_supervisor.id}",
data,
"You cannot update project grade sheet! It's not your group!",
400,
method="patch",
key="error",
)
def test_update_project_grade_sheet_for_both_term_if_project_supervisor_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term, data in zip(terms_uri, [data_1, data_2]):
_test_case_client(
client,
f"/api/project_supervisor/project-grade-sheet/group/3/{term}/?id=3",
data,
"Not found project supervisor!",
404,
method="patch",
key="error",
)

View File

@ -7,8 +7,8 @@ from app.examination_schedule.models import ExaminationSchedule, TermOfDefence
from ...factory import (
ExaminationScheduleFactory,
GroupFactory,
StudentFactory,
ProjectSupervisorFactory,
StudentFactory,
TermOfDefenceFactory,
YearGroupFactory,
)
@ -18,7 +18,7 @@ from ...utils import (
assert_model_changes,
create_many_models,
create_one_model,
get_data_of_term_of_defence
get_data_of_term_of_defence,
)
@ -32,7 +32,9 @@ def test_list_examination_schedule(test_app_with_context) -> None:
assert len(data.get("examination_schedules")) == 23
def test_list_examination_schedule_if_student_doesnt_exist(test_app_with_context) -> None:
def test_list_examination_schedule_if_student_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
yg = create_one_model(YearGroupFactory)
_test_case_client(
@ -51,13 +53,19 @@ def test_list_term_of_defences(test_app_with_context) -> None:
year_group = create_one_model(YearGroupFactory)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id)
project_supervisors = create_many_models(13, ProjectSupervisorFactory, year_group_id=year_group.id)
project_supervisors = create_many_models(
13, ProjectSupervisorFactory, year_group_id=year_group.id
)
ps = project_supervisors[0]
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
group.students.append(st)
db.session.commit()
term_of_defences = create_many_models(13, TermOfDefenceFactory, examination_schedule_id=ex.id)
term_of_defences = create_many_models(
13, TermOfDefenceFactory, examination_schedule_id=ex.id
)
ps_amount = 6
for i in range(ps_amount):
term_of_defences[i].members_of_committee.append(ps)
@ -84,12 +92,17 @@ def test_list_term_of_defences_if_student_doesnt_exist(test_app_with_context) ->
def test_assign_your_group_to_term_of_defence(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id)
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
td.members_of_committee.append(ps)
group.students.append(st)
db.session.commit()
@ -105,7 +118,7 @@ def test_assign_your_group_to_term_of_defence(test_app_with_context) -> None:
def test_assign_your_group_to_term_of_defence_if_student_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
_test_case_client(
@ -120,7 +133,7 @@ def test_assign_your_group_to_term_of_defence_if_student_doesnt_exist(
def test_assign_your_group_to_term_of_defence_if_term_of_defence_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
st = create_one_model(StudentFactory)
@ -136,7 +149,7 @@ def test_assign_your_group_to_term_of_defence_if_term_of_defence_doesnt_exist(
def test_assign_your_group_to_term_of_defence_if_enrollments_havent_started_yet(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
@ -155,12 +168,15 @@ def test_assign_your_group_to_term_of_defence_if_enrollments_havent_started_yet(
def test_assign_your_group_to_term_of_defence_if_you_dont_have_group(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
_test_case_client(
@ -175,16 +191,21 @@ def test_assign_your_group_to_term_of_defence_if_you_dont_have_group(
def test_assign_your_group_to_term_of_defence_if_your_group_has_already_assigned_to_any_term_of_defence(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
td.group_id = group.id
group.students.append(st)
db.session.commit()
@ -199,17 +220,23 @@ def test_assign_your_group_to_term_of_defence_if_your_group_has_already_assigned
key="error",
)
def test_assign_your_group_to_term_of_defence_if_your_project_supervisor_is_not_in_committee(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
group.students.append(st)
db.session.commit()
@ -223,15 +250,23 @@ def test_assign_your_group_to_term_of_defence_if_your_project_supervisor_is_not_
key="error",
)
def test_delete_your_group_from_term_of_defence(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id, group_id=group.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
td = create_one_model(
TermOfDefenceFactory, examination_schedule_id=ex.id, group_id=group.id
)
td.members_of_committee.append(ps)
group.students.append(st)
db.session.commit()
@ -244,8 +279,10 @@ def test_delete_your_group_from_term_of_defence(test_app_with_context) -> None:
200,
method="delete",
)
def test_delete_your_group_from_term_of_defence_if_student_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
_test_case_client(
@ -258,8 +295,9 @@ def test_delete_your_group_from_term_of_defence_if_student_doesnt_exist(
key="error",
)
def test_delete_your_group_from_term_of_defence_if_term_of_defence_doesnt_exist(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
st = create_one_model(StudentFactory)
@ -273,17 +311,23 @@ def test_delete_your_group_from_term_of_defence_if_term_of_defence_doesnt_exist(
key="error",
)
def test_assign_your_group_to_term_of_defence_if_you_try_delete_not_your_group(
test_app_with_context,
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
year_group = create_one_model(YearGroupFactory)
ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value)
ex = create_one_model(
ExaminationScheduleFactory,
year_group_id=year_group.id,
open_enrollments=EnrollmentsMode.OPEN.value,
)
td = create_one_model(TermOfDefenceFactory, examination_schedule_id=ex.id)
st = create_one_model(StudentFactory, year_group_id=year_group.id)
ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id)
group = create_one_model(GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id)
group = create_one_model(
GroupFactory, year_group_id=year_group.id, project_supervisor_id=ps.id
)
td.group_id = group.id
db.session.commit()

View File

@ -1,20 +1,22 @@
import copy
from app.dependencies import db
from ...factory import StudentFactory, GroupFactory, YearGroupFactory, ProjectGradeSheetFactory
from ...factory import (
GroupFactory,
ProjectGradeSheetFactory,
StudentFactory,
YearGroupFactory,
)
from ...utils import (
_test_case_client,
_test_case_client_without_response,
assert_model_changes,
create_many_models,
create_one_model,
)
terms = [1, 2]
def test_detail_project_grade_sheet_first_term(test_app_with_context) -> None:
def test_detail_project_grade_sheet(test_app_with_context) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
@ -33,7 +35,9 @@ def test_detail_project_grade_sheet_first_term(test_app_with_context) -> None:
assert_model_changes(pgs, data)
def test_detail_student_if_student_doesnt_exist(test_app_with_context) -> None:
def test_detail_project_grade_sheet_if_student_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
@ -47,7 +51,10 @@ def test_detail_student_if_student_doesnt_exist(test_app_with_context) -> None:
key="error",
)
def test_detail_student_if_group_doesnt_exist(test_app_with_context) -> None:
def test_detail_project_grade_sheet_if_group_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
@ -62,7 +69,10 @@ def test_detail_student_if_group_doesnt_exist(test_app_with_context) -> None:
key="error",
)
def test_detail_student_if_project_grade_sheet_doesnt_exist(test_app_with_context) -> None:
def test_detail_project_grade_sheet_if_project_grade_sheet_doesnt_exist(
test_app_with_context,
) -> None:
with test_app_with_context.test_client() as client:
for term in terms:
yg = create_one_model(YearGroupFactory)
@ -79,4 +89,3 @@ def test_detail_student_if_project_grade_sheet_doesnt_exist(test_app_with_contex
method="get",
key="error",
)

View File

@ -1,8 +1,12 @@
from app.dependencies import db
from app.students.models import Group
from ...utils import _test_case_client_without_response, create_many_models, create_one_model
from ...factory import GroupFactory, YearGroupFactory, ProjectSupervisorFactory
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:
@ -12,8 +16,18 @@ def test_list_available_groups(test_app_with_context) -> None:
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)
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()
@ -31,8 +45,11 @@ def test_list_available_groups(test_app_with_context) -> None:
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())
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

View File

@ -5,6 +5,7 @@ from factory.alchemy import SQLAlchemyModelFactory
from flask.testing import FlaskClient
from app.dependencies import db
from app.examination_schedule.models import ExaminationSchedule
from app.students.models import Group
@ -17,11 +18,11 @@ def assert_model_changes(model: db.Model, expected_data: dict) -> None:
def _test_case_client_without_response(
test_client: FlaskClient,
url: str,
data: Union[dict, None],
status_code: int,
method: str = "post",
test_client: FlaskClient,
url: str,
data: Union[dict, None],
status_code: int,
method: str = "post",
) -> dict:
method_func = getattr(test_client, method)
if data is not None:
@ -34,13 +35,13 @@ def _test_case_client_without_response(
def _test_case_client(
test_client: FlaskClient,
url: str,
data: Union[dict, None],
message: str,
status_code: int,
key: str = "message",
method: str = "post",
test_client: FlaskClient,
url: str,
data: Union[dict, None],
message: str,
status_code: int,
key: str = "message",
method: str = "post",
) -> dict:
response_data = _test_case_client_without_response(
test_client, url, data, status_code, method
@ -59,7 +60,7 @@ def _test_case_group(group: Group, data: dict) -> None:
def create_many_models(
amount: int, factory: Type[SQLAlchemyModelFactory], **kwargs
amount: int, factory: Type[SQLAlchemyModelFactory], **kwargs
) -> List[SQLAlchemyModelFactory]:
models = [factory(**kwargs) for _ in range(amount)]
db.session.add_all(models)
@ -68,9 +69,9 @@ def create_many_models(
def create_one_model(
model: Union[Type[db.Model], Type[SQLAlchemyModelFactory]],
data: dict = None,
**kwargs
model: Union[Type[db.Model], Type[SQLAlchemyModelFactory]],
data: dict = None,
**kwargs
) -> Union[db.Model, SQLAlchemyModelFactory]:
if issubclass(model, SQLAlchemyModelFactory):
m = model(**kwargs) # it's a factory
@ -92,6 +93,6 @@ def get_data_of_term_of_defence(timedelta_minutes: int = 30) -> dict:
"%Y-%m-%dT%H:%M:%S.000Z"
),
"end_date": (
date + datetime.timedelta(days=1, minutes=timedelta_minutes)
date + datetime.timedelta(days=1, minutes=timedelta_minutes)
).strftime("%Y-%m-%dT%H:%M:%S.000Z"),
}