From ca2376404f985bcd473221c446eb07296c2b43d3 Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:59:22 -0500 Subject: [PATCH] ref: remove calls to iso_format in testutils (#82461) --- src/sentry/integrations/github/client.py | 2 +- src/sentry/testutils/cases.py | 6 +++--- src/sentry/testutils/fixtures.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sentry/integrations/github/client.py b/src/sentry/integrations/github/client.py index 98c189d50bbbfd..5db8d605024778 100644 --- a/src/sentry/integrations/github/client.py +++ b/src/sentry/integrations/github/client.py @@ -141,7 +141,7 @@ def _get_token(self, prepared_request: PreparedRequest) -> str | None: access_token: str | None = self.integration.metadata.get("access_token") expires_at: str | None = self.integration.metadata.get("expires_at") is_expired = ( - bool(expires_at) and datetime.strptime(cast(str, expires_at), "%Y-%m-%dT%H:%M:%S") < now + bool(expires_at) and datetime.fromisoformat(expires_at).replace(tzinfo=None) < now ) should_refresh = not access_token or not expires_at or is_expired diff --git a/src/sentry/testutils/cases.py b/src/sentry/testutils/cases.py index c8d30c3b3a71a3..dee1be41de057b 100644 --- a/src/sentry/testutils/cases.py +++ b/src/sentry/testutils/cases.py @@ -132,7 +132,7 @@ from sentry.snuba.metrics.naming_layer.public import TransactionMetricKey from sentry.tagstore.snuba.backend import SnubaTagStorage from sentry.testutils.factories import get_fixture_path -from sentry.testutils.helpers.datetime import before_now, iso_format +from sentry.testutils.helpers.datetime import before_now from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE from sentry.testutils.helpers.slack import install_slack from sentry.testutils.pytest.selenium import Browser @@ -2126,7 +2126,7 @@ def create_event(self, timestamp, fingerprint=None, user=None): data = { "event_id": event_id, "fingerprint": [fingerprint], - "timestamp": iso_format(timestamp), + "timestamp": timestamp.isoformat(), "type": "error", # This is necessary because event type error should not exist without # an exception being in the payload @@ -3388,7 +3388,7 @@ def load_default(self) -> Event: start, _ = self.get_start_end_from_day_ago(1000) return self.store_event( { - "timestamp": iso_format(start), + "timestamp": start.isoformat(), "contexts": { "trace": { "type": "trace", diff --git a/src/sentry/testutils/fixtures.py b/src/sentry/testutils/fixtures.py index 8496eded5216ea..6c6b2c535c750a 100644 --- a/src/sentry/testutils/fixtures.py +++ b/src/sentry/testutils/fixtures.py @@ -29,7 +29,7 @@ from sentry.snuba.models import QuerySubscription from sentry.tempest.models import TempestCredentials from sentry.testutils.factories import Factories -from sentry.testutils.helpers.datetime import before_now, iso_format +from sentry.testutils.helpers.datetime import before_now from sentry.testutils.silo import assume_test_silo_mode # XXX(dcramer): this is a compatibility layer to transition to pytest-based fixtures @@ -104,7 +104,7 @@ def event(self): data={ "event_id": "a" * 32, "message": "\u3053\u3093\u306b\u3061\u306f", - "timestamp": iso_format(before_now(seconds=1)), + "timestamp": before_now(seconds=1).isoformat(), }, project_id=self.project.id, ) @@ -129,7 +129,7 @@ def integration(self): external_id="github:1", metadata={ "access_token": "xxxxx-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx", - "expires_at": iso_format(timezone.now() + timedelta(days=14)), + "expires_at": (timezone.now() + timedelta(days=14)).isoformat(), }, ) integration.add_organization(self.organization, self.user)