Skip to content

Commit 9baa5b3

Browse files
committed
Move imports in logging system tests, use _datetime_to_rfc3339.
1 parent 7d9bce0 commit 9baa5b3

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

logging/unit_tests/test__gax.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def test_write_entries_w_extra_properties(self):
369369
from datetime import datetime
370370
from google.logging.type.log_severity_pb2 import WARNING
371371
from google.cloud.proto.logging.v2.log_entry_pb2 import LogEntry
372+
from google.cloud._helpers import _datetime_to_rfc3339
372373
from google.cloud._helpers import UTC, _pb_timestamp_to_datetime
373374

374375
NOW = datetime.utcnow().replace(tzinfo=UTC)
@@ -412,7 +413,7 @@ def test_write_entries_w_extra_properties(self):
412413
'severity': SEVERITY,
413414
'labels': LABELS,
414415
'insertId': IID,
415-
'timestamp': NOW.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
416+
'timestamp': _datetime_to_rfc3339(NOW),
416417
'httpRequest': REQUEST,
417418
'operation': OPERATION,
418419
}

logging/unit_tests/test_logger.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ def test_commit_w_bound_client(self):
653653
from google.protobuf.json_format import MessageToJson
654654
from google.protobuf.struct_pb2 import Struct
655655
from google.protobuf.struct_pb2 import Value
656+
from google.cloud._helpers import _datetime_to_rfc3339
656657

657658
TEXT = 'This is the entry text'
658659
STRUCT = {'message': TEXT, 'weather': 'partly cloudy'}
@@ -668,12 +669,12 @@ def test_commit_w_bound_client(self):
668669
}
669670
ENTRIES = [
670671
{'textPayload': TEXT, 'insertId': IID1,
671-
'timestamp': TIMESTAMP1.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
672+
'timestamp': _datetime_to_rfc3339(TIMESTAMP1)},
672673
{'jsonPayload': STRUCT, 'insertId': IID2,
673-
'timestamp': TIMESTAMP2.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
674+
'timestamp': _datetime_to_rfc3339(TIMESTAMP2)},
674675
{'protoPayload': json.loads(MessageToJson(message)),
675676
'insertId': IID3,
676-
'timestamp': TIMESTAMP3.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
677+
'timestamp': _datetime_to_rfc3339(TIMESTAMP3)},
677678
]
678679
client = _Client(project=self.PROJECT)
679680
api = client.logging_api = _DummyLoggingAPI()

system_tests/logging_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import datetime
1516
import logging
1617
import unittest
1718

1819
from google.gax.errors import GaxError
1920
from google.gax.grpc import exc_to_code
2021
from grpc import StatusCode
2122

23+
from google.cloud._helpers import UTC
2224
from google.cloud.exceptions import Conflict
2325
from google.cloud.exceptions import NotFound
2426
from google.cloud.exceptions import TooManyRequests
@@ -131,8 +133,6 @@ def test_log_text(self):
131133
self.assertEqual(entries[0].payload, TEXT_PAYLOAD)
132134

133135
def test_log_text_with_timestamp(self):
134-
import datetime
135-
136136
text_payload = 'System test: test_log_text_with_timestamp'
137137
logger = Config.CLIENT.logger(self._logger_name())
138138
now = datetime.datetime.utcnow()
@@ -143,7 +143,7 @@ def test_log_text_with_timestamp(self):
143143
entries = _list_entries(logger)
144144
self.assertEqual(len(entries), 1)
145145
self.assertEqual(entries[0].payload, text_payload)
146-
# self.assertEqual(entries[0].timestamp, now)
146+
self.assertEqual(entries[0].timestamp, now.replace(tzinfo=UTC))
147147

148148
def test_log_text_w_metadata(self):
149149
TEXT_PAYLOAD = 'System test: test_log_text'

0 commit comments

Comments
 (0)