Coverage for tasks/tests/cpft_covid_medical_tests.py: 35%

1"""

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

29 import unittest

30

31 from camcops_server.tasks.cpft_covid_medical import CpftCovidMedical

32

33

34 class CpftCovidMedicalTests(unittest.TestCase):

35 def setUp(self) -> None:

36 super().setUp()

37

38 self.request = mock.Mock()

39

40 def test_complete_when_all_answers_valid(self) -> None:

41 task = CpftCovidMedical()

42

43 task.how_and_when_symptoms = 0

44

45 self.assertTrue(task.is_complete())

46

47 def test_incomplete_when_symptoms_null(self) -> None:

48 task = CpftCovidMedical()

49

50 self.assertFalse(task.is_complete())

51

52 def test_incomplete_when_any_field_invalid(self) -> None:

53 all_fields = ["how_and_when_symptoms"]

54

55 for invalid_field in all_fields:

56 task = CpftCovidMedical()

57

58 for field in all_fields:

59 setattr(task, field, 0)

60

61 self.assertTrue(task.is_complete())

62

63 setattr(task, invalid_field, 10.5)

64 self.assertFalse(

65 task.is_complete(),

66 msg=f"Failed when setting {invalid_field} invalid",

67 )