@@ -52,7 +52,9 @@ def test_ctor(self):
5252 self .assertTrue (api ._gax_api is gax_api )
5353
5454 def test_list_topics_no_paging (self ):
55- response = _ListTopicsResponsePB ([_TopicPB (self .TOPIC_PATH )])
55+ from google .gax import INITIAL_PAGE
56+ TOKEN = 'TOKEN'
57+ response = _ListTopicsResponsePB ([_TopicPB (self .TOPIC_PATH )], TOKEN )
5658 gax_api = _GAXPublisherAPI (_list_topics_response = response )
5759 api = self ._makeOne (gax_api )
5860
@@ -62,11 +64,31 @@ def test_list_topics_no_paging(self):
6264 topic = topics [0 ]
6365 self .assertIsInstance (topic , dict )
6466 self .assertEqual (topic ['name' ], self .TOPIC_PATH )
65- self .assertEqual (next_token , None )
67+ self .assertEqual (next_token , TOKEN )
6668
6769 name , options = gax_api ._list_topics_called_with
6870 self .assertEqual (name , self .PROJECT_PATH )
69- self .assertFalse (options .is_page_streaming )
71+ self .assertTrue (options .page_token is INITIAL_PAGE )
72+
73+ def test_list_topics_with_paging (self ):
74+ TOKEN = 'TOKEN'
75+ NEW_TOKEN = 'NEW_TOKEN'
76+ response = _ListTopicsResponsePB (
77+ [_TopicPB (self .TOPIC_PATH )], NEW_TOKEN )
78+ gax_api = _GAXPublisherAPI (_list_topics_response = response )
79+ api = self ._makeOne (gax_api )
80+
81+ topics , next_token = api .list_topics (self .PROJECT , page_token = TOKEN )
82+
83+ self .assertEqual (len (topics ), 1 )
84+ topic = topics [0 ]
85+ self .assertIsInstance (topic , dict )
86+ self .assertEqual (topic ['name' ], self .TOPIC_PATH )
87+ self .assertEqual (next_token , NEW_TOKEN )
88+
89+ name , options = gax_api ._list_topics_called_with
90+ self .assertEqual (name , self .PROJECT_PATH )
91+ self .assertEqual (options .page_token , TOKEN )
7092
7193 def test_topic_create (self ):
7294 topic_pb = _TopicPB (self .TOPIC_PATH )
@@ -233,6 +255,7 @@ def test_topic_publish_error(self):
233255 self .assertEqual (options , None )
234256
235257 def test_topic_list_subscriptions_no_paging (self ):
258+ from google .gax import INITIAL_PAGE
236259 response = _ListTopicSubscriptionsResponsePB ([self .SUB_PATH ])
237260 gax_api = _GAXPublisherAPI (_list_topic_subscriptions_response = response )
238261 api = self ._makeOne (gax_api )
@@ -249,9 +272,32 @@ def test_topic_list_subscriptions_no_paging(self):
249272
250273 topic_path , options = gax_api ._list_topic_subscriptions_called_with
251274 self .assertEqual (topic_path , self .TOPIC_PATH )
252- self .assertFalse (options .is_page_streaming )
275+ self .assertTrue (options .page_token is INITIAL_PAGE )
276+
277+ def test_topic_list_subscriptions_with_paging (self ):
278+ TOKEN = 'TOKEN'
279+ NEW_TOKEN = 'NEW_TOKEN'
280+ response = _ListTopicSubscriptionsResponsePB (
281+ [self .SUB_PATH ], NEW_TOKEN )
282+ gax_api = _GAXPublisherAPI (_list_topic_subscriptions_response = response )
283+ api = self ._makeOne (gax_api )
284+
285+ subscriptions , next_token = api .topic_list_subscriptions (
286+ self .TOPIC_PATH , page_token = TOKEN )
287+
288+ self .assertEqual (len (subscriptions ), 1 )
289+ subscription = subscriptions [0 ]
290+ self .assertIsInstance (subscription , dict )
291+ self .assertEqual (subscription ['name' ], self .SUB_PATH )
292+ self .assertEqual (subscription ['topic' ], self .TOPIC_PATH )
293+ self .assertEqual (next_token , NEW_TOKEN )
294+
295+ name , options = gax_api ._list_topic_subscriptions_called_with
296+ self .assertEqual (name , self .TOPIC_PATH )
297+ self .assertEqual (options .page_token , TOKEN )
253298
254299 def test_topic_list_subscriptions_miss (self ):
300+ from google .gax import INITIAL_PAGE
255301 from gcloud .exceptions import NotFound
256302 gax_api = _GAXPublisherAPI ()
257303 api = self ._makeOne (gax_api )
@@ -261,9 +307,10 @@ def test_topic_list_subscriptions_miss(self):
261307
262308 topic_path , options = gax_api ._list_topic_subscriptions_called_with
263309 self .assertEqual (topic_path , self .TOPIC_PATH )
264- self .assertFalse (options .is_page_streaming )
310+ self .assertTrue (options .page_token is INITIAL_PAGE )
265311
266312 def test_topic_list_subscriptions_error (self ):
313+ from google .gax import INITIAL_PAGE
267314 from google .gax .errors import GaxError
268315 gax_api = _GAXPublisherAPI (_random_gax_error = True )
269316 api = self ._makeOne (gax_api )
@@ -273,7 +320,7 @@ def test_topic_list_subscriptions_error(self):
273320
274321 topic_path , options = gax_api ._list_topic_subscriptions_called_with
275322 self .assertEqual (topic_path , self .TOPIC_PATH )
276- self .assertFalse (options .is_page_streaming )
323+ self .assertTrue (options .page_token is INITIAL_PAGE )
277324
278325
279326@unittest2 .skipUnless (_HAVE_GAX , 'No gax-python' )
@@ -291,6 +338,7 @@ def test_ctor(self):
291338 self .assertTrue (api ._gax_api is gax_api )
292339
293340 def test_list_subscriptions_no_paging (self ):
341+ from google .gax import INITIAL_PAGE
294342 response = _ListSubscriptionsResponsePB ([_SubscriptionPB (
295343 self .SUB_PATH , self .TOPIC_PATH , self .PUSH_ENDPOINT , 0 )])
296344 gax_api = _GAXSubscriberAPI (_list_subscriptions_response = response )
@@ -310,7 +358,32 @@ def test_list_subscriptions_no_paging(self):
310358
311359 name , options = gax_api ._list_subscriptions_called_with
312360 self .assertEqual (name , self .PROJECT_PATH )
313- self .assertFalse (options .is_page_streaming )
361+ self .assertTrue (options .page_token is INITIAL_PAGE )
362+
363+ def test_list_subscriptions_with_paging (self ):
364+ TOKEN = 'TOKEN'
365+ NEW_TOKEN = 'NEW_TOKEN'
366+ response = _ListSubscriptionsResponsePB ([_SubscriptionPB (
367+ self .SUB_PATH , self .TOPIC_PATH , self .PUSH_ENDPOINT , 0 )], NEW_TOKEN )
368+ gax_api = _GAXSubscriberAPI (_list_subscriptions_response = response )
369+ api = self ._makeOne (gax_api )
370+
371+ subscriptions , next_token = api .list_subscriptions (
372+ self .PROJECT , page_token = TOKEN )
373+
374+ self .assertEqual (len (subscriptions ), 1 )
375+ subscription = subscriptions [0 ]
376+ self .assertIsInstance (subscription , dict )
377+ self .assertEqual (subscription ['name' ], self .SUB_PATH )
378+ self .assertEqual (subscription ['topic' ], self .TOPIC_PATH )
379+ self .assertEqual (subscription ['pushConfig' ],
380+ {'pushEndpoint' : self .PUSH_ENDPOINT })
381+ self .assertEqual (subscription ['ackDeadlineSeconds' ], 0 )
382+ self .assertEqual (next_token , NEW_TOKEN )
383+
384+ name , options = gax_api ._list_subscriptions_called_with
385+ self .assertEqual (name , self .PROJECT_PATH )
386+ self .assertEqual (options .page_token , TOKEN )
314387
315388 def test_subscription_create (self ):
316389 sub_pb = _SubscriptionPB (self .SUB_PATH , self .TOPIC_PATH , '' , 0 )
0 commit comments