Coverage for tasks/tests/maas_tests.py: 38%
26 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/maas_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"""
28import pendulum
30from camcops_server.cc_modules.cc_testfactories import (
31 PatientFactory,
32 UserFactory,
33)
34from camcops_server.cc_modules.cc_unittest import DemoRequestTestCase
35from camcops_server.tasks.maas import Maas, MaasReport
36from camcops_server.tasks.tests.factories import MaasFactory
39class MaasReportTests(DemoRequestTestCase):
40 PROGRESS_COL = 4
42 def setUp(self) -> None:
43 super().setUp()
45 self.report = self.create_report()
46 self.req._debugging_user = UserFactory(superuser=True)
48 patient = PatientFactory()
50 # Default to answering 1 to everything
51 response_dict = {q: 1 for q in Maas.TASK_FIELDS}
53 # Same patient completing the task at different intervals
54 response_dict["q1"] = 2
55 response_dict["q2"] = 2
56 MaasFactory(
57 patient=patient,
58 when_created=pendulum.parse("2019-03-01"),
59 **response_dict,
60 ) # total 17 * 1 + 2 + 2 = 21
62 response_dict["q1"] = 5
63 response_dict["q2"] = 5
64 MaasFactory(
65 patient=patient,
66 when_created=pendulum.parse("2019-06-01"),
67 **response_dict,
68 ) # total 17 * 1 + 5 + 5 = 27
70 def create_report(self) -> MaasReport:
71 return MaasReport(via_index=False)
73 def test_average_progress_is_positive(self) -> None:
74 pages = self.report.get_spreadsheet_pages(req=self.req)
76 # Numbers as above
77 expected_progress = 27 - 21
78 actual_progress = pages[0].plainrows[0][self.PROGRESS_COL]
80 self.assertEqual(actual_progress, expected_progress)