update and add functional tests for project supervisor endpoints
This commit is contained in:
parent
f4f9072c3f
commit
fe06023f82
@ -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!")
|
||||
|
@ -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 = (
|
||||
|
@ -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(
|
||||
|
@ -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):
|
||||
@ -106,6 +106,21 @@ class TemporaryAvailabilityFactory(alchemy.SQLAlchemyModelFactory):
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
|
||||
class ProjectGradeSheetFactory(alchemy.SQLAlchemyModelFactory):
|
||||
class Meta:
|
||||
model = ProjectGradeSheet
|
||||
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
@ -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",
|
||||
)
|
@ -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",
|
||||
)
|
@ -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()
|
||||
@ -159,8 +172,11 @@ def test_assign_your_group_to_term_of_defence_if_you_dont_have_group(
|
||||
) -> 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(
|
||||
@ -179,12 +195,17 @@ def test_assign_your_group_to_term_of_defence_if_your_group_has_already_assigned
|
||||
) -> 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,
|
||||
) -> 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,6 +279,8 @@ 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,
|
||||
) -> None:
|
||||
@ -258,6 +295,7 @@ 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,
|
||||
) -> None:
|
||||
@ -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,
|
||||
) -> 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()
|
||||
|
||||
|
@ -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",
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user