|
64 | 64 | RAND_LEN = 15 |
65 | 65 | SCOPES = ['https://www.googleapis.com/auth/cloud-platform'] |
66 | 66 |
|
| 67 | +# Tag 00081190 contains temp store name which contains currentDate |
| 68 | +VOLATILE_TAGS = {"00081190"} |
| 69 | + |
| 70 | + |
| 71 | +def normalize_outer(elem: dict) -> dict: |
| 72 | + elem = dict(elem) # shallow copy |
| 73 | + elem["result"] = [normalize_instance(d) for d in elem.get("result", [])] |
| 74 | + return elem |
| 75 | + |
| 76 | + |
| 77 | +def normalize_instance(instance: dict) -> dict: |
| 78 | + return {k: v for k, v in instance.items() if k not in VOLATILE_TAGS} |
| 79 | + |
67 | 80 |
|
68 | 81 | def random_string_generator(length): |
69 | 82 | letters_and_digits = string.ascii_letters + string.digits |
@@ -173,17 +186,22 @@ def test_dicom_search_instances(self): |
173 | 186 | results_all = ( |
174 | 187 | p |
175 | 188 | | 'create all dict' >> beam.Create([input_dict_all]) |
176 | | - | 'search all' >> DicomSearch()) |
| 189 | + | 'search all' >> DicomSearch() |
| 190 | + | 'normalize all' >> beam.Map(normalize_outer)) |
177 | 191 | results_refine = ( |
178 | 192 | p |
179 | 193 | | 'create refine dict' >> beam.Create([input_dict_refine]) |
180 | | - | 'search refine' >> DicomSearch()) |
| 194 | + | 'search refine' >> DicomSearch() |
| 195 | + | 'normalize refine' >> beam.Map(normalize_outer)) |
| 196 | + |
| 197 | + expected_all_norm = normalize_outer(expected_dict_all) |
| 198 | + expected_refine_norm = normalize_outer(expected_dict_refine) |
181 | 199 |
|
182 | 200 | assert_that( |
183 | | - results_all, equal_to([expected_dict_all]), label='all search assert') |
| 201 | + results_all, equal_to([expected_all_norm]), label='all search assert') |
184 | 202 | assert_that( |
185 | 203 | results_refine, |
186 | | - equal_to([expected_dict_refine]), |
| 204 | + equal_to([expected_refine_norm]), |
187 | 205 | label='refine search assert') |
188 | 206 |
|
189 | 207 | @pytest.mark.it_postcommit |
@@ -218,8 +236,13 @@ def test_dicom_store_instance_from_gcs(self): |
218 | 236 |
|
219 | 237 | self.assertEqual(status_code, 200) |
220 | 238 |
|
221 | | - # List comparison based on different version of python |
222 | | - self.assertCountEqual(result, self.expected_output_all_metadata) |
| 239 | + actual_norm = [normalize_instance(r) for r in result] |
| 240 | + expected_norm = [ |
| 241 | + normalize_instance(r) for r in self.expected_output_all_metadata |
| 242 | + ] |
| 243 | + |
| 244 | + # Order-insensitive deep equality |
| 245 | + self.assertCountEqual(actual_norm, expected_norm) |
223 | 246 |
|
224 | 247 |
|
225 | 248 | if __name__ == '__main__': |
|
0 commit comments