Coverage for tasks/tests/paradise24_tests.py: 28%
29 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/paradise24_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, TestCase
30from camcops_server.tasks.paradise24 import Paradise24
33class Paradise24Tests(TestCase):
34 def test_complete_when_all_answers_valid(self) -> None:
35 paradise24 = Paradise24()
37 for q_num in range(1, 24 + 1):
38 setattr(paradise24, f"q{q_num}", 0)
40 self.assertTrue(paradise24.is_complete())
42 def test_is_complete_false_when_not_finished(self) -> None:
43 paradise24 = Paradise24()
45 self.assertFalse(paradise24.is_complete())
47 def test_total_score_none_when_not_complete(self) -> None:
48 paradise24 = Paradise24()
50 self.assertIsNone(paradise24.total_score())
52 def test_total_score_is_sum_of_all_answers(self) -> None:
53 paradise24 = Paradise24()
55 for q_num in range(1, 24 + 1):
56 setattr(paradise24, f"q{q_num}", 2)
58 self.assertEqual(paradise24.total_score(), 48)
60 def test_metric_score_derived_from_total(self) -> None:
61 paradise24 = Paradise24()
63 # Not an exhaustive test of all values as that would not be
64 # particularly useful. Enough to check the lookup
65 # is working.
66 paradise24.total_score = mock.Mock(return_value=48)
67 self.assertEqual(paradise24.metric_score(), 100)
69 paradise24.total_score = mock.Mock(return_value=24)
70 self.assertEqual(paradise24.metric_score(), 64)
72 paradise24.total_score = mock.Mock(return_value=0)
73 self.assertEqual(paradise24.metric_score(), 0)
75 paradise24.total_score = mock.Mock(return_value=None)
76 self.assertIsNone(paradise24.metric_score())