Coverage for tasks/tests/cia_tests.py: 31%
35 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/cia_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 TestCase
32from camcops_server.tasks.cia import Cia
35class CiaTests(TestCase):
36 def test_complete_when_all_answers_valid(self) -> None:
37 cia = Cia()
39 for q_num in range(1, 16 + 1):
40 setattr(cia, f"q{q_num}", 0)
42 self.assertTrue(cia.is_complete())
44 def test_not_complete_when_not_started(self) -> None:
45 cia = Cia()
47 self.assertFalse(cia.is_complete())
49 def test_complete_when_all_mandatory_answers_valid(self) -> None:
50 cia = Cia()
52 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16):
53 setattr(cia, f"q{q_num}", 3)
55 self.assertTrue(cia.is_complete())
57 def test_max_global_score_for_all_answers(self) -> None:
58 cia = Cia()
60 for q_num in range(1, 16 + 1):
61 setattr(cia, f"q{q_num}", 3)
63 self.assertEqual(cia.global_score(), 48)
65 def test_global_score_is_prorated_for_mandatory_questions(self) -> None:
66 cia = Cia()
68 for q_num in (1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16):
69 setattr(cia, f"q{q_num}", 3)
71 self.assertEqual(cia.global_score(), 48)
73 def test_global_score_is_not_rated_when_mandatory_questions_not_answered(
74 self,
75 ) -> None:
76 cia = Cia()
78 for q_num in (3, 4, 7, 10):
79 setattr(cia, f"q{q_num}", 3)
81 self.assertIsNone(cia.global_score())
83 def test_global_score_is_not_rated_for_any_unanswered_questions(
84 self,
85 ) -> None:
86 cia = Cia()
88 self.assertIsNone(cia.global_score())