Coverage for cc_modules/tests/cc_task_collection_tests.py: 38%
16 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 13:48 +0000
1"""
2camcops_server/cc_modules/tests/cc_taskcollection_tests.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
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.
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.
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/>.
24===============================================================================
26"""
28from kombu.serialization import dumps, loads
29from camcops_server.cc_modules.cc_taskcollection import (
30 TaskCollection,
31 TaskSortMethod,
32)
34from camcops_server.cc_modules.cc_taskfilter import TaskFilter
35from camcops_server.cc_modules.cc_unittest import BasicDatabaseTestCase
38# =============================================================================
39# Unit tests
40# =============================================================================
43class TaskCollectionTests(BasicDatabaseTestCase):
44 def test_it_can_be_serialized(self) -> None:
45 taskfilter = TaskFilter()
46 taskfilter.task_types = ["task1", "task2", "task3"]
47 taskfilter.group_ids = [1, 2, 3]
49 coll = TaskCollection(
50 self.req,
51 taskfilter=taskfilter,
52 as_dump=True,
53 sort_method_by_class=TaskSortMethod.CREATION_DATE_ASC,
54 )
55 content_type, encoding, data = dumps(coll, serializer="json")
56 new_coll = loads(data, content_type, encoding)
58 self.assertEqual(new_coll._as_dump, True)
59 self.assertEqual(
60 new_coll._sort_method_by_class, TaskSortMethod.CREATION_DATE_ASC
61 )
62 self.assertEqual(
63 new_coll._filter.task_types, ["task1", "task2", "task3"]
64 )
65 self.assertEqual(new_coll._filter.group_ids, [1, 2, 3])