Coverage for anonymise/tests/ddr_tests.py: 100%
17 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/ddr_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===============================================================================
26Data Dictionary Row tests
28"""
30from unittest import mock, TestCase
32from sqlalchemy import String
34from crate_anon.anonymise.ddr import DataDictionaryRow
37class DataDictionaryRowTests(TestCase):
38 def test_odd_chars_replaced_in_dest_table(self) -> None:
39 mock_config = mock.Mock()
40 ddr = DataDictionaryRow(mock_config)
41 # unicode n-dash ------------------------v
42 test_table = f"A b(c)d/e|f\tg{chr(0x80)}h–i"
43 test_field = test_table
45 src_datatype_sqltext = "" # Arbitrary
46 src_sqla_coltype = String()
47 mock_db_config = mock.Mock(
48 bin2text_dict={},
49 ddgen_convert_odd_chars_to_underscore=True,
50 ddgen_extra_hash_fields={},
51 ddgen_filename_to_text_fields=[],
52 ddgen_force_lower_case=False,
53 ddgen_include_fields=[],
54 ddgen_master_pid_fieldname="nhs_num",
55 ddgen_min_length_for_scrubbing=50,
56 ddgen_omit_fields=[],
57 ddgen_patient_opt_out_fields=[],
58 ddgen_per_table_pid_field="patient_id",
59 ddgen_pid_defining_fieldnames=[],
60 ddgen_pk_fields=[],
61 ddgen_rename_tables_remove_suffixes=[],
62 ddgen_required_scrubsrc_fields=[],
63 ddgen_safe_fields_exempt_from_scrubbing=[],
64 ddgen_scrubsrc_patient_fields=[],
65 ddgen_scrubsrc_thirdparty_fields=[],
66 ddgen_scrubsrc_thirdparty_xref_pid_fields=[],
67 ddgen_truncate_date_fields=[],
68 )
69 ddr.set_from_src_db_info(
70 "test_db",
71 test_table,
72 test_field,
73 src_datatype_sqltext,
74 src_sqla_coltype,
75 mock_db_config,
76 )
78 expected_table = "A_b_c_d_e_f_g_h_i"
79 expected_field = expected_table
81 self.assertEqual(ddr.dest_table, expected_table)
82 self.assertEqual(ddr.dest_field, expected_field)