Coverage for cc_modules/tests/cc_task_collection_tests.py: 41%
17 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/tests/cc_taskcollection_tests.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
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.
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.
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/>.
26===============================================================================
28"""
30from kombu.serialization import dumps, loads
31from camcops_server.cc_modules.cc_taskcollection import (
32 TaskCollection,
33 TaskSortMethod,
34)
36from camcops_server.cc_modules.cc_taskfilter import TaskFilter
37from camcops_server.cc_modules.cc_unittest import BasicDatabaseTestCase
40# =============================================================================
41# Unit tests
42# =============================================================================
45class TaskCollectionTests(BasicDatabaseTestCase):
46 def test_it_can_be_serialized(self) -> None:
47 taskfilter = TaskFilter()
48 taskfilter.task_types = ["task1", "task2", "task3"]
49 taskfilter.group_ids = [1, 2, 3]
51 coll = TaskCollection(
52 self.req,
53 taskfilter=taskfilter,
54 as_dump=True,
55 sort_method_by_class=TaskSortMethod.CREATION_DATE_ASC,
56 )
57 content_type, encoding, data = dumps(coll, serializer="json")
58 new_coll = loads(data, content_type, encoding)
60 self.assertEqual(new_coll._as_dump, True)
61 self.assertEqual(
62 new_coll._sort_method_by_class, TaskSortMethod.CREATION_DATE_ASC
63 )
64 self.assertEqual(
65 new_coll._filter.task_types, ["task1", "task2", "task3"]
66 )
67 self.assertEqual(new_coll._filter.group_ids, [1, 2, 3])