Example #1
0
    def test_analyze_syntax(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = language_v1.LanguageServiceClient()

        # Mock request
        document = {}

        # Mock response
        language = 'language-1613589672'
        expected_response = {'language': language}
        expected_response = language_service_pb2.AnalyzeSyntaxResponse(
            **expected_response)
        grpc_stub.AnalyzeSyntax.return_value = expected_response

        response = client.analyze_syntax(document)
        self.assertEqual(expected_response, response)

        grpc_stub.AnalyzeSyntax.assert_called_once()
        args, kwargs = grpc_stub.AnalyzeSyntax.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = language_service_pb2.AnalyzeSyntaxRequest(
            document=document)
        self.assertEqual(expected_request, actual_request)
    def test_analyze_syntax(self):
        # Setup Expected Response
        language = "language-1613589672"
        expected_response = {"language": language}
        expected_response = language_service_pb2.AnalyzeSyntaxResponse(
            **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 = language_v1.LanguageServiceClient()

        # Setup Request
        document = {}

        response = client.analyze_syntax(document)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = language_service_pb2.AnalyzeSyntaxRequest(
            document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_analyze_syntax(self):
        # Setup Expected Response
        language = 'language-1613589672'
        expected_response = {'language': language}
        expected_response = language_service_pb2.AnalyzeSyntaxResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = language_v1.LanguageServiceClient(channel=channel)

        # Setup Request
        document = {}

        response = client.analyze_syntax(document)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = language_service_pb2.AnalyzeSyntaxRequest(
            document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request