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