mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 20:10:10 +03:00
Fix test with Django 5 when pytz is available (#9715)
* Fix test with Django 5 when pytz is available * fix formatting * remove original condition Co-authored-by: Ülgen Sarıkavak <ulgens@users.noreply.github.com> * remove trailing whitespace * further improvements * let's not skip the pytz test - it should always be executed when testing against Django 4 * add comment to test requirements Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com> * simplify the pytz import as it should always be available * make isort happy --------- Co-authored-by: Ülgen Sarıkavak <ulgens@users.noreply.github.com> Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
This commit is contained in:
parent
2ae8c117da
commit
853969c69c
|
@ -5,3 +5,4 @@ pytest-django>=4.5.2,<5.0
|
||||||
importlib-metadata<5.0
|
importlib-metadata<5.0
|
||||||
# temporary pin of attrs
|
# temporary pin of attrs
|
||||||
attrs==22.1.0
|
attrs==22.1.0
|
||||||
|
pytz # Remove when dropping support for Django<5.0
|
||||||
|
|
|
@ -9,13 +9,9 @@ from enum import auto
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
import django
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytz
|
||||||
try:
|
|
||||||
import pytz
|
|
||||||
except ImportError:
|
|
||||||
pytz = None
|
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||||
from django.db.models import IntegerChoices, TextChoices
|
from django.db.models import IntegerChoices, TextChoices
|
||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
|
@ -1624,7 +1620,10 @@ class TestCustomTimezoneForDateTimeField(TestCase):
|
||||||
assert rendered_date == rendered_date_in_timezone
|
assert rendered_date == rendered_date_in_timezone
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(pytz is None, reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.")
|
@pytest.mark.skipif(
|
||||||
|
condition=django.VERSION >= (5,),
|
||||||
|
reason="Django 5.0 has removed pytz; this test should eventually be able to get removed.",
|
||||||
|
)
|
||||||
class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
|
class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
|
||||||
"""
|
"""
|
||||||
Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST.
|
Invalid values for `DateTimeField` with datetime in DST shift (non-existing or ambiguous) and timezone with DST.
|
||||||
|
@ -1638,16 +1637,15 @@ class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
|
||||||
}
|
}
|
||||||
outputs = {}
|
outputs = {}
|
||||||
|
|
||||||
if pytz:
|
class MockTimezone(pytz.BaseTzInfo):
|
||||||
class MockTimezone(pytz.BaseTzInfo):
|
@staticmethod
|
||||||
@staticmethod
|
def localize(value, is_dst):
|
||||||
def localize(value, is_dst):
|
raise pytz.InvalidTimeError()
|
||||||
raise pytz.InvalidTimeError()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'America/New_York'
|
return 'America/New_York'
|
||||||
|
|
||||||
field = serializers.DateTimeField(default_timezone=MockTimezone())
|
field = serializers.DateTimeField(default_timezone=MockTimezone())
|
||||||
|
|
||||||
|
|
||||||
@patch('rest_framework.utils.timezone.datetime_ambiguous', return_value=True)
|
@patch('rest_framework.utils.timezone.datetime_ambiguous', return_value=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user