Skip to content

Commit

Permalink
Add datetime.now() as fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Sep 3, 2024
1 parent 999d047 commit 2979eb8
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions exceptional_situations/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta
from datetime import datetime, timedelta

import pytest
from django.contrib.gis.geos import GEOSGeometry
Expand All @@ -13,14 +13,17 @@
SituationType,
)

NOW = timezone.now()


@pytest.fixture
def api_client():
return APIClient()


@pytest.fixture
def now():
return datetime.now().replace(tzinfo=timezone.get_default_timezone())


@pytest.mark.django_db
@pytest.fixture
def municipalities():
Expand Down Expand Up @@ -58,15 +61,16 @@ def locations():

@pytest.mark.django_db
@pytest.fixture
def announcements(locations, municipalities):
def announcements(locations, municipalities, now):

json_data = {"test_key": "test_value"}
sa = SituationAnnouncement.objects.create(
title="Twelve hours",
description="Twelve hours long situation",
additional_info=json_data,
location=locations[0],
start_time=NOW,
end_time=NOW + timedelta(hours=12),
start_time=now,
end_time=now + timedelta(hours=12),
)
sa.municipalities.add(municipalities.filter(id="turku").first())
sa.municipalities.add(municipalities.filter(id="lieto").first())
Expand All @@ -75,33 +79,33 @@ def announcements(locations, municipalities):
description="two days long situation",
additional_info=json_data,
location=locations[1],
start_time=NOW - timedelta(days=1),
end_time=NOW + timedelta(days=1),
start_time=now - timedelta(days=1),
end_time=now + timedelta(days=1),
)
sa.municipalities.add(municipalities.filter(id="raisio").first())
return SituationAnnouncement.objects.all()


@pytest.mark.django_db
@pytest.fixture
def inactive_announcements(locations):
def inactive_announcements(locations, now):
json_data = {"test_key": "test_value"}
SituationAnnouncement.objects.create(
title="in past",
description="inactive announcement",
additional_info=json_data,
location=locations[2],
start_time=NOW - timedelta(days=2),
end_time=NOW - timedelta(days=1),
start_time=now - timedelta(days=2),
end_time=now - timedelta(days=1),
)
return SituationAnnouncement.objects.all()


@pytest.mark.django_db
@pytest.fixture
def inactive_situations(situation_types, inactive_announcements):
def inactive_situations(situation_types, inactive_announcements, now):
situation = Situation.objects.create(
release_time=NOW,
release_time=now,
situation_id="inactive",
situation_type=situation_types.first(),
)
Expand All @@ -111,15 +115,15 @@ def inactive_situations(situation_types, inactive_announcements):

@pytest.mark.django_db
@pytest.fixture
def situations(situation_types, announcements):
def situations(situation_types, announcements, now):
situation = Situation.objects.create(
release_time=NOW,
situation_id="TwoHoursLong",
release_time=now,
situation_id="TwelveHoursLong",
situation_type=situation_types.first(),
)
situation.announcements.add(announcements[0])
situation = Situation.objects.create(
release_time=NOW - timedelta(days=1),
release_time=now - timedelta(days=1),
situation_id="TwoDaysLong",
situation_type=situation_types.first(),
)
Expand Down

0 comments on commit 2979eb8

Please sign in to comment.