feat: test middleware; use zoneinfo; fix datetime warnings

This commit is contained in:
bkfox
2023-08-23 15:08:20 +02:00
parent 02a8bb7a4e
commit 43c2d552e4
11 changed files with 53 additions and 36 deletions

View File

@@ -2,6 +2,7 @@ from datetime import time, timedelta
import itertools
import logging
from django.conf import settings
from django.contrib.auth.models import User
from django.test import RequestFactory
@@ -16,6 +17,12 @@ req_factory = RequestFactory()
"""Request Factory used among different tests."""
settings.ALLOWED_HOSTS = list(settings.ALLOWED_HOSTS) + [
"sub.server.org",
"server.org",
]
@pytest.fixture
def staff_user():
return baker.make(User, is_active=True, is_staff=True)
@@ -31,12 +38,23 @@ def logger():
@pytest.fixture
def station():
return baker.make(models.Station, audio_streams="stream 1\nstream 2")
return baker.make(
models.Station,
hosts="server.org",
audio_streams="stream 1\nstream 2",
default=True,
)
@pytest.fixture
def stations(station):
return [station, baker.make(models.Station)]
def sub_station():
"""Non-default station."""
return baker.make(models.Station, hosts="sub.server.org", default=False)
@pytest.fixture
def stations(station, sub_station):
return [station, sub_station]
@pytest.fixture

View File

@@ -24,7 +24,7 @@ class TestSchedule:
@pytest.mark.django_db
def test_tz(self, schedules):
for schedule in schedules:
assert schedule.timezone == schedule.tz.zone
assert schedule.timezone == schedule.tz.key
@pytest.mark.django_db
def test_start(self, schedules):
@@ -45,7 +45,7 @@ class TestSchedule:
def test_normalize(self, schedules):
for schedule in schedules:
dt = datetime.combine(schedule.date, schedule.time)
assert schedule.normalize(dt).tzinfo.zone == schedule.timezone
assert schedule.normalize(dt).tzinfo.key == schedule.timezone
@pytest.mark.django_db
def test_dates_of_month_ponctual(self):
@@ -117,7 +117,7 @@ class TestSchedule:
assert dt.month == at.month
assert dt.weekday() == schedule.date.weekday()
assert dt.time() == schedule.time
assert dt.tzinfo.zone == schedule.timezone
assert dt.tzinfo.key == schedule.timezone
@pytest.mark.django_db
def test_diffusions_of_month(self, sched_initials):