Coverage for tasks/tests/edeq_tests.py: 15%

1"""

2 camcops_server/tasks/tests/edeq_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

28 from unittest import mock, TestCase

29

30 from camcops_server.tasks.edeq import Edeq

31

32

33 class EdeqTests(TestCase):

34 def test_restraint_subscale(self):

35 edeq = Edeq()

36

37 edeq.q1 = 1

38 edeq.q2 = 2

39 edeq.q3 = 3

40 edeq.q4 = 4

41 edeq.q5 = 6

42

43 # 1 + 2 + 3 + 4 + 6 = 16

44 # 16 / 5 = 3.2

45

46 self.assertEqual(edeq.restraint(), 3.2)

47

48 def test_subscale_none_if_answer_none(self):

49 edeq = Edeq()

50

51 edeq.q1 = None

52 edeq.q2 = 2

53 edeq.q3 = 3

54 edeq.q4 = 4

55 edeq.q5 = 6

56

57 self.assertIsNone(edeq.restraint())

58

59 def test_eating_concern_subscale(self):

60 edeq = Edeq()

61

62 edeq.q7 = 1

63 edeq.q9 = 2

64 edeq.q19 = 3

65 edeq.q21 = 4

66 edeq.q20 = 6

67

68 # 1 + 2 + 3 + 4 + 6 = 16

69 # 16 / 5 = 3.2

70

71 self.assertEqual(edeq.eating_concern(), 3.2)

72

73 def test_shape_concern_subscale(self):

74 edeq = Edeq()

75

76 edeq.q6 = 1

77 edeq.q8 = 2

78 edeq.q23 = 3

79 edeq.q10 = 4

80 edeq.q26 = 5

81 edeq.q27 = 6

82 edeq.q28 = 3

83 edeq.q11 = 4

84

85 # 1 + 2 + 3 + 4 + 5 + 6 + 3 + 4 = 28

86 # 28 / 8 = 3.5

87

88 self.assertEqual(edeq.shape_concern(), 3.5)

89

90 def test_weight_concern_subscale(self):

91 edeq = Edeq()

92

93 edeq.q8 = 1

94 edeq.q12 = 2

95 edeq.q22 = 3

96 edeq.q24 = 4

97 edeq.q25 = 6

98

99 # 1 + 2 + 3 + 4 + 6 = 16

100 # 16 / 5 = 3.2

101

102 self.assertEqual(edeq.weight_concern(), 3.2)

103

104 def test_complete_when_all_answers_valid_for_female(self) -> None:

105 edeq = Edeq()

106 edeq.patient = mock.Mock(sex="F")

107

108 for q_num in range(1, 28 + 1):

109 setattr(edeq, f"q{q_num}", 0)

110

111 edeq.mass_kg = 67.0

112 edeq.height_m = 1.83

113

114 edeq.num_periods_missed = 1

115 edeq.pill = False

116

117 self.assertTrue(edeq.is_complete())

118

119 def test_incomplete_when_female_misses_female_questions(self) -> None:

120 edeq = Edeq()

121 edeq.patient = mock.Mock(sex="F")

122

123 for q_num in range(1, 28 + 1):

124 setattr(edeq, f"q{q_num}", 0)

125

126 edeq.mass_kg = 67.0

127 edeq.height_m = 1.83

128

129 edeq.num_periods_missed = None

130 edeq.pill = None

131

132 self.assertFalse(edeq.is_complete())

133

134 def test_complete_when_all_answers_valid_for_male(self) -> None:

135 edeq = Edeq()

136 edeq.patient = mock.Mock(sex="M")

137

138 for q_num in range(1, 28 + 1):

139 setattr(edeq, f"q{q_num}", 0)

140

141 edeq.mass_kg = 67.0

142 edeq.height_m = 1.83

143

144 edeq.num_periods_missed = None

145 edeq.pill = None

146

147 self.assertTrue(edeq.is_complete())

148

149 def test_is_complete_false_when_not_finished(self) -> None:

150 edeq = Edeq()

151

152 self.assertFalse(edeq.is_complete())

153

154 def test_global_score_is_mean_of_subscales(self) -> None:

155 edeq = Edeq()

156

157 edeq.restraint = mock.Mock(return_value=1)

158 edeq.eating_concern = mock.Mock(return_value=2)

159 edeq.shape_concern = mock.Mock(return_value=3)

160 edeq.weight_concern = mock.Mock(return_value=4)

161

162 # (1 + 2 + 3 + 4) / 4

163 self.assertEqual(edeq.global_score(), 2.5)

164

165 def test_global_score_none_if_any_subscale_none(self) -> None:

166 edeq = Edeq()

167

168 edeq.restraint = mock.Mock(return_value=1)

169 edeq.eating_concern = mock.Mock(return_value=2)

170 edeq.shape_concern = mock.Mock(return_value=3)

171 edeq.weight_concern = mock.Mock(return_value=None)

172

173 self.assertIsNone(edeq.global_score())