diff --git a/exceptional_situations/tests/test_api.py b/exceptional_situations/tests/test_api.py index 1278daff..d1f979c4 100644 --- a/exceptional_situations/tests/test_api.py +++ b/exceptional_situations/tests/test_api.py @@ -1,7 +1,6 @@ from datetime import datetime, timedelta import pytest -from django.utils import timezone from rest_framework.reverse import reverse SITUATION_LIST_URL = reverse("exceptional_situations:situation-list") @@ -70,8 +69,8 @@ def test_situation_retrieve(api_client, situations): @pytest.mark.django_db -def test_situation_filter_by_start_time(api_client, situations): - start_time = timezone.now() - timedelta(hours=6) +def test_situation_filter_by_start_time(api_client, situations, now): + start_time = now - timedelta(hours=6) response = api_client.get( SITUATION_LIST_URL + f"?start_time__gt={datetime.strftime(start_time, DATETIME_FORMAT)}" @@ -84,7 +83,7 @@ def test_situation_filter_by_start_time(api_client, situations): ) assert response.json()["count"] == 1 - start_time = timezone.now() - timedelta(days=2) + start_time = now - timedelta(days=2) response = api_client.get( SITUATION_LIST_URL + f"?start_time__gt={datetime.strftime(start_time, DATETIME_FORMAT)}" @@ -98,8 +97,8 @@ def test_situation_filter_by_start_time(api_client, situations): @pytest.mark.django_db -def test_situation_filter_by_end_time(api_client, situations): - end_time = timezone.now() +def test_situation_filter_by_end_time(api_client, situations, now): + end_time = now response = api_client.get( SITUATION_LIST_URL + f"?end_time__gt={datetime.strftime(end_time, DATETIME_FORMAT)}" @@ -111,7 +110,7 @@ def test_situation_filter_by_end_time(api_client, situations): ) assert response.json()["count"] == 0 - end_time = timezone.now() - timedelta(days=2) + end_time = now - timedelta(days=2) response = api_client.get( SITUATION_LIST_URL + f"?end_time__gt={datetime.strftime(end_time, DATETIME_FORMAT)}" diff --git a/exceptional_situations/tests/test_models.py b/exceptional_situations/tests/test_models.py index 0561ce4a..56ee23d1 100644 --- a/exceptional_situations/tests/test_models.py +++ b/exceptional_situations/tests/test_models.py @@ -1,20 +1,19 @@ from datetime import timedelta import pytest -from django.utils import timezone from exceptional_situations.models import Situation, SituationAnnouncement @pytest.mark.django_db -def test_situation_is_active(situation_types): - now = timezone.now() +def test_situation_is_active(situation_types, now): announcement_1 = SituationAnnouncement.objects.create(start_time=now, title="test1") announcement_2 = SituationAnnouncement.objects.create(start_time=now, title="test2") situation = Situation.objects.create( release_time=now, situation_type=situation_types.first(), situation_id="TestID" ) + # No announcements, returns False assert situation.is_active is False situation.announcements.add(announcement_1) @@ -44,8 +43,7 @@ def test_situation_is_active(situation_types): @pytest.mark.django_db -def test_situation_start_time(situation_types): - now = timezone.now() +def test_situation_start_time(situation_types, now): announcement_1 = SituationAnnouncement.objects.create( start_time=now, title="starts now" ) @@ -61,8 +59,7 @@ def test_situation_start_time(situation_types): @pytest.mark.django_db -def test_situation_end_time(situation_types): - now = timezone.now() +def test_situation_end_time(situation_types, now): announcement_1 = SituationAnnouncement.objects.create( start_time=now - timedelta(hours=1), end_time=now + timedelta(hours=2),