Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/tasks/tests/maas_tests.py 

5 

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

7 

8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com). 

9 

10 This file is part of CamCOPS. 

11 

12 CamCOPS is free software: you can redistribute it and/or modify 

13 it under the terms of the GNU General Public License as published by 

14 the Free Software Foundation, either version 3 of the License, or 

15 (at your option) any later version. 

16 

17 CamCOPS is distributed in the hope that it will be useful, 

18 but WITHOUT ANY WARRANTY; without even the implied warranty of 

19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

20 GNU General Public License for more details. 

21 

22 You should have received a copy of the GNU General Public License 

23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>. 

24 

25=============================================================================== 

26 

27""" 

28 

29import pendulum 

30from camcops_server.cc_modules.cc_patient import Patient 

31from camcops_server.tasks.maas import Maas, MaasReport 

32 

33from camcops_server.cc_modules.tests.cc_report_tests import ( 

34 AverageScoreReportTestCase 

35) 

36 

37 

38class MaasReportTests(AverageScoreReportTestCase): 

39 PROGRESS_COL = 4 

40 

41 def create_report(self) -> MaasReport: 

42 return MaasReport(via_index=False) 

43 

44 def create_tasks(self) -> None: 

45 self.patient_1 = self.create_patient() 

46 

47 self.create_task(patient=self.patient_1, q1=2, q2=2, 

48 era="2019-03-01") # total 17 + 2 + 2 

49 self.create_task(patient=self.patient_1, q1=5, q2=5, 

50 era="2019-06-01") # total 17 + 5 + 5 

51 self.dbsession.commit() 

52 

53 def create_task(self, patient: Patient, era: str = None, **kwargs) -> None: 

54 task = Maas() 

55 self.apply_standard_task_fields(task) 

56 task.id = next(self.task_id_sequence) 

57 

58 task.patient_id = patient.id 

59 for fieldname in Maas.TASK_FIELDS: 

60 value = kwargs.get(fieldname, 1) 

61 setattr(task, fieldname, value) 

62 

63 if era is not None: 

64 task.when_created = pendulum.parse(era) 

65 

66 self.dbsession.add(task) 

67 

68 def test_average_progress_is_positive(self) -> None: 

69 tsv_pages = self.report.get_tsv_pages(req=self.req) 

70 

71 expected_progress = 27 - 21 

72 actual_progress = tsv_pages[0].plainrows[0][self.PROGRESS_COL] 

73 

74 self.assertEqual(actual_progress, expected_progress)