@@ -94,22 +94,19 @@ def test_list_entries_defaults(self):
9494 IID = 'IID'
9595 TEXT = 'TEXT'
9696 TOKEN = 'TOKEN'
97- RETURNED = {
98- 'entries' : [{
99- 'textPayload' : TEXT ,
100- 'insertId' : IID ,
101- 'resource' : {
102- 'type' : 'global' ,
103- },
104- 'logName' : 'projects/%s/logs/%s' % (
105- self .PROJECT , self .LOGGER_NAME ),
106- }],
107- 'nextPageToken' : TOKEN ,
108- }
97+ ENTRIES = [{
98+ 'textPayload' : TEXT ,
99+ 'insertId' : IID ,
100+ 'resource' : {
101+ 'type' : 'global' ,
102+ },
103+ 'logName' : 'projects/%s/logs/%s' % (
104+ self .PROJECT , self .LOGGER_NAME ),
105+ }]
109106 creds = _Credentials ()
110107 client = self ._makeOne (project = self .PROJECT , credentials = creds )
111108 api = client ._logging_api = _DummyLoggingAPI ()
112- api ._list_entries_response = RETURNED
109+ api ._list_entries_response = ENTRIES , TOKEN
113110
114111 entries , token = client .list_entries ()
115112
@@ -143,28 +140,26 @@ def test_list_entries_explicit(self):
143140 PROTO_PAYLOAD ['@type' ] = 'type.googleapis.com/testing.example'
144141 TOKEN = 'TOKEN'
145142 PAGE_SIZE = 42
146- RETURNED = {
147- 'entries' : [{
148- 'jsonPayload' : PAYLOAD ,
149- 'insertId' : IID1 ,
150- 'resource' : {
151- 'type' : 'global' ,
152- },
153- 'logName' : 'projects/%s/logs/%s' % (
154- self .PROJECT , self .LOGGER_NAME ),
155- }, {
156- 'protoPayload' : PROTO_PAYLOAD ,
157- 'insertId' : IID2 ,
158- 'resource' : {
159- 'type' : 'global' ,
160- },
161- 'logName' : 'projects/%s/logs/%s' % (
162- self .PROJECT , self .LOGGER_NAME ),
163- }],
164- }
143+ ENTRIES = [{
144+ 'jsonPayload' : PAYLOAD ,
145+ 'insertId' : IID1 ,
146+ 'resource' : {
147+ 'type' : 'global' ,
148+ },
149+ 'logName' : 'projects/%s/logs/%s' % (
150+ self .PROJECT , self .LOGGER_NAME ),
151+ }, {
152+ 'protoPayload' : PROTO_PAYLOAD ,
153+ 'insertId' : IID2 ,
154+ 'resource' : {
155+ 'type' : 'global' ,
156+ },
157+ 'logName' : 'projects/%s/logs/%s' % (
158+ self .PROJECT , self .LOGGER_NAME ),
159+ }]
165160 client = self ._makeOne (self .PROJECT , credentials = _Credentials ())
166161 api = client ._logging_api = _DummyLoggingAPI ()
167- api ._list_entries_response = RETURNED
162+ api ._list_entries_response = ENTRIES , None
168163
169164 entries , token = client .list_entries (
170165 projects = [PROJECT1 , PROJECT2 ], filter_ = FILTER , order_by = DESCENDING ,
@@ -216,17 +211,14 @@ def test_list_sinks_no_paging(self):
216211 SINK_NAME = 'sink_name'
217212 FILTER = 'logName:syslog AND severity>=ERROR'
218213 SINK_PATH = 'projects/%s/sinks/%s' % (PROJECT , SINK_NAME )
219- RETURNED = {
220- 'sinks' : [{
221- 'name' : SINK_PATH ,
222- 'filter' : FILTER ,
223- 'destination' : self .DESTINATION_URI ,
224- }],
225- 'nextPageToken' : TOKEN ,
226- }
214+ SINKS = [{
215+ 'name' : SINK_PATH ,
216+ 'filter' : FILTER ,
217+ 'destination' : self .DESTINATION_URI ,
218+ }]
227219 client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
228220 api = client ._sinks_api = _DummySinksAPI ()
229- api ._list_sinks_response = RETURNED
221+ api ._list_sinks_response = SINKS , TOKEN
230222
231223 sinks , token = client .list_sinks ()
232224
@@ -249,16 +241,14 @@ def test_list_sinks_with_paging(self):
249241 SINK_PATH = 'projects/%s/sinks/%s' % (PROJECT , SINK_NAME )
250242 TOKEN = 'TOKEN'
251243 PAGE_SIZE = 42
252- RETURNED = {
253- 'sinks' : [{
254- 'name' : SINK_PATH ,
255- 'filter' : FILTER ,
256- 'destination' : self .DESTINATION_URI ,
257- }],
258- }
244+ SINKS = [{
245+ 'name' : SINK_PATH ,
246+ 'filter' : FILTER ,
247+ 'destination' : self .DESTINATION_URI ,
248+ }]
259249 client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
260250 api = client ._sinks_api = _DummySinksAPI ()
261- api ._list_sinks_response = RETURNED
251+ api ._list_sinks_response = SINKS , None
262252
263253 sinks , token = client .list_sinks (PAGE_SIZE , TOKEN )
264254
@@ -272,19 +262,6 @@ def test_list_sinks_with_paging(self):
272262 self .assertEqual (api ._list_sinks_called_with ,
273263 (PROJECT , PAGE_SIZE , TOKEN ))
274264
275- def test_list_sinks_missing_key (self ):
276- PROJECT = 'PROJECT'
277- client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
278- api = client ._sinks_api = _DummySinksAPI ()
279- api ._list_sinks_response = {}
280-
281- sinks , token = client .list_sinks ()
282-
283- self .assertEqual (len (sinks ), 0 )
284- self .assertEqual (token , None )
285- self .assertEqual (api ._list_sinks_called_with ,
286- (PROJECT , None , None ))
287-
288265 def test_metric (self ):
289266 from gcloud .logging .metric import Metric
290267 creds = _Credentials ()
@@ -303,17 +280,14 @@ def test_list_metrics_no_paging(self):
303280 from gcloud .logging .metric import Metric
304281 PROJECT = 'PROJECT'
305282 TOKEN = 'TOKEN'
306- RETURNED = {
307- 'metrics' : [{
308- 'name' : self .METRIC_NAME ,
309- 'filter' : self .FILTER ,
310- 'description' : self .DESCRIPTION ,
311- }],
312- 'nextPageToken' : TOKEN ,
313- }
283+ METRICS = [{
284+ 'name' : self .METRIC_NAME ,
285+ 'filter' : self .FILTER ,
286+ 'description' : self .DESCRIPTION ,
287+ }]
314288 client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
315289 api = client ._metrics_api = _DummyMetricsAPI ()
316- api ._list_metrics_response = RETURNED
290+ api ._list_metrics_response = METRICS , TOKEN
317291
318292 metrics , token = client .list_metrics ()
319293
@@ -332,16 +306,14 @@ def test_list_metrics_with_paging(self):
332306 PROJECT = 'PROJECT'
333307 TOKEN = 'TOKEN'
334308 PAGE_SIZE = 42
335- RETURNED = {
336- 'metrics' : [{
337- 'name' : self .METRIC_NAME ,
338- 'filter' : self .FILTER ,
339- 'description' : self .DESCRIPTION ,
340- }],
341- }
309+ METRICS = [{
310+ 'name' : self .METRIC_NAME ,
311+ 'filter' : self .FILTER ,
312+ 'description' : self .DESCRIPTION ,
313+ }]
342314 client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
343315 api = client ._metrics_api = _DummyMetricsAPI ()
344- api ._list_metrics_response = RETURNED
316+ api ._list_metrics_response = METRICS , None
345317
346318 # Execute request.
347319 metrics , token = client .list_metrics (PAGE_SIZE , TOKEN )
@@ -356,19 +328,6 @@ def test_list_metrics_with_paging(self):
356328 self .assertEqual (api ._list_metrics_called_with ,
357329 (PROJECT , PAGE_SIZE , TOKEN ))
358330
359- def test_list_metrics_missing_key (self ):
360- PROJECT = 'PROJECT'
361- client = self ._makeOne (project = PROJECT , credentials = _Credentials ())
362- api = client ._metrics_api = _DummyMetricsAPI ()
363- api ._list_metrics_response = {}
364-
365- metrics , token = client .list_metrics ()
366-
367- self .assertEqual (len (metrics ), 0 )
368- self .assertEqual (token , None )
369- self .assertEqual (api ._list_metrics_called_with ,
370- (PROJECT , None , None ))
371-
372331
373332class _Credentials (object ):
374333
0 commit comments