From 6a1be658fd7fea03428f0ef1bbcce630ab290782 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Wed, 24 Feb 2021 14:57:00 +0100 Subject: Censor unittests on GET /forms/$id --- backend/routes/forms/unittesting.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'backend/routes/forms/unittesting.py') diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index ddf0843..0cb7d8d 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -16,6 +16,19 @@ with open("resources/unittest_template.py") as file: UnittestResult = namedtuple("UnittestResult", "question_id return_code passed result") +def filter_unittests(form: Form) -> Form: + """ + Replace the unittest data section of code questions with the number of test cases. + + This is used to redact the exact tests when sending the form back to the frontend. + """ + for question in form.questions: + if question.type == "code" and "unittests" in question.data: + question.data["unittests"] = len(question.data["unittests"]) + + return form + + def _make_unit_code(units: dict[str, str]) -> str: result = "" -- cgit v1.2.3