Skip to content

Commit

Permalink
undo backend response change
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterjanin committed May 17, 2024
1 parent 0d36528 commit 0561d52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/src/submission/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def upload_files(files: list[UploadFile], project: Project) -> str:
matches = [file for file in filelist if fnmatch.fnmatch(file, r.value)]

if not r.mandatory and len(matches):
errors.append({"mandatory": False, "value": r.value,
errors.append({"type": "forbidden", "requirement": r.value,
"msg": f"Forbidden file(s) found: {r.value}", "files": matches})
elif r.mandatory and not len(matches):
errors.append({"mandatory": True, "value": r.value,
errors.append({"type": "mandatory", "requirement": r.value,
"msg": f"Required file not found: {r.value}"})

if len(errors):
Expand Down
14 changes: 7 additions & 7 deletions backend/tests/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ async def test_project_requirements(client: AsyncClient, group_with_reqs_id: int
response = await client.post("/api/submissions/", params={"group_id": group_with_reqs_id}, files=[optional])
assert response.status_code == 422
assert len(response.json()["detail"]) == 1
assert response.json()["detail"][0]["value"] == "*.py"
assert response.json()["detail"][0]["mandatory"] is True
assert response.json()["detail"][0]["requirement"] == "*.py"
assert response.json()["detail"][0]["type"] == "mandatory"

# Submit with forbidden
response = await client.post(
"/api/submissions/", params={"group_id": group_with_reqs_id}, files=[optional, forbidden]
)
assert response.status_code == 422
assert len(response.json()["detail"]) == 2
reqs = [(req["value"], req["mandatory"]) for req in response.json()["detail"]]
assert ("*.py", True) in reqs
assert ("*.pdf", False) in reqs
reqs = [(req["requirement"], req["type"]) for req in response.json()["detail"]]
assert ("*.py", "mandatory") in reqs
assert ("*.pdf", "forbidden") in reqs

# Submit with forbidden and mandatory
response = await client.post(
"/api/submissions/", params={"group_id": group_with_reqs_id}, files=[optional, forbidden, mandatory]
)
assert response.status_code == 422
assert len(response.json()["detail"]) == 1
reqs = [(req["value"], req["mandatory"]) for req in response.json()["detail"]]
assert ("*.pdf", False) == reqs[0]
reqs = [(req["requirement"], req["type"]) for req in response.json()["detail"]]
assert ("*.pdf", "forbidden") == reqs[0]

# Submit with mandatory
response = await client.post(
Expand Down

0 comments on commit 0561d52

Please sign in to comment.