Coverage for tasks/tests/maas_tests.py: 37%
30 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/maas_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"""
30import pendulum
32from camcops_server.cc_modules.cc_patient import Patient
33from camcops_server.cc_modules.tests.cc_report_tests import (
34 AverageScoreReportTestCase,
35)
36from camcops_server.tasks.maas import Maas, MaasReport
39class MaasReportTests(AverageScoreReportTestCase):
40 PROGRESS_COL = 4
42 def create_report(self) -> MaasReport:
43 return MaasReport(via_index=False)
45 def create_tasks(self) -> None:
46 self.patient_1 = self.create_patient()
48 self.create_task(
49 patient=self.patient_1, q1=2, q2=2, era="2019-03-01"
50 ) # total 17 + 2 + 2
51 self.create_task(
52 patient=self.patient_1, q1=5, q2=5, era="2019-06-01"
53 ) # total 17 + 5 + 5
54 self.dbsession.commit()
56 def create_task(self, patient: Patient, era: str = None, **kwargs) -> None:
57 task = Maas()
58 self.apply_standard_task_fields(task)
59 task.id = next(self.task_id_sequence)
61 task.patient_id = patient.id
62 for fieldname in Maas.TASK_FIELDS:
63 value = kwargs.get(fieldname, 1)
64 setattr(task, fieldname, value)
66 if era is not None:
67 task.when_created = pendulum.parse(era)
69 self.dbsession.add(task)
71 def test_average_progress_is_positive(self) -> None:
72 pages = self.report.get_spreadsheet_pages(req=self.req)
74 expected_progress = 27 - 21
75 actual_progress = pages[0].plainrows[0][self.PROGRESS_COL]
77 self.assertEqual(actual_progress, expected_progress)