|
1 | | -import unittest |
| 1 | +"""Unit tests for CreateCaseVersionConverter.convert_v3_to_vactive / |
| 2 | +convert_vactive_to_v3, calling the converter directly (no Flask/HTTP). |
2 | 3 |
|
3 | | -from converter.cisu_version_converters.create_case.rc_eda_version_converter import ( |
| 4 | +convert_v3_to_vactive mirrors from_rs_to_cisu's mapping direction |
| 5 | +(2.3 -> 1.9 nomenclature); convert_vactive_to_v3 mirrors from_cisu_to_rs's |
| 6 | +(1.9 -> 2.3 nomenclature). |
| 7 | +
|
| 8 | +Test cases are generated from the real nomenclature maps rather than |
| 9 | +hardcoded codes, so they stay correct if the maps are regenerated. Each map |
| 10 | +is only exercised on the scenarios it actually contains: as of this writing, |
| 11 | +7 of the 8 (field, direction) maps have no entry mapped to None, and |
| 12 | +riskThreat's v1.9->2.3 map (used by convert_vactive_to_v3) has no entry |
| 13 | +mapped to a value (its single entry maps to None) -- those scenarios are |
| 14 | +legitimately absent, not skipped by omission. |
| 15 | +""" |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from converter.cisu_version_converters.create_case.create_case_version_converter import ( |
4 | 20 | CreateCaseVersionConverter, |
5 | 21 | ) |
| 22 | +from converter.nomenclatures.from_v1_9_to_v2_3.health_motive import ( |
| 23 | + V1_9_TO_V2_3_HEALTH_MOTIVE_MAP, |
| 24 | +) |
| 25 | +from converter.nomenclatures.from_v1_9_to_v2_3.location_kind import ( |
| 26 | + V1_9_TO_V2_3_LOCATION_KIND_MAP, |
| 27 | +) |
| 28 | +from converter.nomenclatures.from_v1_9_to_v2_3.risk_threat import ( |
| 29 | + V1_9_TO_V2_3_RISK_THREAT_MAP, |
| 30 | +) |
| 31 | +from converter.nomenclatures.from_v1_9_to_v2_3.whats_happen import ( |
| 32 | + V1_9_TO_V2_3_WHATS_HAPPEN_MAP, |
| 33 | +) |
| 34 | +from converter.nomenclatures.from_v2_3_to_v1_9.health_motive import ( |
| 35 | + V2_3_TO_V1_9_HEALTH_MOTIVE_MAP, |
| 36 | +) |
| 37 | +from converter.nomenclatures.from_v2_3_to_v1_9.location_kind import ( |
| 38 | + V2_3_TO_V1_9_LOCATION_KIND_MAP, |
| 39 | +) |
| 40 | +from converter.nomenclatures.from_v2_3_to_v1_9.risk_threat import ( |
| 41 | + V2_3_TO_V1_9_RISK_THREAT_MAP, |
| 42 | +) |
| 43 | +from converter.nomenclatures.from_v2_3_to_v1_9.whats_happen import ( |
| 44 | + V2_3_TO_V1_9_WHATS_HAPPEN_MAP, |
| 45 | +) |
| 46 | +from tests.cisu.helpers import get_edxl_message |
6 | 47 | from tests.constants import TestConstants |
7 | 48 | from tests.test_helpers import TestHelper |
8 | 49 |
|
| 50 | +UNCHANGED = "sentinel: field left as injected" |
| 51 | +REMOVED = "sentinel: field removed from qualification" |
| 52 | +UNMAPPED_CODE = "UNMAPPED-TEST-CODE" |
| 53 | + |
| 54 | +BASE_MESSAGE_PATH = "tests/fixtures/RC-EDA/RC-EDA_required_fields.json" |
| 55 | + |
| 56 | +# (qualification field, is a list field, map used by convert_v3_to_vactive, map used by convert_vactive_to_v3) |
| 57 | +FIELD_SPECS = [ |
| 58 | + ( |
| 59 | + "whatsHappen", |
| 60 | + False, |
| 61 | + V2_3_TO_V1_9_WHATS_HAPPEN_MAP, |
| 62 | + V1_9_TO_V2_3_WHATS_HAPPEN_MAP, |
| 63 | + ), |
| 64 | + ( |
| 65 | + "healthMotive", |
| 66 | + False, |
| 67 | + V2_3_TO_V1_9_HEALTH_MOTIVE_MAP, |
| 68 | + V1_9_TO_V2_3_HEALTH_MOTIVE_MAP, |
| 69 | + ), |
| 70 | + ( |
| 71 | + "riskThreat", |
| 72 | + True, |
| 73 | + V2_3_TO_V1_9_RISK_THREAT_MAP, |
| 74 | + V1_9_TO_V2_3_RISK_THREAT_MAP, |
| 75 | + ), |
| 76 | + ( |
| 77 | + "locationKind", |
| 78 | + False, |
| 79 | + V2_3_TO_V1_9_LOCATION_KIND_MAP, |
| 80 | + V1_9_TO_V2_3_LOCATION_KIND_MAP, |
| 81 | + ), |
| 82 | +] |
| 83 | + |
| 84 | + |
| 85 | +def _first_entry(mapping, *, mapped_to_none): |
| 86 | + return next( |
| 87 | + ( |
| 88 | + (code, value) |
| 89 | + for code, value in mapping.items() |
| 90 | + if (value is None) == mapped_to_none |
| 91 | + ), |
| 92 | + None, |
| 93 | + ) |
| 94 | + |
| 95 | + |
| 96 | +def _build_cases(): |
| 97 | + cases = [] |
| 98 | + for field, is_list, v3_to_vactive_map, vactive_to_v3_map in FIELD_SPECS: |
| 99 | + for method_name, mapping in [ |
| 100 | + ("convert_v3_to_vactive", v3_to_vactive_map), |
| 101 | + ("convert_vactive_to_v3", vactive_to_v3_map), |
| 102 | + ]: |
| 103 | + cases.append( |
| 104 | + pytest.param( |
| 105 | + field, |
| 106 | + is_list, |
| 107 | + method_name, |
| 108 | + UNMAPPED_CODE, |
| 109 | + UNCHANGED, |
| 110 | + id=f"{field}-{method_name}-unmapped", |
| 111 | + ) |
| 112 | + ) |
| 113 | + |
| 114 | + mapped_value_entry = _first_entry(mapping, mapped_to_none=False) |
| 115 | + if mapped_value_entry is not None: |
| 116 | + code, expected_value = mapped_value_entry |
| 117 | + cases.append( |
| 118 | + pytest.param( |
| 119 | + field, |
| 120 | + is_list, |
| 121 | + method_name, |
| 122 | + code, |
| 123 | + expected_value, |
| 124 | + id=f"{field}-{method_name}-mapped_to_value", |
| 125 | + ) |
| 126 | + ) |
| 127 | + |
| 128 | + mapped_none_entry = _first_entry(mapping, mapped_to_none=True) |
| 129 | + if mapped_none_entry is not None: |
| 130 | + code, _ = mapped_none_entry |
| 131 | + cases.append( |
| 132 | + pytest.param( |
| 133 | + field, |
| 134 | + is_list, |
| 135 | + method_name, |
| 136 | + code, |
| 137 | + REMOVED, |
| 138 | + id=f"{field}-{method_name}-mapped_to_none", |
| 139 | + ) |
| 140 | + ) |
| 141 | + return cases |
| 142 | + |
| 143 | + |
| 144 | +@pytest.mark.parametrize( |
| 145 | + "field, is_list, method_name, injected_code, expected", |
| 146 | + _build_cases(), |
| 147 | +) |
| 148 | +def test_nomenclature_mapping(field, is_list, method_name, injected_code, expected): |
| 149 | + message = TestHelper.create_edxl_json_from_sample( |
| 150 | + TestConstants.EDXL_FIRE_TO_HEALTH_ENVELOPE_PATH, BASE_MESSAGE_PATH |
| 151 | + ) |
| 152 | + injected_value = {"code": injected_code, "label": "Libellé de test"} |
| 153 | + qualification = get_edxl_message(message)["createCase"]["qualification"] |
| 154 | + qualification[field] = [injected_value] if is_list else injected_value |
| 155 | + |
| 156 | + convert = getattr(CreateCaseVersionConverter, method_name) |
| 157 | + result = convert(message) |
| 158 | + |
| 159 | + result_qualification = get_edxl_message(result)["createCase"]["qualification"] |
9 | 160 |
|
10 | | -class TestCreateCaseVersionConverter(unittest.TestCase): |
11 | | - def setUp(self): |
12 | | - self.edxl_envelope_health_to_fire_path = ( |
13 | | - TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH |
14 | | - ) |
15 | | - self.edxl_envelope_fire_to_health_path = ( |
16 | | - TestConstants.EDXL_FIRE_TO_HEALTH_ENVELOPE_PATH |
17 | | - ) |
18 | | - self.fixtures_folder_path = "tests/fixtures/" |
19 | | - self.converter = CreateCaseVersionConverter |
20 | | - |
21 | | - def test_v3_to_vactive(self): |
22 | | - message = TestHelper.create_edxl_json_from_sample( |
23 | | - self.edxl_envelope_health_to_fire_path, |
24 | | - self.fixtures_folder_path + "RC-EDA/RC-EDA_exhaustive_fill.json", |
25 | | - ) |
26 | | - converted_message = self.converter.convert_v3_to_vactive(message) |
27 | | - assert converted_message == message |
28 | | - |
29 | | - def test_vactive_to_v3(self): |
30 | | - message = TestHelper.create_edxl_json_from_sample( |
31 | | - self.edxl_envelope_fire_to_health_path, |
32 | | - self.fixtures_folder_path + "RC-EDA/RC-EDA_exhaustive_fill.json", |
33 | | - ) |
34 | | - converted_message = self.converter.convert_vactive_to_v3(message) |
35 | | - assert converted_message == message |
| 161 | + if expected == REMOVED: |
| 162 | + assert field not in result_qualification |
| 163 | + elif expected == UNCHANGED: |
| 164 | + expected_field_value = [injected_value] if is_list else injected_value |
| 165 | + assert result_qualification[field] == expected_field_value |
| 166 | + else: |
| 167 | + expected_field_value = [expected] if is_list else expected |
| 168 | + assert result_qualification[field] == expected_field_value |
0 commit comments