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

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/tasks/tests/maas_tests.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

10 

11 This file is part of CamCOPS. 

12 

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. 

17 

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. 

22 

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/>. 

25 

26=============================================================================== 

27 

28""" 

29 

30import pendulum 

31 

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 

37 

38 

39class MaasReportTests(AverageScoreReportTestCase): 

40 PROGRESS_COL = 4 

41 

42 def create_report(self) -> MaasReport: 

43 return MaasReport(via_index=False) 

44 

45 def create_tasks(self) -> None: 

46 self.patient_1 = self.create_patient() 

47 

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() 

55 

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) 

60 

61 task.patient_id = patient.id 

62 for fieldname in Maas.TASK_FIELDS: 

63 value = kwargs.get(fieldname, 1) 

64 setattr(task, fieldname, value) 

65 

66 if era is not None: 

67 task.when_created = pendulum.parse(era) 

68 

69 self.dbsession.add(task) 

70 

71 def test_average_progress_is_positive(self) -> None: 

72 pages = self.report.get_spreadsheet_pages(req=self.req) 

73 

74 expected_progress = 27 - 21 

75 actual_progress = pages[0].plainrows[0][self.PROGRESS_COL] 

76 

77 self.assertEqual(actual_progress, expected_progress)