From ba2b90b3ed70d46affec8c58a94c70dcb61ee1b9 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 19 Sep 2024 17:47:05 +0100 Subject: [PATCH] add more tests --- tests/test_basics.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/test_basics.py b/tests/test_basics.py index 9a2dbf5316..3415f80b8e 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -8,6 +8,7 @@ import pytest from sentry_sdk.client import Client +from sentry_sdk.utils import datetime_from_isoformat from tests.conftest import patch_start_tracing_child import sentry_sdk @@ -418,14 +419,7 @@ def test_breadcrumb_ordering(sentry_init, capture_events): assert len(event["breadcrumbs"]["values"]) == len(timestamps) timestamps_from_event = [ - datetime.datetime.strptime( - # Because Python doesn't know how to parse ISO timestamps until 3.11 - # And Python 3.6 randomly uses +00:00 or Z as UTC timezone - # TODO: Replace this with the format "%Y-%m-%dT%H:%M:%S.%f%z" once 3.6 is gone - x["timestamp"][0:19], - "%Y-%m-%dT%H:%M:%S", - ).replace(tzinfo=datetime.timezone.utc) - for x in event["breadcrumbs"]["values"] + datetime_from_isoformat(x["timestamp"]) for x in event["breadcrumbs"]["values"] ] assert timestamps_from_event == sorted(timestamps) @@ -433,20 +427,33 @@ def test_breadcrumb_ordering(sentry_init, capture_events): def test_breadcrumb_ordering_different_types(sentry_init, capture_events): sentry_init() events = capture_events() - now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0) + now = datetime.datetime.now(datetime.timezone.utc) timestamps = [ now - datetime.timedelta(days=10), now - datetime.timedelta(days=8), - now - datetime.timedelta(days=12), + now.replace(microsecond=0) - datetime.timedelta(days=12), + now - datetime.timedelta(days=9), + now - datetime.timedelta(days=13), + now.replace(microsecond=0) - datetime.timedelta(days=11), + ] + + breadcrumb_timestamps = [ + timestamps[0], + timestamps[1].isoformat(), + datetime.datetime.strftime(timestamps[2], "%Y-%m-%dT%H:%M:%S") + "Z", + datetime.datetime.strftime(timestamps[3], "%Y-%m-%dT%H:%M:%S.%f") + "+00:00", + datetime.datetime.strftime(timestamps[4], "%Y-%m-%dT%H:%M:%S.%f") + "+0000", + datetime.datetime.strftime(timestamps[5], "%Y-%m-%dT%H:%M:%S.%f") + "+0000", ] + print(breadcrumb_timestamps) for i, timestamp in enumerate(timestamps): add_breadcrumb( message="Authenticated at %s" % timestamp, category="auth", level="info", - timestamp=timestamp if i % 2 == 0 else timestamp.isoformat(), + timestamp=breadcrumb_timestamps[i], ) capture_exception(ValueError()) @@ -454,14 +461,7 @@ def test_breadcrumb_ordering_different_types(sentry_init, capture_events): assert len(event["breadcrumbs"]["values"]) == len(timestamps) timestamps_from_event = [ - datetime.datetime.strptime( - # Because Python doesn't know how to parse ISO timestamps until 3.11 - # And Python 3.6 randomly uses +00:00 or Z as UTC timezone - # TODO: Replace this with the format "%Y-%m-%dT%H:%M:%S.%f%z" once 3.6 is gone - x["timestamp"][0:19], - "%Y-%m-%dT%H:%M:%S", - ).replace(tzinfo=datetime.timezone.utc) - for x in event["breadcrumbs"]["values"] + datetime_from_isoformat(x["timestamp"]) for x in event["breadcrumbs"]["values"] ] assert timestamps_from_event == sorted(timestamps)