def test_batch_create_notes(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = grafeas_pb2.BatchCreateNotesResponse(
            **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]")
        notes = {}

        response = client.batch_create_notes(parent, notes)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = grafeas_pb2.BatchCreateNotesRequest(parent=parent,
                                                               notes=notes)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def get_grafeas_client(self):
        """Returns an equivalent grafeas client.

        Returns:
            A :class:`~grafeas.grafeas_v1.GrafeasClient` instance.
        """
        grafeas_transport = grafeas_grpc_transport.GrafeasGrpcTransport(
            self.SERVICE_ADDRESS, self.transport._OAUTH_SCOPES)

        return grafeas_v1.GrafeasClient(grafeas_transport)
    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_note_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
        name = client.note_path("[PROJECT]", "[NOTE]")

        paged_list_response = client.list_note_occurrences(name)
        with pytest.raises(CustomException):
            list(paged_list_response)
    def test_batch_create_notes_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]")
        notes = {}

        with pytest.raises(CustomException):
            client.batch_create_notes(parent, notes)
    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_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