Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK committed Sep 19, 2024
1 parent e211b11 commit ba2b90b
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,50 +419,49 @@ 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)


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())
(event,) = 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)

Expand Down

0 comments on commit ba2b90b

Please sign in to comment.