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

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

30from unittest import mock, TestCase 

31 

32from camcops_server.tasks.paradise24 import Paradise24 

33 

34 

35class Paradise24Tests(TestCase): 

36 def test_complete_when_all_answers_valid(self) -> None: 

37 paradise24 = Paradise24() 

38 

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

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

41 

42 self.assertTrue(paradise24.is_complete()) 

43 

44 def test_is_complete_false_when_not_finished(self) -> None: 

45 paradise24 = Paradise24() 

46 

47 self.assertFalse(paradise24.is_complete()) 

48 

49 def test_total_score_none_when_not_complete(self) -> None: 

50 paradise24 = Paradise24() 

51 

52 self.assertIsNone(paradise24.total_score()) 

53 

54 def test_total_score_is_sum_of_all_answers(self) -> None: 

55 paradise24 = Paradise24() 

56 

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

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

59 

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

61 

62 def test_metric_score_derived_from_total(self) -> None: 

63 paradise24 = Paradise24() 

64 

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

66 # particularly useful. Enough to check the lookup 

67 # is working. 

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

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

70 

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

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

73 

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

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

76 

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

78 self.assertIsNone(paradise24.metric_score())