From 094eb7dc5d7bc9f3de9ef57e8d764f0d8defe037 Mon Sep 17 00:00:00 2001 From: Svetak Sundhar Date: Mon, 8 Jan 2024 23:09:05 +0000 Subject: [PATCH] Increase granularity of DICOM IO Unit Tests (#29956) * Create HealthcareUtils file with shared resources * revert * Adding more granular test cases to missing DicomIO inputs. --- .../io/gcp/healthcare/dicomio_test.py | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/io/gcp/healthcare/dicomio_test.py b/sdks/python/apache_beam/io/gcp/healthcare/dicomio_test.py index 812f258576851..30e5d4c0f7708 100644 --- a/sdks/python/apache_beam/io/gcp/healthcare/dicomio_test.py +++ b/sdks/python/apache_beam/io/gcp/healthcare/dicomio_test.py @@ -211,7 +211,6 @@ def test_Qido_search_small_buffer_flush(self, MockClient): @patch("apache_beam.io.gcp.healthcare.dicomio.DicomApiHttpClient") def test_param_dict_passing(self, MockClient): - input_dict = {} input_dict = {} input_dict['project_id'] = "test_project" input_dict['region'] = "test_region" @@ -257,7 +256,25 @@ def test_wrong_input_type(self, MockClient): assert_that(results, equal_to([expected_invalid_dict])) @patch("apache_beam.io.gcp.healthcare.dicomio.DicomApiHttpClient") - def test_missing_parameters(self, MockClient): + def test_missing_project_id(self, MockClient): + input_dict = {} + input_dict['dataset_id'] = "test_dataset" + input_dict['region'] = "test_region" + + expected_invalid_dict = {} + expected_invalid_dict['result'] = [] + expected_invalid_dict['status'] = 'Must have project_id in the dict.' + expected_invalid_dict['input'] = input_dict + expected_invalid_dict['success'] = False + + mc = MockHttpClient() + MockClient.return_value = mc + with TestPipeline() as p: + results = (p | beam.Create([input_dict]) | DicomSearch()) + assert_that(results, equal_to([expected_invalid_dict])) + + @patch("apache_beam.io.gcp.healthcare.dicomio.DicomApiHttpClient") + def test_missing_dataset_id(self, MockClient): input_dict = {} input_dict['project_id'] = "test_project" input_dict['region'] = "test_region" @@ -274,6 +291,24 @@ def test_missing_parameters(self, MockClient): results = (p | beam.Create([input_dict]) | DicomSearch()) assert_that(results, equal_to([expected_invalid_dict])) + @patch("apache_beam.io.gcp.healthcare.dicomio.DicomApiHttpClient") + def test_missing_region(self, MockClient): + input_dict = {} + input_dict['project_id'] = "test_project" + input_dict['dataset_id'] = "test_dataset" + + expected_invalid_dict = {} + expected_invalid_dict['result'] = [] + expected_invalid_dict['status'] = 'Must have region in the dict.' + expected_invalid_dict['input'] = input_dict + expected_invalid_dict['success'] = False + + mc = MockHttpClient() + MockClient.return_value = mc + with TestPipeline() as p: + results = (p | beam.Create([input_dict]) | DicomSearch()) + assert_that(results, equal_to([expected_invalid_dict])) + @patch("apache_beam.io.gcp.healthcare.dicomio.DicomApiHttpClient") def test_client_search_notfound(self, MockClient): input_dict = {}