def test_get_job_trigger(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name_2, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.JobTrigger(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request name = client.project_job_trigger_path('[PROJECT]', '[JOB_TRIGGER]') response = client.get_job_trigger(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetJobTriggerRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_job_trigger(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.JobTrigger(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request parent = client.project_path('[PROJECT]') response = client.create_job_trigger(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.CreateJobTriggerRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_deidentify_template(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name_2, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.DeidentifyTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request name = client.organization_deidentify_template_path( '[ORGANIZATION]', '[DEIDENTIFY_TEMPLATE]') response = client.update_deidentify_template(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.UpdateDeidentifyTemplateRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_job_triggers(self): # Setup Expected Response next_page_token = '' job_triggers_element = {} job_triggers = [job_triggers_element] expected_response = { 'next_page_token': next_page_token, 'job_triggers': job_triggers } expected_response = dlp_pb2.ListJobTriggersResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request parent = client.project_path('[PROJECT]') paged_list_response = client.list_job_triggers(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.job_triggers[0] == resources[0] assert len(channel.requests) == 1 expected_request = dlp_pb2.ListJobTriggersRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_inspect_templates(self): # Setup Expected Response next_page_token = '' inspect_templates_element = {} inspect_templates = [inspect_templates_element] expected_response = { 'next_page_token': next_page_token, 'inspect_templates': inspect_templates } expected_response = dlp_pb2.ListInspectTemplatesResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request parent = client.organization_path('[ORGANIZATION]') paged_list_response = client.list_inspect_templates(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.inspect_templates[0] == resources[0] assert len(channel.requests) == 1 expected_request = dlp_pb2.ListInspectTemplatesRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_inspect_template_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = dlp_v2.DlpServiceClient(channel=channel) with pytest.raises(CustomException): client.get_inspect_template()
def test_create_inspect_template(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.InspectTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dlp_v2.DlpServiceClient(channel=channel) # Setup Request parent = client.organization_path('[ORGANIZATION]') response = client.create_inspect_template(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.CreateInspectTemplateRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_stored_info_type(self): # Setup Expected Response name_2 = "name2-1052831874" expected_response = {"name": name_2} expected_response = dlp_pb2.StoredInfoType(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.organization_stored_info_type_path( "[ORGANIZATION]", "[STORED_INFO_TYPE]" ) response = client.get_stored_info_type(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetStoredInfoTypeRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_job_trigger(self): client = dlp_v2.DlpServiceClient() name_inside = client.project_path(PROJECT_INSIDE) delayed_inside = lambda: client.create_job_trigger(name_inside) name_outside = client.project_path(PROJECT_OUTSIDE) delayed_outside = lambda: client.create_job_trigger(name_outside) TestSystemDlpService._do_test(delayed_inside, delayed_outside)
def test_update_job_trigger(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name_2, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.JobTrigger(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.project_job_trigger_path('[PROJECT]', '[JOB_TRIGGER]') response = client.update_job_trigger(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.UpdateJobTriggerRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_redact_image(self): client = dlp_v2.DlpServiceClient() name_inside = client.project_path(PROJECT_INSIDE) delayed_inside = lambda: client.redact_image(name_inside) name_outside = client.project_path(PROJECT_OUTSIDE) delayed_outside = lambda: client.redact_image(name_outside) TestSystemDlpService._do_test(delayed_inside, delayed_outside)
def test_list_info_types_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = dlp_v2.DlpServiceClient(channel=channel) with pytest.raises(CustomException): client.list_info_types()
def test_list_stored_info_types(self): client = dlp_v2.DlpServiceClient() name_inside = client.project_path(PROJECT_INSIDE) delayed_inside = lambda: client.list_stored_info_types(name_inside) name_outside = client.project_path(PROJECT_OUTSIDE) delayed_outside = lambda: client.list_stored_info_types(name_outside) TestSystemDlpService._do_test(delayed_inside, delayed_outside)
def test_get_job_trigger(self): # Setup Expected Response name_2 = "name2-1052831874" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "name": name_2, "display_name": display_name, "description": description, } expected_response = dlp_pb2.JobTrigger(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.project_job_trigger_path("[PROJECT]", "[JOB_TRIGGER]") response = client.get_job_trigger(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetJobTriggerRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_deidentify_template(self): # Setup Expected Response name_2 = "name2-1052831874" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "name": name_2, "display_name": display_name, "description": description, } expected_response = dlp_pb2.DeidentifyTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.organization_deidentify_template_path( "[ORGANIZATION]", "[DEIDENTIFY_TEMPLATE]" ) response = client.update_deidentify_template(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.UpdateDeidentifyTemplateRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_inspect_templates(self): # Setup Expected Response next_page_token = "" inspect_templates_element = {} inspect_templates = [inspect_templates_element] expected_response = { "next_page_token": next_page_token, "inspect_templates": inspect_templates, } expected_response = dlp_pb2.ListInspectTemplatesResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.organization_path("[ORGANIZATION]") paged_list_response = client.list_inspect_templates(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.inspect_templates[0] == resources[0] assert len(channel.requests) == 1 expected_request = dlp_pb2.ListInspectTemplatesRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_deidentify_content(self): client = dlp_v2.DlpServiceClient() name_inside = client.project_path(PROJECT_INSIDE) delayed_inside = lambda: client.deidentify_content(name_inside) name_outside = client.project_path(PROJECT_OUTSIDE) delayed_outside = lambda: client.deidentify_content(name_outside) TestSystemDlpService._do_test(delayed_inside, delayed_outside)
def test_redact_image(self): # Setup Expected Response redacted_image = b'28' extracted_text = 'extractedText998260012' expected_response = { 'redacted_image': redacted_image, 'extracted_text': extracted_text } expected_response = dlp_pb2.RedactImageResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.project_path('[PROJECT]') response = client.redact_image(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.RedactImageRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def setup(self): if self.client is None: self.client = dlp_v2.DlpServiceClient() self.params = { 'timeout': self.timeout, } self.parent = self.client.common_project_path(self.project)
def test_list_job_triggers(self): # Setup Expected Response next_page_token = '' job_triggers_element = {} job_triggers = [job_triggers_element] expected_response = { 'next_page_token': next_page_token, 'job_triggers': job_triggers } expected_response = dlp_pb2.ListJobTriggersResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.project_path('[PROJECT]') paged_list_response = client.list_job_triggers(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.job_triggers[0] == resources[0] assert len(channel.requests) == 1 expected_request = dlp_pb2.ListJobTriggersRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_dlp_job(self): # Setup Expected Response name = 'name3373707' job_trigger_name = 'jobTriggerName1819490804' expected_response = { 'name': name, 'job_trigger_name': job_trigger_name } expected_response = dlp_pb2.DlpJob(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.project_path('[PROJECT]') response = client.create_dlp_job(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.CreateDlpJobRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_dlp_job(self): # Setup Expected Response name_2 = 'name2-1052831874' job_trigger_name = 'jobTriggerName1819490804' expected_response = { 'name': name_2, 'job_trigger_name': job_trigger_name } expected_response = dlp_pb2.DlpJob(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.dlp_job_path('[PROJECT]', '[DLP_JOB]') response = client.get_dlp_job(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetDlpJobRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_deidentify_template(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name_2, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.DeidentifyTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request name = client.organization_deidentify_template_path( '[ORGANIZATION]', '[DEIDENTIFY_TEMPLATE]') response = client.get_deidentify_template(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetDeidentifyTemplateRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_deidentify_templates(self): # Setup Expected Response next_page_token = '' deidentify_templates_element = {} deidentify_templates = [deidentify_templates_element] expected_response = { 'next_page_token': next_page_token, 'deidentify_templates': deidentify_templates } expected_response = dlp_pb2.ListDeidentifyTemplatesResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.organization_path('[ORGANIZATION]') paged_list_response = client.list_deidentify_templates(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.deidentify_templates[0] == resources[0] assert len(channel.requests) == 1 expected_request = dlp_pb2.ListDeidentifyTemplatesRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_deidentify_template(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.DeidentifyTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.organization_path('[ORGANIZATION]') response = client.create_deidentify_template(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.CreateDeidentifyTemplateRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_inspect_template(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' description = 'description-1724546052' expected_response = { 'name': name, 'display_name': display_name, 'description': description } expected_response = dlp_pb2.InspectTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() response = client.get_inspect_template() assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.GetInspectTemplateRequest() actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_inspect_template(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" description = "description-1724546052" expected_response = { "name": name, "display_name": display_name, "description": description, } expected_response = dlp_pb2.InspectTemplate(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() # Setup Request parent = client.organization_path("[ORGANIZATION]") response = client.create_inspect_template(parent) assert expected_response == response assert len(channel.requests) == 1 expected_request = dlp_pb2.CreateInspectTemplateRequest(parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def setup(self): if self.client is None: self.client = dlp_v2.DlpServiceClient() self.params = { 'timeout': self.timeout, "parent": self.client.project_path(self.project) } self.params.update(self.config)
def test_list_info_types_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() with pytest.raises(CustomException): client.list_info_types()
def test_get_inspect_template_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = dlp_v2.DlpServiceClient() with pytest.raises(CustomException): client.get_inspect_template()