37 lines
1.7 KiB
Python
37 lines
1.7 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from wisegrade.api import ImportConfirm, ProjectConfirm
|
|
|
|
|
|
def project(**changes):
|
|
return {"relative_dir": "test/student", "student_no": "9000000001", "name": "学生甲", "topic": "机器人项目",
|
|
"files": [{"relative_path": "test/student/最终报告.pdf", "category": "final_report", "sha256": "a" * 64}], **changes}
|
|
|
|
|
|
def test_confirm_normalizes_identity_before_validating():
|
|
result = ProjectConfirm.model_validate(project(student_no=" 9000000001 ", name=" 学生甲 ", topic=" 机器人项目 "))
|
|
assert (result.student_no, result.name, result.topic) == ("9000000001", "学生甲", "机器人项目")
|
|
|
|
|
|
@pytest.mark.parametrize("changes", [
|
|
{"name": " "}, {"topic": " "}, {"student_no": "9000000001"}, {"files": []},
|
|
{"files": [{"relative_path": "test/student/a.pdf", "category": "unknown", "sha256": "a" * 64}]},
|
|
{"files": [{"relative_path": "test/student/a.pdf", "category": "final_report", "sha256": "a" * 64, "status": "ignored"}]},
|
|
{"files": [{"relative_path": f"test/student/{i}.pdf", "category": "final_report", "sha256": "a" * 64} for i in range(2)]},
|
|
])
|
|
def test_confirm_rejects_invalid_identity_or_selection(changes):
|
|
with pytest.raises(ValidationError):
|
|
ProjectConfirm.model_validate(project(**changes))
|
|
|
|
|
|
def test_empty_import_is_rejected():
|
|
with pytest.raises(ValidationError):
|
|
ImportConfirm(course_version_id=1, projects=[])
|
|
|
|
|
|
def test_ignored_unknown_material_does_not_block_valid_selection():
|
|
data = project()
|
|
data["files"].append({"relative_path": "test/student/foreign.pdf", "category": "unknown", "sha256": "b" * 64, "status": "ignored"})
|
|
assert len(ProjectConfirm.model_validate(data).files) == 2
|