@@ -64,9 +64,9 @@ def test_list_entries_no_paging(self):
6464 self .assertEqual (len (entries ), 1 )
6565 entry = entries [0 ]
6666 self .assertIsInstance (entry , dict )
67- self .assertEqual (entry ['log_name ' ], self .LOG_NAME )
67+ self .assertEqual (entry ['logName ' ], self .LOG_NAME )
6868 self .assertEqual (entry ['resource' ], {'type' : 'global' })
69- self .assertEqual (entry ['text_payload ' ], TEXT )
69+ self .assertEqual (entry ['textPayload ' ], TEXT )
7070 self .assertEqual (next_token , TOKEN )
7171
7272 projects , filter_ , order_by , page_size , options = (
@@ -94,9 +94,9 @@ def test_list_entries_with_paging(self):
9494 self .assertEqual (len (entries ), 1 )
9595 entry = entries [0 ]
9696 self .assertIsInstance (entry , dict )
97- self .assertEqual (entry ['log_name ' ], self .LOG_NAME )
97+ self .assertEqual (entry ['logName ' ], self .LOG_NAME )
9898 self .assertEqual (entry ['resource' ], {'type' : 'global' })
99- self .assertEqual (entry ['json_payload ' ], PAYLOAD )
99+ self .assertEqual (entry ['jsonPayload ' ], PAYLOAD )
100100 self .assertEqual (next_token , NEW_TOKEN )
101101
102102 projects , filter_ , order_by , page_size , options = (
@@ -108,7 +108,12 @@ def test_list_entries_with_paging(self):
108108 self .assertEqual (options .page_token , TOKEN )
109109
110110 def test_list_entries_with_extra_properties (self ):
111+ from datetime import datetime
111112 from gcloud ._testing import _GAXPageIterator
113+ from gcloud ._helpers import UTC
114+ from gcloud ._helpers import _datetime_to_rfc3339
115+ from gcloud ._helpers import _datetime_to_pb_timestamp
116+ NOW = datetime .utcnow ().replace (tzinfo = UTC )
112117 SIZE = 23
113118 TOKEN = 'TOKEN'
114119 NEW_TOKEN = 'NEW_TOKEN'
@@ -128,6 +133,8 @@ def test_list_entries_with_extra_properties(self):
128133 'operation' : operation ,
129134 }
130135 ENTRY = _LogEntryPB (self .LOG_NAME , proto_payload = PAYLOAD , ** EXTRAS )
136+ ENTRY .resource .labels ['foo' ] = 'bar'
137+ ENTRY .timestamp = _datetime_to_pb_timestamp (NOW )
131138 response = _GAXPageIterator ([ENTRY ], NEW_TOKEN )
132139 gax_api = _GAXLoggingAPI (_list_log_entries_response = response )
133140 api = self ._makeOne (gax_api )
@@ -138,12 +145,14 @@ def test_list_entries_with_extra_properties(self):
138145 self .assertEqual (len (entries ), 1 )
139146 entry = entries [0 ]
140147 self .assertIsInstance (entry , dict )
141- self .assertEqual (entry ['log_name' ], self .LOG_NAME )
142- self .assertEqual (entry ['resource' ], {'type' : 'global' })
143- self .assertEqual (entry ['proto_payload' ], PAYLOAD )
148+ self .assertEqual (entry ['logName' ], self .LOG_NAME )
149+ self .assertEqual (entry ['resource' ],
150+ {'type' : 'global' , 'labels' : {'foo' : 'bar' }})
151+ self .assertEqual (entry ['protoPayload' ], PAYLOAD )
144152 self .assertEqual (entry ['severity' ], SEVERITY )
145153 self .assertEqual (entry ['labels' ], LABELS )
146- self .assertEqual (entry ['insert_id' ], IID )
154+ self .assertEqual (entry ['insertId' ], IID )
155+ self .assertEqual (entry ['timestamp' ], _datetime_to_rfc3339 (NOW ))
147156 EXPECTED_REQUEST = {
148157 'request_method' : request .request_method ,
149158 'request_url' : request .request_url ,
@@ -155,7 +164,7 @@ def test_list_entries_with_extra_properties(self):
155164 'remote_ip' : request .remote_ip ,
156165 'cache_hit' : request .cache_hit ,
157166 }
158- self .assertEqual (entry ['http_request ' ], EXPECTED_REQUEST )
167+ self .assertEqual (entry ['httpRequest ' ], EXPECTED_REQUEST )
159168 EXPECTED_OPERATION = {
160169 'producer' : operation .producer ,
161170 'id' : operation .id ,
@@ -178,9 +187,9 @@ def test_write_entries_single(self):
178187 TEXT = 'TEXT'
179188 LOG_PATH = 'projects/%s/logs/%s' % (self .PROJECT , self .LOG_NAME )
180189 ENTRY = {
181- 'log_name ' : LOG_PATH ,
190+ 'logName ' : LOG_PATH ,
182191 'resource' : {'type' : 'global' },
183- 'text_payload ' : TEXT ,
192+ 'textPayload ' : TEXT ,
184193 }
185194 gax_api = _GAXLoggingAPI ()
186195 api = self ._makeOne (gax_api )
@@ -227,15 +236,15 @@ def test_write_entries_w_extra_properties(self):
227236 USER_AGENT = 'Agent/1.0'
228237 REMOTE_IP = '1.2.3.4'
229238 REQUEST = {
230- 'request_method ' : REQUEST_METHOD ,
231- 'request_url ' : REQUEST_URL ,
239+ 'requestMethod ' : REQUEST_METHOD ,
240+ 'requestUrl ' : REQUEST_URL ,
232241 'status' : STATUS ,
233- 'request_size ' : REQUEST_SIZE ,
234- 'response_size ' : RESPONSE_SIZE ,
242+ 'requestSize ' : REQUEST_SIZE ,
243+ 'responseSize ' : RESPONSE_SIZE ,
235244 'referer' : REFERRER_URL ,
236- 'user_agent ' : USER_AGENT ,
237- 'remote_ip ' : REMOTE_IP ,
238- 'cache_hit ' : False ,
245+ 'userAgent ' : USER_AGENT ,
246+ 'remoteIp ' : REMOTE_IP ,
247+ 'cacheHit ' : False ,
239248 }
240249 PRODUCER = 'PRODUCER'
241250 OPID = 'OPID'
@@ -246,14 +255,14 @@ def test_write_entries_w_extra_properties(self):
246255 'last' : True ,
247256 }
248257 ENTRY = {
249- 'log_name ' : LOG_PATH ,
258+ 'logName ' : LOG_PATH ,
250259 'resource' : {'type' : 'global' },
251- 'text_payload ' : TEXT ,
260+ 'textPayload ' : TEXT ,
252261 'severity' : SEVERITY ,
253262 'labels' : LABELS ,
254- 'insert_id ' : IID ,
263+ 'insertId ' : IID ,
255264 'timestamp' : NOW ,
256- 'http_request ' : REQUEST ,
265+ 'httpRequest ' : REQUEST ,
257266 'operation' : OPERATION ,
258267 }
259268 gax_api = _GAXLoggingAPI ()
@@ -302,28 +311,30 @@ def test_write_entries_w_extra_properties(self):
302311
303312 def test_write_entries_multiple (self ):
304313 # pylint: disable=too-many-statements
314+ import datetime
305315 from google .logging .type .log_severity_pb2 import WARNING
306316 from google .logging .v2 .log_entry_pb2 import LogEntry
307317 from google .protobuf .any_pb2 import Any
308318 from google .protobuf .struct_pb2 import Struct
319+ from gcloud ._helpers import _datetime_to_rfc3339 , UTC
309320 TEXT = 'TEXT'
310- TIMESTAMP = _LogEntryPB . _make_timestamp ( )
321+ NOW = datetime . datetime . utcnow (). replace ( tzinfo = UTC )
311322 TIMESTAMP_TYPE_URL = 'type.googleapis.com/google.protobuf.Timestamp'
312323 JSON = {'payload' : 'PAYLOAD' , 'type' : 'json' }
313324 PROTO = {
314325 '@type' : TIMESTAMP_TYPE_URL ,
315- 'value' : TIMESTAMP ,
326+ 'value' : _datetime_to_rfc3339 ( NOW ) ,
316327 }
317328 PRODUCER = 'PRODUCER'
318329 OPID = 'OPID'
319330 URL = 'http://example.com/'
320331 ENTRIES = [
321- {'text_payload ' : TEXT ,
332+ {'textPayload ' : TEXT ,
322333 'severity' : WARNING },
323- {'json_payload ' : JSON ,
334+ {'jsonPayload ' : JSON ,
324335 'operation' : {'producer' : PRODUCER , 'id' : OPID }},
325- {'proto_payload ' : PROTO ,
326- 'http_request ' : {'request_url ' : URL }},
336+ {'protoPayload ' : PROTO ,
337+ 'httpRequest ' : {'requestUrl ' : URL }},
327338 ]
328339 LOG_PATH = 'projects/%s/logs/%s' % (self .PROJECT , self .LOG_NAME )
329340 RESOURCE = {
@@ -956,6 +967,13 @@ class _LogEntryOperationPB(object):
956967 id = 'OPID'
957968
958969
970+ class _ResourcePB (object ):
971+
972+ def __init__ (self , type_ = 'global' , ** labels ):
973+ self .type = type_
974+ self .labels = labels
975+
976+
959977class _LogEntryPB (object ):
960978
961979 severity = 'DEFAULT'
@@ -964,7 +982,7 @@ class _LogEntryPB(object):
964982
965983 def __init__ (self , log_name , ** kw ):
966984 self .log_name = log_name
967- self .resource = { 'type' : 'global' }
985+ self .resource = _ResourcePB ()
968986 self .timestamp = self ._make_timestamp ()
969987 self .labels = kw .pop ('labels' , {})
970988 self .__dict__ .update (kw )
@@ -973,9 +991,9 @@ def __init__(self, log_name, **kw):
973991 def _make_timestamp ():
974992 from datetime import datetime
975993 from gcloud ._helpers import UTC
976- from gcloud .logging . test_entries import _datetime_to_rfc3339_w_nanos
994+ from gcloud ._helpers import _datetime_to_pb_timestamp
977995 NOW = datetime .utcnow ().replace (tzinfo = UTC )
978- return _datetime_to_rfc3339_w_nanos (NOW )
996+ return _datetime_to_pb_timestamp (NOW )
979997
980998
981999class _LogSinkPB (object ):
0 commit comments