From 28b6d4c8b8f7bc6c6230b42c2e2db376be559562 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 24 Jun 2022 05:06:35 +0400 Subject: Allow Setup For Unittests Adds the setup method as a special method for unittest question types. Additionally, a couple QoL fixes are included. I changed `unit` to `self` to clarify what it actually is, and I changed an `lstrip` to a `removeprefix` to avoid removing unintentional portions of the name (for instance `something` -> `omething`) Signed-off-by: Hassan Abouelela --- backend/models/question.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'backend/models') diff --git a/backend/models/question.py b/backend/models/question.py index 5a1334a..201aa51 100644 --- a/backend/models/question.py +++ b/backend/models/question.py @@ -15,8 +15,10 @@ class Unittests(BaseModel): @validator("tests") def validate_tests(cls, value: _TESTS_TYPE) -> _TESTS_TYPE: """Confirm that at least one test exists in a test suite.""" - if isinstance(value, dict) and len(value.keys()) == 0: - raise ValueError("Must have at least one test in a test suite.") + if isinstance(value, dict): + keys = len(value.keys()) - (1 if "setUp" in value.keys() else 0) + if keys == 0: + raise ValueError("Must have at least one test in a test suite.") return value -- cgit v1.2.3