2023-01-16 21:59:49 +01:00
|
|
|
from app.dependencies import db
|
|
|
|
|
2023-01-16 22:51:52 +01:00
|
|
|
from ...factory import (
|
|
|
|
GroupFactory,
|
|
|
|
ProjectGradeSheetFactory,
|
|
|
|
StudentFactory,
|
|
|
|
YearGroupFactory,
|
|
|
|
)
|
2023-01-16 21:59:49 +01:00
|
|
|
from ...utils import (
|
|
|
|
_test_case_client,
|
|
|
|
_test_case_client_without_response,
|
|
|
|
assert_model_changes,
|
|
|
|
create_one_model,
|
|
|
|
)
|
|
|
|
|
|
|
|
terms = [1, 2]
|
|
|
|
|
|
|
|
|
2023-01-16 22:51:52 +01:00
|
|
|
def test_detail_project_grade_sheet(test_app_with_context) -> None:
|
2023-01-16 21:59:49 +01:00
|
|
|
with test_app_with_context.test_client() as client:
|
|
|
|
for term in terms:
|
|
|
|
yg = create_one_model(YearGroupFactory)
|
|
|
|
group = create_one_model(GroupFactory, year_group_id=yg.id)
|
|
|
|
st = create_one_model(StudentFactory, year_group_id=yg.id)
|
|
|
|
pgs = create_one_model(ProjectGradeSheetFactory, group_id=group.id)
|
|
|
|
group.students.append(st)
|
|
|
|
db.session.commit()
|
|
|
|
data = _test_case_client_without_response(
|
|
|
|
client,
|
|
|
|
f"/api/students/project-grade-sheet/year-group/{yg.id}/?student_id={st.id}&term={term}",
|
|
|
|
None,
|
|
|
|
200,
|
|
|
|
method="get",
|
|
|
|
)
|
|
|
|
assert_model_changes(pgs, data)
|
|
|
|
|
|
|
|
|
2023-01-16 22:51:52 +01:00
|
|
|
def test_detail_project_grade_sheet_if_student_doesnt_exist(
|
|
|
|
test_app_with_context,
|
|
|
|
) -> None:
|
2023-01-16 21:59:49 +01:00
|
|
|
with test_app_with_context.test_client() as client:
|
|
|
|
for term in terms:
|
|
|
|
yg = create_one_model(YearGroupFactory)
|
|
|
|
_test_case_client(
|
|
|
|
client,
|
|
|
|
f"/api/students/project-grade-sheet/year-group/{yg.id}/?student_id=3&term={term}",
|
|
|
|
None,
|
|
|
|
"Not found student!",
|
|
|
|
404,
|
|
|
|
method="get",
|
|
|
|
key="error",
|
|
|
|
)
|
|
|
|
|
2023-01-16 22:51:52 +01:00
|
|
|
|
|
|
|
def test_detail_project_grade_sheet_if_group_doesnt_exist(
|
|
|
|
test_app_with_context,
|
|
|
|
) -> None:
|
2023-01-16 21:59:49 +01:00
|
|
|
with test_app_with_context.test_client() as client:
|
|
|
|
for term in terms:
|
|
|
|
yg = create_one_model(YearGroupFactory)
|
|
|
|
st = create_one_model(StudentFactory, year_group_id=yg.id)
|
|
|
|
_test_case_client(
|
|
|
|
client,
|
|
|
|
f"/api/students/project-grade-sheet/year-group/{yg.id}/?student_id={st.id}&term={term}",
|
|
|
|
None,
|
|
|
|
"Not found group!",
|
|
|
|
404,
|
|
|
|
method="get",
|
|
|
|
key="error",
|
|
|
|
)
|
|
|
|
|
2023-01-16 22:51:52 +01:00
|
|
|
|
|
|
|
def test_detail_project_grade_sheet_if_project_grade_sheet_doesnt_exist(
|
|
|
|
test_app_with_context,
|
|
|
|
) -> None:
|
2023-01-16 21:59:49 +01:00
|
|
|
with test_app_with_context.test_client() as client:
|
|
|
|
for term in terms:
|
|
|
|
yg = create_one_model(YearGroupFactory)
|
|
|
|
st = create_one_model(StudentFactory, year_group_id=yg.id)
|
|
|
|
group = create_one_model(GroupFactory, year_group_id=yg.id)
|
|
|
|
group.students.append(st)
|
|
|
|
db.session.commit()
|
|
|
|
_test_case_client(
|
|
|
|
client,
|
|
|
|
f"/api/students/project-grade-sheet/year-group/{yg.id}/?student_id={st.id}&term={term}",
|
|
|
|
None,
|
|
|
|
"Not found project grade sheet!",
|
|
|
|
404,
|
|
|
|
method="get",
|
|
|
|
key="error",
|
|
|
|
)
|