예제 #1
0
    def test_read(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**expected_response)

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

        # Setup Request
        session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]',
                                      '[SESSION]')
        table = 'table110115790'
        columns = []
        key_set = {}

        response = client.read(session, table, columns, key_set)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ReadRequest(session=session,
                                                   table=table,
                                                   columns=columns,
                                                   key_set=key_set)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
예제 #2
0
    def test_read(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = spanner_v1.SpannerClient()

        # Mock request
        session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]',
                                      '[SESSION]')
        table = 'table110115790'
        columns = []
        key_set = {}

        # Mock response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**expected_response)
        grpc_stub.Read.return_value = expected_response

        response = client.read(session, table, columns, key_set)
        self.assertEqual(expected_response, response)

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

        expected_request = spanner_pb2.ReadRequest(session=session,
                                                   table=table,
                                                   columns=columns,
                                                   key_set=key_set)
        self.assertEqual(expected_request, actual_request)
예제 #3
0
    def test_execute_sql(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = spanner_v1.SpannerClient()

        # Mock request
        session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]',
                                      '[SESSION]')
        sql = 'sql114126'

        # Mock response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**expected_response)
        grpc_stub.ExecuteSql.return_value = expected_response

        response = client.execute_sql(session, sql)
        self.assertEqual(expected_response, response)

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

        expected_request = spanner_pb2.ExecuteSqlRequest(session=session,
                                                         sql=sql)
        self.assertEqual(expected_request, actual_request)
예제 #4
0
    def test_read(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**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 = spanner_v1.SpannerClient()

        # Setup Request
        session = client.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]",
                                      "[SESSION]")
        table = "table110115790"
        columns = []
        key_set = {}

        response = client.read(session, table, columns, key_set)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ReadRequest(session=session,
                                                   table=table,
                                                   columns=columns,
                                                   key_set=key_set)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
예제 #5
0
    def test_execute_sql(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**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 = spanner_v1.SpannerClient()

        # Setup Request
        session = client.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]",
                                      "[SESSION]")
        sql = "sql114126"

        response = client.execute_sql(session, sql)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ExecuteSqlRequest(session=session,
                                                         sql=sql)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
예제 #6
0
    def test_execute_sql(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = result_set_pb2.ResultSet(**expected_response)

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

        # Setup Request
        session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]',
                                      '[SESSION]')
        sql = 'sql114126'

        response = client.execute_sql(session, sql)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ExecuteSqlRequest(session=session,
                                                         sql=sql)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request