Coverage for anonymise/tests/models_tests.py: 100%
13 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
1"""
2crate_anon/anonymise/tests/models_tests.py
4===============================================================================
6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CRATE.
11 CRATE 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 CRATE 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 CRATE. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26"""
28import random
29from unittest import mock
31from crate_anon.anonymise.models import PatientInfo
32from crate_anon.testing.classes import SlowSecretDatabaseTestCase
35class PatientInfoTests(SlowSecretDatabaseTestCase):
36 def test_patient_saved_with_random_trid(self) -> None:
37 expected_trids = [7, 1, 5, 6, 4, 10, 3, 2, 9, 8]
39 with mock.patch.multiple(
40 "crate_anon.anonymise.models",
41 MAX_TRID=10,
42 ):
43 random.seed(12345)
45 for i, expected_trid in enumerate(expected_trids):
46 patient = PatientInfo(pid=i + 1)
47 patient.ensure_trid(self.secret_dbsession)
48 self.assertEqual(patient.trid, expected_trid)