Coverage for tasks/tests/perinatalpoem_tests.py: 23%

75 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 13:48 +0000

1""" 

2camcops_server/tasks/tests/perinatalpoem_tests.py 

3 

4=============================================================================== 

5 

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

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

8 

9 This file is part of CamCOPS. 

10 

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. 

15 

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. 

20 

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

23 

24=============================================================================== 

25 

26""" 

27 

28from camcops_server.cc_modules.cc_unittest import DemoRequestTestCase 

29from camcops_server.tasks.perinatalpoem import PerinatalPoemReport 

30from camcops_server.tasks.tests.factories import PerinatalPoemFactory 

31 

32# ============================================================================= 

33# Unit tests 

34# ============================================================================= 

35 

36 

37class PerinatalPoemReportTestCase(DemoRequestTestCase): 

38 def setUp(self) -> None: 

39 super().setUp() 

40 

41 self.report = PerinatalPoemReport() 

42 

43 # Really only needed for tests 

44 self.report.start_datetime = None 

45 self.report.end_datetime = None 

46 

47 

48class PerinatalPoemReportTests(PerinatalPoemReportTestCase): 

49 """ 

50 Most of the base class tested in APEQCPFT Perinatal so just some basic 

51 sanity checking here 

52 """ 

53 

54 def setUp(self) -> None: 

55 super().setUp() 

56 

57 t1 = PerinatalPoemFactory(general_comments="comment 1") 

58 t2 = PerinatalPoemFactory(general_comments="comment 2") 

59 t3 = PerinatalPoemFactory(general_comments="comment 3") 

60 

61 self.dbsession.add(t1) 

62 self.dbsession.add(t2) 

63 self.dbsession.add(t3) 

64 

65 self.dbsession.commit() 

66 

67 def test_qa_rows_counts(self) -> None: 

68 tables = self.report._get_html_tables(self.req) 

69 

70 rows = tables[0].rows 

71 

72 self.assertEqual(len(rows), 1) 

73 self.assertEqual(len(rows[0]), 4) 

74 

75 def test_qb_rows_counts(self) -> None: 

76 tables = self.report._get_html_tables(self.req) 

77 

78 rows = tables[1].rows 

79 

80 self.assertEqual(len(rows), 1) 

81 self.assertEqual(len(rows[0]), 4) 

82 

83 def test_q1_rows_counts(self) -> None: 

84 tables = self.report._get_html_tables(self.req) 

85 

86 rows = tables[2].rows 

87 

88 self.assertEqual(len(rows), 2) 

89 self.assertEqual(len(rows[0]), 7) 

90 

91 def test_q2_rows_counts(self) -> None: 

92 tables = self.report._get_html_tables(self.req) 

93 

94 rows = tables[3].rows 

95 

96 self.assertEqual(len(rows), 12) 

97 self.assertEqual(len(rows[0]), 6) 

98 

99 def test_q3_rows_counts(self) -> None: 

100 tables = self.report._get_html_tables(self.req) 

101 

102 rows = tables[4].rows 

103 

104 self.assertEqual(len(rows), 6) 

105 self.assertEqual(len(rows[0]), 6) 

106 

107 def test_participation_rows_counts(self) -> None: 

108 tables = self.report._get_html_tables(self.req) 

109 

110 rows = tables[5].rows 

111 

112 self.assertEqual(len(rows), 1) 

113 self.assertEqual(len(rows[0]), 4) 

114 

115 def test_comments(self) -> None: 

116 expected_comments = ["comment 1", "comment 2", "comment 3"] 

117 comments = self.report._get_comments(self.req) 

118 self.assertEqual(comments, expected_comments) 

119 

120 

121class PerinatalPoemReportDateRangeTests(PerinatalPoemReportTestCase): 

122 def setUp(self) -> None: 

123 super().setUp() 

124 

125 t1 = PerinatalPoemFactory( 

126 general_comments="comments 1", 

127 when_created="2018-10-01T00:00:00.000000+00:00", 

128 ) 

129 t2 = PerinatalPoemFactory( 

130 general_comments="comments 2", 

131 when_created="2018-10-02T00:00:00.000000+00:00", 

132 ) 

133 t3 = PerinatalPoemFactory( 

134 general_comments="comments 3", 

135 when_created="2018-10-03T00:00:00.000000+00:00", 

136 ) 

137 t4 = PerinatalPoemFactory( 

138 general_comments="comments 4", 

139 when_created="2018-10-04T00:00:00.000000+00:00", 

140 ) 

141 t5 = PerinatalPoemFactory( 

142 general_comments="comments 5", 

143 when_created="2018-10-05T00:00:00.000000+00:00", 

144 ) 

145 self.dbsession.add(t1) 

146 self.dbsession.add(t2) 

147 self.dbsession.add(t3) 

148 self.dbsession.add(t4) 

149 self.dbsession.add(t5) 

150 

151 self.dbsession.commit() 

152 

153 def test_comments_filtered_by_date(self) -> None: 

154 self.report.start_datetime = "2018-10-02T00:00:00.000000+00:00" 

155 self.report.end_datetime = "2018-10-05T00:00:00.000000+00:00" 

156 

157 comments = self.report._get_comments(self.req) 

158 self.assertEqual(len(comments), 3) 

159 

160 self.assertEqual(comments[0], "comments 2") 

161 self.assertEqual(comments[1], "comments 3") 

162 self.assertEqual(comments[2], "comments 4")