92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
from app.dependencies import db
|
|
|
|
from ...factory import (
|
|
GroupFactory,
|
|
ProjectGradeSheetFactory,
|
|
StudentFactory,
|
|
YearGroupFactory,
|
|
)
|
|
from ...utils import (
|
|
_test_case_client,
|
|
_test_case_client_without_response,
|
|
assert_model_changes,
|
|
create_one_model,
|
|
)
|
|
|
|
terms = [1, 2]
|
|
|
|
|
|
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)
|
|
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)
|
|
|
|
|
|
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)
|
|
_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",
|
|
)
|
|
|
|
|
|
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)
|
|
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",
|
|
)
|
|
|
|
|
|
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)
|
|
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",
|
|
)
|