diff options
author | 2021-06-02 04:06:00 +0300 | |
---|---|---|
committer | 2021-06-02 04:06:00 +0300 | |
commit | b98da9ae3693b40427077f69092b4b8ee69d2543 (patch) | |
tree | 64bcbdf573e8fd665f0fa05403b5266139ac142c /backend/routes/forms/submit.py | |
parent | Adds Code Question Model (diff) |
Records Failed Unittests
Adds logic for saving submissions of failed unittests. Updates schema
docs.
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/routes/forms/submit.py')
-rw-r--r-- | backend/routes/forms/submit.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index c0a50f3..97cf2ac 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -168,16 +168,38 @@ class SubmitForm(Route): if any("unittests" in question.data for question in form.questions): unittest_results = await execute_unittest(response_obj, form) - if not all(test.passed for test in unittest_results): - # Return 500 if we encountered an internal error (code 99). - status_code = 500 if any( - test.return_code == 99 for test in unittest_results - ) else 403 + failures = [] + status_code = 403 + for test in unittest_results: + response_obj.response[test.question_id] = { + "value": response_obj.response[test.question_id], + "passed": test.passed + } + + if test.return_code == 0: + test_names = [] if test.passed else test.result.split(";") + response_obj.response[test.question_id]["failures"] = test_names + + # Report a failure on internal errors, + # or if the test suite doesn't allow failures + if not test.passed: + allow_failure = ( + form.questions[test.question_index].data["unittests"]["allow_failure"] + ) + + if test.return_code == 99: + failures.append(test) + status_code = 500 + + elif not allow_failure: + failures.append(test) + + if len(failures): return JSONResponse({ "error": "failed_tests", "test_results": [ - test._asdict() for test in unittest_results if not test.passed + test._asdict() for test in failures ] }, status_code=status_code) |