12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import datetime
15
16
import unittest
16
17
17
18
import mock
@@ -365,7 +366,17 @@ def test_list_subscriptions_w_missing_key(self):
365
366
self .assertEqual (api ._listed_subscriptions ,
366
367
(self .PROJECT , None , None ))
367
368
368
- def test_topic (self ):
369
+ def test_list_snapshots (self ):
370
+ creds = _make_credentials ()
371
+ client = self ._make_one (project = self .PROJECT , credentials = creds )
372
+ client ._connection = object ()
373
+ api = _FauxSubscriberAPI ()
374
+ response = api ._list_snapshots_response = object ()
375
+ client ._subscriber_api = api
376
+ self .assertEqual (client .list_snapshots (), response )
377
+ self .assertEqual (api ._listed_snapshots , (self .PROJECT , None , None ))
378
+
379
+ def test_topic_factory (self ):
369
380
PROJECT = 'PROJECT'
370
381
TOPIC_NAME = 'TOPIC_NAME'
371
382
creds = _make_credentials ()
@@ -379,17 +390,33 @@ def test_topic(self):
379
390
'projects/%s/topics/%s' % (PROJECT , TOPIC_NAME ))
380
391
self .assertFalse (new_topic .timestamp_messages )
381
392
382
- def test_list_snapshots (self ):
393
+ def test_subscription_factory (self ):
394
+ project = 'PROJECT'
383
395
creds = _make_credentials ()
384
- client = self ._make_one (project = self .PROJECT , credentials = creds )
385
- client ._connection = object ()
386
- api = _FauxSubscriberAPI ()
387
- response = api ._list_snapshots_response = object ()
388
- client ._subscriber_api = api
389
- self .assertEqual (client .list_snapshots (), response )
390
- self .assertEqual (api ._listed_snapshots , (self .PROJECT , None , None ))
396
+ client_obj = self ._make_one (project = project , credentials = creds )
397
+
398
+ sub_name = 'hoot-n-holler'
399
+ ack_deadline = 60 ,
400
+ push_endpoint = 'https://api.example.com/push'
401
+ message_retention_duration = datetime .timedelta (3600 )
402
+ new_subscription = client_obj .subscription (
403
+ sub_name , ack_deadline = ack_deadline ,
404
+ push_endpoint = push_endpoint ,
405
+ retain_acked_messages = True ,
406
+ message_retention_duration = message_retention_duration )
407
+
408
+ self .assertEqual (new_subscription .name , sub_name )
409
+ self .assertIsNone (new_subscription .topic )
410
+ self .assertIs (new_subscription ._client , client_obj )
411
+ self .assertEqual (new_subscription ._project , project )
412
+ self .assertEqual (new_subscription .ack_deadline , ack_deadline )
413
+ self .assertEqual (new_subscription .push_endpoint , push_endpoint )
414
+ self .assertTrue (new_subscription .retain_acked_messages )
415
+ self .assertEqual (
416
+ new_subscription .message_retention_duration ,
417
+ message_retention_duration )
418
+
391
419
392
-
393
420
class _Iterator (object ):
394
421
395
422
def __init__ (self , items , token ):
@@ -419,7 +446,8 @@ def list_subscriptions(self, project, page_size, page_token):
419
446
420
447
def list_snapshots (self , project , page_size , page_token ):
421
448
self ._listed_snapshots = (project , page_size , page_token )
422
- return self ._list_snapshots_response
449
+ return self ._list_snapshots_response
450
+
423
451
424
452
class _Connection (object ):
425
453
0 commit comments