@@ -22,17 +22,18 @@ def _callFUT(self, *args, **kw):
22
22
return list_topics (* args , ** kw )
23
23
24
24
def test_w_explicit_connection_no_paging (self ):
25
+ from gcloud .pubsub .topic import Topic
25
26
TOPIC_NAME = 'topic_name'
26
27
PROJECT = 'PROJECT'
27
- TOKEN = 'TOKEN'
28
- returned = {'topics' : [{'name' : TOPIC_NAME }],
29
- 'nextPageToken' : TOKEN }
28
+ TOPIC_PATH = 'projects/%s/topics/%s' % (PROJECT , TOPIC_NAME )
29
+ returned = {'topics' : [{'name' : TOPIC_PATH }]}
30
30
conn = _Connection (returned )
31
- response = self ._callFUT (project = PROJECT , connection = conn )
32
- topics = response [ 'topics' ]
31
+ topics , next_page_token = self ._callFUT (project = PROJECT ,
32
+ connection = conn )
33
33
self .assertEqual (len (topics ), 1 )
34
- self .assertEqual (topics [0 ], {'name' : TOPIC_NAME })
35
- self .assertEqual (response ['nextPageToken' ], TOKEN )
34
+ self .assertTrue (isinstance (topics [0 ], Topic ))
35
+ self .assertEqual (topics [0 ].name , TOPIC_NAME )
36
+ self .assertEqual (next_page_token , None )
36
37
self .assertEqual (len (conn ._requested ), 1 )
37
38
req = conn ._requested [0 ]
38
39
self .assertEqual (req ['method' ], 'GET' )
@@ -42,39 +43,43 @@ def test_w_explicit_connection_no_paging(self):
42
43
def test_w_implicit_connection_and_project_wo_paging (self ):
43
44
from gcloud ._testing import _monkey_defaults as _monkey_base_defaults
44
45
from gcloud .pubsub ._testing import _monkey_defaults
46
+ from gcloud .pubsub .topic import Topic
45
47
TOPIC_NAME = 'topic_name'
46
48
PROJECT = 'PROJECT'
49
+ TOPIC_PATH = 'projects/%s/topics/%s' % (PROJECT , TOPIC_NAME )
47
50
TOKEN = 'TOKEN'
48
- returned = {'topics' : [{'name' : TOPIC_NAME }],
51
+ returned = {'topics' : [{'name' : TOPIC_PATH }],
49
52
'nextPageToken' : TOKEN }
50
53
conn = _Connection (returned )
51
54
with _monkey_base_defaults (project = PROJECT ):
52
55
with _monkey_defaults (connection = conn ):
53
- response = self ._callFUT ()
54
- topics = response ['topics' ]
56
+ topics , next_page_token = self ._callFUT ()
55
57
self .assertEqual (len (topics ), 1 )
56
- self .assertEqual (topics [0 ], {'name' : TOPIC_NAME })
57
- self .assertEqual (response ['nextPageToken' ], TOKEN )
58
+ self .assertTrue (isinstance (topics [0 ], Topic ))
59
+ self .assertEqual (topics [0 ].name , TOPIC_NAME )
60
+ self .assertEqual (next_page_token , TOKEN )
58
61
self .assertEqual (len (conn ._requested ), 1 )
59
62
req = conn ._requested [0 ]
60
63
self .assertEqual (req ['method' ], 'GET' )
61
64
self .assertEqual (req ['path' ], '/projects/%s/topics' % PROJECT )
62
65
self .assertEqual (req ['query_params' ], {})
63
66
64
67
def test_w_explicit_connection_and_project_w_paging (self ):
68
+ from gcloud .pubsub .topic import Topic
65
69
TOPIC_NAME = 'topic_name'
66
70
PROJECT = 'PROJECT'
71
+ TOPIC_PATH = 'projects/%s/topics/%s' % (PROJECT , TOPIC_NAME )
67
72
TOKEN1 = 'TOKEN1'
68
73
TOKEN2 = 'TOKEN2'
69
74
SIZE = 1
70
- returned = {'topics' : [{'name' : TOPIC_NAME }],
75
+ returned = {'topics' : [{'name' : TOPIC_PATH }],
71
76
'nextPageToken' : TOKEN2 }
72
77
conn = _Connection (returned )
73
- response = self ._callFUT (SIZE , TOKEN1 , PROJECT , conn )
74
- topics = response ['topics' ]
78
+ topics , next_page_token = self ._callFUT (SIZE , TOKEN1 , PROJECT , conn )
75
79
self .assertEqual (len (topics ), 1 )
76
- self .assertEqual (topics [0 ], {'name' : TOPIC_NAME })
77
- self .assertEqual (response ['nextPageToken' ], TOKEN2 )
80
+ self .assertTrue (isinstance (topics [0 ], Topic ))
81
+ self .assertEqual (topics [0 ].name , TOPIC_NAME )
82
+ self .assertEqual (next_page_token , TOKEN2 )
78
83
self .assertEqual (len (conn ._requested ), 1 )
79
84
req = conn ._requested [0 ]
80
85
self .assertEqual (req ['method' ], 'GET' )
0 commit comments