mirror of https://github.com/django/django.git
[1.6.x] Fixed #21074 -- Added tests for localized datetime fields.
Fields must render values in the current time zone.
This commit only contains tests because this ticket was just a symptom of
a regression from #18777 that was fixed separately.
Backport of 5444a9c
from master.
This commit is contained in:
parent
ece8d65217
commit
e76dd4cd1a
|
@ -8,7 +8,16 @@ class EventForm(forms.Form):
|
||||||
class EventSplitForm(forms.Form):
|
class EventSplitForm(forms.Form):
|
||||||
dt = forms.SplitDateTimeField()
|
dt = forms.SplitDateTimeField()
|
||||||
|
|
||||||
|
class EventLocalizedForm(forms.Form):
|
||||||
|
dt = forms.DateTimeField(localize=True)
|
||||||
|
|
||||||
class EventModelForm(forms.ModelForm):
|
class EventModelForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class EventLocalizedModelForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Event
|
||||||
|
fields = '__all__'
|
||||||
|
localized_fields = '__all__'
|
||||||
|
|
|
@ -27,7 +27,7 @@ from django.utils import timezone
|
||||||
from django.utils.tzinfo import FixedOffset
|
from django.utils.tzinfo import FixedOffset
|
||||||
from django.utils.unittest import skipIf, skipUnless
|
from django.utils.unittest import skipIf, skipUnless
|
||||||
|
|
||||||
from .forms import EventForm, EventSplitForm, EventModelForm
|
from .forms import EventForm, EventSplitForm, EventLocalizedForm, EventModelForm, EventLocalizedModelForm
|
||||||
from .models import Event, MaybeEvent, Session, SessionEvent, Timestamp, AllDayEvent
|
from .models import Event, MaybeEvent, Session, SessionEvent, Timestamp, AllDayEvent
|
||||||
|
|
||||||
|
|
||||||
|
@ -1036,12 +1036,24 @@ class NewFormsTests(TestCase):
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
||||||
|
|
||||||
|
@requires_tz_support
|
||||||
|
def test_localized_form(self):
|
||||||
|
form = EventLocalizedForm(initial={'dt': datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)})
|
||||||
|
with timezone.override(ICT):
|
||||||
|
self.assertIn("2011-09-01 17:20:30", str(form))
|
||||||
|
|
||||||
@requires_tz_support
|
@requires_tz_support
|
||||||
def test_model_form(self):
|
def test_model_form(self):
|
||||||
EventModelForm({'dt': '2011-09-01 13:20:30'}).save()
|
EventModelForm({'dt': '2011-09-01 13:20:30'}).save()
|
||||||
e = Event.objects.get()
|
e = Event.objects.get()
|
||||||
self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
|
||||||
|
|
||||||
|
@requires_tz_support
|
||||||
|
def test_localized_model_form(self):
|
||||||
|
form = EventLocalizedModelForm(instance=Event(dt=datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)))
|
||||||
|
with timezone.override(ICT):
|
||||||
|
self.assertIn("2011-09-01 17:20:30", str(form))
|
||||||
|
|
||||||
|
|
||||||
@override_settings(DATETIME_FORMAT='c', TIME_ZONE='Africa/Nairobi', USE_L10N=False, USE_TZ=True,
|
@override_settings(DATETIME_FORMAT='c', TIME_ZONE='Africa/Nairobi', USE_L10N=False, USE_TZ=True,
|
||||||
PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
|
|
Loading…
Reference in New Issue