mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
Events: some modelling and a command to ingest JSONs from other projects as examples
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from unittest import TestCase
|
||||
import datetime
|
||||
from django.test import override_settings
|
||||
|
||||
from .dsn import get_store_url, get_envelope_url, get_header_value
|
||||
from .auth import parse_auth_header_value
|
||||
from .timestamp import parse_timestamp
|
||||
|
||||
|
||||
class DsnTestCase(TestCase):
|
||||
@@ -29,7 +32,39 @@ class DsnTestCase(TestCase):
|
||||
"Sentry sentry_key=public_key, sentry_version=7, sentry_client=bugsink/0.0.1",
|
||||
get_header_value("https://public_key@hosted.bugsink/1"))
|
||||
|
||||
|
||||
class AuthTestCase(TestCase):
|
||||
def test_parse_header_value(self):
|
||||
self.assertEquals(
|
||||
{"sentry_key": "foo", "sentry_version": "bar"},
|
||||
parse_auth_header_value('Sentry sentry_key=foo,sentry_version=bar'))
|
||||
|
||||
|
||||
class TimestampTestCase(TestCase):
|
||||
def test_numeric_values(self):
|
||||
self.assertEquals(
|
||||
datetime.datetime(2023, 11, 11, 17, 32, 24, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp(1699723944))
|
||||
|
||||
self.assertEquals(
|
||||
datetime.datetime(2023, 11, 11, 17, 32, 24, 500_000, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp(1699723944.5))
|
||||
|
||||
def test_string(self):
|
||||
self.assertEquals(
|
||||
datetime.datetime(2022, 9, 1, 9, 45, 0, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp("2022-09-01T09:45:00.000Z"))
|
||||
|
||||
self.assertEquals(
|
||||
datetime.datetime(2018, 1, 1, 5, 6, 7, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp("2018-01-01T05:06:07+00:00"))
|
||||
|
||||
@override_settings(TIME_ZONE='Europe/Istanbul')
|
||||
def test_non_utc_settings_dont_influence_parsing(self):
|
||||
self.assertEquals(
|
||||
datetime.datetime(2023, 11, 11, 17, 32, 24, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp(1699723944))
|
||||
|
||||
self.assertEquals(
|
||||
datetime.datetime(2022, 9, 1, 9, 45, 0, tzinfo=datetime.timezone.utc),
|
||||
parse_timestamp("2022-09-01T09:45:00.000Z"))
|
||||
|
||||
22
compat/timestamp.py
Normal file
22
compat/timestamp.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import datetime
|
||||
|
||||
from django.utils.dateparse import parse_datetime
|
||||
|
||||
|
||||
def parse_timestamp(value):
|
||||
"""
|
||||
> Indicates when the event was created in the Sentry SDK. The format is either a string as defined in RFC 3339 or a
|
||||
> numeric (integer or float) value representing the number of seconds that have elapsed since the Unix epoch
|
||||
|
||||
> Timezone is assumed to be UTC if missing.
|
||||
|
||||
> Sub-microsecond precision is not preserved with numeric values due to precision limitations with floats (at least
|
||||
> in our systems). With that caveat in mind, just send whatever is easiest to produce.
|
||||
|
||||
> All timestamps in the event protocol are formatted this way.
|
||||
"""
|
||||
|
||||
if isinstance(value, int) or isinstance(value, float):
|
||||
return datetime.datetime.fromtimestamp(value, tz=datetime.timezone.utc)
|
||||
|
||||
return parse_datetime(value)
|
||||
Reference in New Issue
Block a user