Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions openstates/data/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from datetime import datetime
from datetime import datetime, timezone
from openstates.data.models import (
Jurisdiction,
Division,
Expand Down Expand Up @@ -90,7 +90,10 @@ def event(jurisdiction, event_location):
jurisdiction=jurisdiction,
description="To discuss the pros/cons of wind farming.",
classification="committee-meeting",
start_date=datetime.utcnow().isoformat().split(".")[0],
start_date=datetime.now(timezone.utc)
.replace(tzinfo=None)
.isoformat()
.split(".")[0],
status="passed",
location=event_location,
)
Expand Down
4 changes: 3 additions & 1 deletion openstates/importers/tests/test_base_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def test_invalid_fields_related_item():
@pytest.mark.django_db
def test_automatic_updated_at():
create_jurisdiction()
difference = Organization.objects.get().updated_at - datetime.datetime.utcnow()
difference = Organization.objects.get().updated_at - datetime.datetime.now(
datetime.timezone.utc
).replace(tzinfo=None)
# updated_at should be in UTC, a bit of clock drift notwithstanding
assert abs(difference) < datetime.timedelta(minutes=5)

Expand Down
5 changes: 4 additions & 1 deletion openstates/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class TimeScoped(BaseModel):
)

def is_active(self) -> bool:
date = datetime.datetime.utcnow().date().isoformat()
# datetime.utcnow() is deprecated in Python 3.12.
date = (
datetime.datetime.now(datetime.timezone.utc).date().isoformat()
)
return (self.end_date == "" or str(self.end_date) > date) and (
self.start_date == "" or str(self.start_date) <= date
)
Expand Down
6 changes: 5 additions & 1 deletion openstates/scrape/tests/test_event_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
def event_obj():
e = Event(
name="get-together",
start_date=datetime.datetime.utcnow().isoformat().split(".")[0] + "Z",
start_date=datetime.datetime.now(datetime.timezone.utc)
.replace(tzinfo=None)
.isoformat()
.split(".")[0]
+ "Z",
location_name="Joe's Place",
)
e.add_source(url="http://example.com/foobar")
Expand Down