Example #1
0
    def test_list_sessions(self):
        # Setup Expected Response
        next_page_token = ''
        sessions_element = {}
        sessions = [sessions_element]
        expected_response = {
            'next_page_token': next_page_token,
            'sessions': sessions
        }
        expected_response = spanner_pb2.ListSessionsResponse(
            **expected_response)

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

        # Setup Request
        database = client.database_path('[PROJECT]', '[INSTANCE]',
                                        '[DATABASE]')

        paged_list_response = client.list_sessions(database)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.sessions[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ListSessionsRequest(database=database)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #2
0
    def test_list_sessions(self):
        # Setup Expected Response
        next_page_token = ""
        sessions_element = {}
        sessions = [sessions_element]
        expected_response = {
            "next_page_token": next_page_token,
            "sessions": sessions
        }
        expected_response = spanner_pb2.ListSessionsResponse(
            **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
        database = client.database_path("[PROJECT]", "[INSTANCE]",
                                        "[DATABASE]")

        paged_list_response = client.list_sessions(database)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.sessions[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.ListSessionsRequest(database=database)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request