示例#1
0
async def test_predict_flattened_async():
    client = PredictionServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.predict),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = prediction_service.PredictResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            prediction_service.PredictResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.predict(
            name="name_value",
            payload=data_items.ExamplePayload(image=data_items.Image(
                image_bytes=b"image_bytes_blob")),
            params={"key_value": "value_value"},
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].name == "name_value"

        assert args[0].payload == data_items.ExamplePayload(
            image=data_items.Image(image_bytes=b"image_bytes_blob"))

        assert args[0].params == {"key_value": "value_value"}
async def test_create_client_event_async(
        transport: str = "grpc_asyncio",
        request_type=event_service.CreateClientEventRequest):
    client = EventServiceAsyncClient(
        credentials=ga_credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.create_client_event),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            event.ClientEvent(
                request_id="request_id_value",
                event_id="event_id_value",
                event_notes="event_notes_value",
            ))
        response = await client.create_client_event(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == event_service.CreateClientEventRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, event.ClientEvent)
    assert response.request_id == "request_id_value"
    assert response.event_id == "event_id_value"
    assert response.event_notes == "event_notes_value"
async def test_create_client_event_flattened_async():
    client = EventServiceAsyncClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.create_client_event),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = event.ClientEvent()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            event.ClientEvent())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.create_client_event(
            parent="parent_value",
            client_event=event.ClientEvent(request_id="request_id_value"),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0].parent == "parent_value"
        assert args[0].client_event == event.ClientEvent(
            request_id="request_id_value")
示例#4
0
async def test_list_authorized_domains_async(
        transport: str = "grpc_asyncio",
        request_type=appengine.ListAuthorizedDomainsRequest):
    client = AuthorizedDomainsAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.list_authorized_domains),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            appengine.ListAuthorizedDomainsResponse(
                next_page_token="next_page_token_value", ))

        response = await client.list_authorized_domains(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == appengine.ListAuthorizedDomainsRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, pagers.ListAuthorizedDomainsAsyncPager)

    assert response.next_page_token == "next_page_token_value"
async def test_annotate_video_async(
    transport: str = "grpc_asyncio",
    request_type=video_intelligence.AnnotateVideoRequest,
):
    client = VideoIntelligenceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.annotate_video), "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/spam")
        )

        response = await client.annotate_video(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == video_intelligence.AnnotateVideoRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, future.Future)
async def test_compute_threat_list_diff_flattened_async():
    client = WebRiskServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._client._transport.compute_threat_list_diff),
            "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = webrisk.ComputeThreatListDiffResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            webrisk.ComputeThreatListDiffResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.compute_threat_list_diff(
            threat_type=webrisk.ThreatType.MALWARE,
            version_token=b"version_token_blob",
            constraints=webrisk.ComputeThreatListDiffRequest.Constraints(
                max_diff_entries=1687),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0].threat_type == webrisk.ThreatType.MALWARE
        assert args[0].version_token == b"version_token_blob"
        assert args[
            0].constraints == webrisk.ComputeThreatListDiffRequest.Constraints(
                max_diff_entries=1687)
示例#7
0
async def test_complete_query_async(transport: str = "grpc_asyncio"):
    client = CompletionAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = completion_service.CompleteQueryRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.complete_query),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            completion_service.CompleteQueryResponse())

        response = await client.complete_query(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, completion_service.CompleteQueryResponse)
async def test_report_error_event_flattened_async():
    client = ReportErrorsServiceAsyncClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.report_error_event),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = report_errors_service.ReportErrorEventResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            report_errors_service.ReportErrorEventResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.report_error_event(
            project_name="project_name_value",
            event=report_errors_service.ReportedErrorEvent(
                event_time=timestamp_pb2.Timestamp(seconds=751)),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0].project_name == "project_name_value"
        assert args[0].event == report_errors_service.ReportedErrorEvent(
            event_time=timestamp_pb2.Timestamp(seconds=751))
示例#9
0
async def test_compute_head_cursor_field_headers_async():
    client = TopicStatsServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = topic_stats.ComputeHeadCursorRequest()
    request.topic = "topic/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.compute_head_cursor),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            topic_stats.ComputeHeadCursorResponse())

        await client.compute_head_cursor(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "topic=topic/value",
    ) in kw["metadata"]
示例#10
0
async def test_export_taxonomies_async(
    transport: str = "grpc_asyncio",
    request_type=policytagmanagerserialization.ExportTaxonomiesRequest,
):
    client = PolicyTagManagerSerializationAsyncClient(
        credentials=credentials.AnonymousCredentials(), transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
        type(client.transport.export_taxonomies), "__call__"
    ) as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            policytagmanagerserialization.ExportTaxonomiesResponse()
        )

        response = await client.export_taxonomies(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == policytagmanagerserialization.ExportTaxonomiesRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, policytagmanagerserialization.ExportTaxonomiesResponse)
