Coverage for tasks/tests/cia_tests.py: 29%
34 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/cia_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 TestCase
30from camcops_server.tasks.cia import Cia
33class CiaTests(TestCase):
34 def test_complete_when_all_answers_valid(self) -> None:
35 cia = Cia()
37 for q_num in range(1, 16 + 1):
38 setattr(cia, f"q{q_num}", 0)
40 self.assertTrue(cia.is_complete())
42 def test_not_complete_when_not_started(self) -> None:
43 cia = Cia()
45 self.assertFalse(cia.is_complete())
47 def test_complete_when_all_mandatory_answers_valid(self) -> None:
48 cia = Cia()
50 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16):
51 setattr(cia, f"q{q_num}", 3)
53 self.assertTrue(cia.is_complete())
55 def test_max_global_score_for_all_answers(self) -> None:
56 cia = Cia()
58 for q_num in range(1, 16 + 1):
59 setattr(cia, f"q{q_num}", 3)
61 self.assertEqual(cia.global_score(), 48)
63 def test_global_score_is_prorated_for_mandatory_questions(self) -> None:
64 cia = Cia()
66 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16):
67 setattr(cia, f"q{q_num}", 3)
69 self.assertEqual(cia.global_score(), 48)
71 def test_global_score_is_not_rated_when_mandatory_questions_not_answered(
72 self,
73 ) -> None:
74 cia = Cia()
76 for q_num in (3, 4, 7, 10):
77 setattr(cia, f"q{q_num}", 3)
79 self.assertIsNone(cia.global_score())
81 def test_global_score_is_not_rated_for_any_unanswered_questions(
82 self,
83 ) -> None:
84 cia = Cia()
86 self.assertIsNone(cia.global_score())