Coverage for tasks/tests/cpft_covid_medical_tests.py: 35%
23 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
1"""
2camcops_server/tasks/tests/cpft_covid_medical_tests.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26"""
28from unittest import mock
29import unittest
31from camcops_server.tasks.cpft_covid_medical import CpftCovidMedical
34class CpftCovidMedicalTests(unittest.TestCase):
35 def setUp(self) -> None:
36 super().setUp()
38 self.request = mock.Mock()
40 def test_complete_when_all_answers_valid(self) -> None:
41 task = CpftCovidMedical()
43 task.how_and_when_symptoms = 0
45 self.assertTrue(task.is_complete())
47 def test_incomplete_when_symptoms_null(self) -> None:
48 task = CpftCovidMedical()
50 self.assertFalse(task.is_complete())
52 def test_incomplete_when_any_field_invalid(self) -> None:
53 all_fields = ["how_and_when_symptoms"]
55 for invalid_field in all_fields:
56 task = CpftCovidMedical()
58 for field in all_fields:
59 setattr(task, field, 0)
61 self.assertTrue(task.is_complete())
63 setattr(task, invalid_field, 10.5)
64 self.assertFalse(
65 task.is_complete(),
66 msg=f"Failed when setting {invalid_field} invalid",
67 )