示例#11
0
async def test_export_taxonomies_field_headers_async():
    client = PolicyTagManagerSerializationAsyncClient(
        credentials=credentials.AnonymousCredentials(),
    )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = policytagmanagerserialization.ExportTaxonomiesRequest()
    request.parent = "parent/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
        type(client.transport.export_taxonomies), "__call__"
    ) as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            policytagmanagerserialization.ExportTaxonomiesResponse()
        )

        await client.export_taxonomies(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
async def test_batch_annotate_images_flattened_async():
    client = ImageAnnotatorAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.batch_annotate_images),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = image_annotator.BatchAnnotateImagesResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            image_annotator.BatchAnnotateImagesResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.batch_annotate_images(requests=[
            image_annotator.AnnotateImageRequest(image=image_annotator.Image(
                content=b"content_blob"))
        ], )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].requests == [
            image_annotator.AnnotateImageRequest(image=image_annotator.Image(
                content=b"content_blob"))
        ]
示例#13
0
async def test_async_batch_annotate_files_flattened_async():
    client = ImageAnnotatorAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._client._transport.async_batch_annotate_files),
            "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = operations_pb2.Operation(name="operations/op")

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/spam"))
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.async_batch_annotate_files(requests=[
            image_annotator.AsyncAnnotateFileRequest(
                input_config=image_annotator.InputConfig(
                    gcs_source=image_annotator.GcsSource(uri="uri_value")))
        ], )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].requests == [
            image_annotator.AsyncAnnotateFileRequest(
                input_config=image_annotator.InputConfig(
                    gcs_source=image_annotator.GcsSource(uri="uri_value")))
        ]
示例#14
0
async def test_batch_predict_field_headers_async():
    client = PredictionServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = prediction_service.BatchPredictRequest()
    request.name = "name/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.batch_predict),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/op"))

        await client.batch_predict(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "name=name/value",
    ) in kw["metadata"]
async def test_synthesize_speech_async(
        transport: str = "grpc_asyncio",
        request_type=cloud_tts.SynthesizeSpeechRequest):
    client = TextToSpeechAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.synthesize_speech),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            cloud_tts.SynthesizeSpeechResponse(
                audio_content=b"audio_content_blob", ))

        response = await client.synthesize_speech(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == cloud_tts.SynthesizeSpeechRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, cloud_tts.SynthesizeSpeechResponse)

    assert response.audio_content == b"audio_content_blob"
async def test_allocate_quota_async(
    transport: str = "grpc_asyncio", request_type=quota_controller.AllocateQuotaRequest
):
    client = QuotaControllerAsyncClient(
        credentials=credentials.AnonymousCredentials(), transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.allocate_quota), "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            quota_controller.AllocateQuotaResponse(
                operation_id="operation_id_value",
                service_config_id="service_config_id_value",
            )
        )

        response = await client.allocate_quota(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == quota_controller.AllocateQuotaRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, quota_controller.AllocateQuotaResponse)

    assert response.operation_id == "operation_id_value"

    assert response.service_config_id == "service_config_id_value"
async def test_synthesize_speech_flattened_async():
    client = TextToSpeechAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.synthesize_speech),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = cloud_tts.SynthesizeSpeechResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            cloud_tts.SynthesizeSpeechResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.synthesize_speech(
            input=cloud_tts.SynthesisInput(text="text_value"),
            voice=cloud_tts.VoiceSelectionParams(
                language_code="language_code_value"),
            audio_config=cloud_tts.AudioConfig(
                audio_encoding=cloud_tts.AudioEncoding.LINEAR16),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].input == cloud_tts.SynthesisInput(text="text_value")

        assert args[0].voice == cloud_tts.VoiceSelectionParams(
            language_code="language_code_value")

        assert args[0].audio_config == cloud_tts.AudioConfig(
            audio_encoding=cloud_tts.AudioEncoding.LINEAR16)
示例#18
0
async def test_detect_intent_field_headers_async():
    client = SessionsAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = gcd_session.DetectIntentRequest()
    request.session = "session/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.detect_intent),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            gcd_session.DetectIntentResponse())

        await client.detect_intent(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "session=session/value",
    ) in kw["metadata"]
async def test_search_hashes_flattened_async():
    client = WebRiskServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.search_hashes),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = webrisk.SearchHashesResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            webrisk.SearchHashesResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.search_hashes(
            hash_prefix=b"hash_prefix_blob",
            threat_types=[webrisk.ThreatType.MALWARE],
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0].hash_prefix == b"hash_prefix_blob"
        assert args[0].threat_types == [webrisk.ThreatType.MALWARE]
示例#20
0
async def test_detect_intent_flattened_async():
    client = SessionsAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.detect_intent),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = gcd_session.DetectIntentResponse()

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            gcd_session.DetectIntentResponse())
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.detect_intent(
            session="session_value",
            query_input=gcd_session.QueryInput(
                audio_config=audio_config.InputAudioConfig(
                    audio_encoding=audio_config.AudioEncoding.
                    AUDIO_ENCODING_LINEAR_16)),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].session == "session_value"

        assert args[0].query_input == gcd_session.QueryInput(
            audio_config=audio_config.InputAudioConfig(
                audio_encoding=audio_config.AudioEncoding.
                AUDIO_ENCODING_LINEAR_16))
