Coverage for tasks/tests/paradise24_tests.py: 28%

1"""

2 camcops_server/tasks/tests/paradise24_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.paradise24 import Paradise24

31

32

33 class Paradise24Tests(TestCase):

34 def test_complete_when_all_answers_valid(self) -> None:

35 paradise24 = Paradise24()

36

37 for q_num in range(1, 24 + 1):

38 setattr(paradise24, f"q{q_num}", 0)

39

40 self.assertTrue(paradise24.is_complete())

41

42 def test_is_complete_false_when_not_finished(self) -> None:

43 paradise24 = Paradise24()

44

45 self.assertFalse(paradise24.is_complete())

46

47 def test_total_score_none_when_not_complete(self) -> None:

48 paradise24 = Paradise24()

49

50 self.assertIsNone(paradise24.total_score())

51

52 def test_total_score_is_sum_of_all_answers(self) -> None:

53 paradise24 = Paradise24()

54

55 for q_num in range(1, 24 + 1):

56 setattr(paradise24, f"q{q_num}", 2)

57

58 self.assertEqual(paradise24.total_score(), 48)

59

60 def test_metric_score_derived_from_total(self) -> None:

61 paradise24 = Paradise24()

62

63 # Not an exhaustive test of all values as that would not be

64 # particularly useful. Enough to check the lookup

65 # is working.

66 paradise24.total_score = mock.Mock(return_value=48)

67 self.assertEqual(paradise24.metric_score(), 100)

68

69 paradise24.total_score = mock.Mock(return_value=24)

70 self.assertEqual(paradise24.metric_score(), 64)

71

72 paradise24.total_score = mock.Mock(return_value=0)

73 self.assertEqual(paradise24.metric_score(), 0)

74

75 paradise24.total_score = mock.Mock(return_value=None)

76 self.assertIsNone(paradise24.metric_score())