def test_delete_occurrence_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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup request name = client.occurrence_path("[PROJECT]", "[OCCURRENCE]") with pytest.raises(CustomException): client.delete_occurrence(name)
def test_list_occurrences_exception(self): channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup request parent = client.project_path("[PROJECT]") paged_list_response = client.list_occurrences(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_create_note(self): # Setup Expected Response name = "name3373707" short_description = "shortDescription-235369287" long_description = "longDescription-1747792199" expected_response = { "name": name, "short_description": short_description, "long_description": long_description, } expected_response = grafeas_pb2.Note(**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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup Request parent = client.project_path("[PROJECT]") note_id = "noteId2129224840" note = {} response = client.create_note(parent, note_id, note) assert expected_response == response assert len(channel.requests) == 1 expected_request = grafeas_pb2.CreateNoteRequest(parent=parent, note_id=note_id, note=note) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_occurrence(self): # Setup Expected Response name_2 = "name2-1052831874" resource_uri = "resourceUri-384040517" note_name = "noteName1780787896" remediation = "remediation779381797" expected_response = { "name": name_2, "resource_uri": resource_uri, "note_name": note_name, "remediation": remediation, } expected_response = grafeas_pb2.Occurrence(**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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup Request name = client.occurrence_path("[PROJECT]", "[OCCURRENCE]") occurrence = {} response = client.update_occurrence(name, occurrence) assert expected_response == response assert len(channel.requests) == 1 expected_request = grafeas_pb2.UpdateOccurrenceRequest( name=name, occurrence=occurrence) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_note_occurrences(self): # Setup Expected Response next_page_token = "" occurrences_element = {} occurrences = [occurrences_element] expected_response = { "next_page_token": next_page_token, "occurrences": occurrences, } expected_response = grafeas_pb2.ListNoteOccurrencesResponse( **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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup Request name = client.note_path("[PROJECT]", "[NOTE]") paged_list_response = client.list_note_occurrences(name) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.occurrences[0] == resources[0] assert len(channel.requests) == 1 expected_request = grafeas_pb2.ListNoteOccurrencesRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_note_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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup request parent = client.project_path("[PROJECT]") note_id = "noteId2129224840" note = {} with pytest.raises(CustomException): client.create_note(parent, note_id, note)
def test_delete_occurrence(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup Request name = client.occurrence_path("[PROJECT]", "[OCCURRENCE]") client.delete_occurrence(name) assert len(channel.requests) == 1 expected_request = grafeas_pb2.DeleteOccurrenceRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_note(self): # Setup Expected Response name_2 = "name2-1052831874" short_description = "shortDescription-235369287" long_description = "longDescription-1747792199" expected_response = { "name": name_2, "short_description": short_description, "long_description": long_description, } expected_response = grafeas_pb2.Note(**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 address = "[SERVICE_ADDRESS]" scopes = "SCOPE" transport = grafeas_grpc_transport.GrafeasGrpcTransport( address, scopes) client = grafeas_v1.GrafeasClient(transport) # Setup Request name = client.note_path("[PROJECT]", "[NOTE]") response = client.get_note(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = grafeas_pb2.GetNoteRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def get_grafeas_client(self) -> grafeas_v1.GrafeasClient: transport = type(self).get_transport_class("grpc_asyncio")() grafeas_transport = grafeas_v1.services.grafeas.transports.GrafeasGrpcTransport( host=transport._host, scopes=transport.AUTH_SCOPES) return grafeas_v1.GrafeasClient(transport=grafeas_transport)