async def test_wrap_method_with_overriding_retry_deadline(
        utcnow, unused_sleep):
    fake_call = grpc_helpers_async.FakeUnaryUnaryCall(42)
    method = mock.Mock(
        spec=aio.UnaryUnaryMultiCallable,
        side_effect=([exceptions.InternalServerError(None)] * 4) + [fake_call],
    )

    default_retry = retry_async.AsyncRetry()
    default_timeout = timeout.ExponentialTimeout(deadline=60)
    wrapped_method = gapic_v1.method_async.wrap_method(method, default_retry,
                                                       default_timeout)

    # Overriding only the retry's deadline should also override the timeout's
    # deadline.
    result = await wrapped_method(retry=default_retry.with_deadline(30))

    assert result == 42
    timeout_args = [call[1]["timeout"] for call in method.call_args_list]
    assert timeout_args == [5.0, 10.0, 20.0, 26.0, 25.0]
    assert utcnow.call_count == (
        1 + 1  # Compute wait_for timeout in retry_async
        + 5  # First to set the deadline.
        + 5  # One for each min(timeout, maximum, (DEADLINE - NOW).seconds)
    )
示例#22
0
async def test_analyze_iam_policy_async(
        transport: str = "grpc_asyncio",
        request_type=asset_service.AnalyzeIamPolicyRequest):
    client = AssetServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.analyze_iam_policy),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            asset_service.AnalyzeIamPolicyResponse(fully_explored=True, ))

        response = await client.analyze_iam_policy(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == asset_service.AnalyzeIamPolicyRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, asset_service.AnalyzeIamPolicyResponse)

    assert response.fully_explored is True
示例#23
0
async def test_list_authorized_domains_field_headers_async():
    client = AuthorizedDomainsAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = appengine.ListAuthorizedDomainsRequest()
    request.parent = "parent/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.list_authorized_domains),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            appengine.ListAuthorizedDomainsResponse())

        await client.list_authorized_domains(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "parent=parent/value",
    ) in kw["metadata"]
示例#24
0
async def test_export_iam_policy_analysis_field_headers_async():
    client = AssetServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = asset_service.ExportIamPolicyAnalysisRequest()
    request.analysis_query.parent = "analysis_query.parent/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.export_iam_policy_analysis),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/op"))

        await client.export_iam_policy_analysis(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "analysis_query.parent=analysis_query.parent/value",
    ) in kw["metadata"]
async def test_annotate_video_flattened_async():
    client = VideoIntelligenceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(),
    )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.annotate_video), "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = operations_pb2.Operation(name="operations/op")

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/spam")
        )
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.annotate_video(
            input_uri="input_uri_value",
            features=[video_intelligence.Feature.LABEL_DETECTION],
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].input_uri == "input_uri_value"

        assert args[0].features == [video_intelligence.Feature.LABEL_DETECTION]
示例#26
0
async def test_long_running_recognize_async(transport: str = "grpc_asyncio"):
    client = SpeechAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = cloud_speech.LongRunningRecognizeRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._client._transport.long_running_recognize),
            "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/spam"))

        response = await client.long_running_recognize(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, future.Future)
async def test_create_client_event_field_headers_async():
    client = EventServiceAsyncClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = event_service.CreateClientEventRequest()

    request.parent = "parent/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.create_client_event),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            event.ClientEvent())
        await client.create_client_event(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == request

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "parent=parent/value",
    ) in kw["metadata"]
示例#28
0
async def test_long_running_recognize_flattened_async():
    client = SpeechAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
            type(client._client._transport.long_running_recognize),
            "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = operations_pb2.Operation(name="operations/op")

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            operations_pb2.Operation(name="operations/spam"))
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.long_running_recognize(
            config=cloud_speech.RecognitionConfig(
                encoding=cloud_speech.RecognitionConfig.AudioEncoding.LINEAR16
            ),
            audio=cloud_speech.RecognitionAudio(content=b"content_blob"),
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].config == cloud_speech.RecognitionConfig(
            encoding=cloud_speech.RecognitionConfig.AudioEncoding.LINEAR16)

        assert args[0].audio == cloud_speech.RecognitionAudio(
            content=b"content_blob")
def _mock_grpc_objects(response):
    fake_call = grpc_helpers_async.FakeUnaryUnaryCall(response)
    method = mock.Mock(spec=aio.UnaryUnaryMultiCallable,
                       return_value=fake_call)
    mocked_channel = mock.Mock()
    mocked_channel.unary_unary = mock.Mock(return_value=method)
    return mocked_channel, method, fake_call
示例#30
0
async def test_batch_write_spans_flattened_async():
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.batch_write_spans),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = None

        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        response = await client.batch_write_spans(
            name="name_value",
            spans=[trace.Span(name="name_value")],
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0].name == "name_value"

        assert args[0].spans == [trace.Span(name="name_value")]