summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
diff options
context:
space:
mode:
authorAnton Samarchyan <anton.samarchyan@savoirfairelinux.com>2017-02-24 10:22:25 -0500
committerTim Graham <timograham@gmail.com>2017-03-06 12:01:31 -0500
commite88d2dfcf4daa2b4ee451f518085413bb3b8deeb (patch)
treeb3b77ca9cd8262c674aa64b6a1d2c4ea6330b48b /tests/admin_views/tests.py
parent8346680e1ca4a8ddc8190baf3f5f944f6418d5cf (diff)
Fixed #27475 -- Fixed NonExistentTimeError crash in ModelAdmin.date_hierarchy.
Diffstat (limited to 'tests/admin_views/tests.py')
-rw-r--r--tests/admin_views/tests.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index e36dfa3141..a113e29377 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -5,6 +5,8 @@ import re
import unittest
from urllib.parse import parse_qsl, urljoin, urlparse
+import pytz
+
from django.contrib.admin import AdminSite, ModelAdmin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import ADDITION, DELETION, LogEntry
@@ -42,15 +44,16 @@ from .admin import CityAdmin, site, site2
from .forms import MediaActionForm
from .models import (
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
- AdminOrderedModelMethod, Answer, Article, BarAccount, Book, Bookmark,
- Category, Chapter, ChapterXtra1, ChapterXtra2, Character, Child, Choice,
- City, Collector, Color, ComplexSortedPerson, CoverLetter, CustomArticle,
- CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel, ExternalSubscriber,
- Fabric, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
- FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link,
- MainPrepopulated, Media, ModelWithStringPrimaryKey, OtherStory, Paper,
- Parent, ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona,
- Picture, Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post,
+ AdminOrderedModelMethod, Answer, Answer2, Article, BarAccount, Book,
+ Bookmark, Category, Chapter, ChapterXtra1, ChapterXtra2, Character, Child,
+ Choice, City, Collector, Color, ComplexSortedPerson, CoverLetter,
+ CustomArticle, CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel,
+ ExternalSubscriber, Fabric, FancyDoodad, FieldOverridePost,
+ FilteredManager, FooAccount, FoodDelivery, FunkyTag, Gallery, Grommet,
+ Inquisition, Language, Link, MainPrepopulated, Media,
+ ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
+ ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, Picture,
+ Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post,
PrePopulatedPost, Promo, Question, Recommendation, Recommender,
RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Restaurant,
RowLevelChangePermissionModel, SecretHideout, Section, ShortMessage,
@@ -918,6 +921,18 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
self.assertEqual(response.context['site_url'], '/my-site-url/')
self.assertContains(response, '<a href="/my-site-url/">View site</a>')
+ @override_settings(TIME_ZONE='America/Sao_Paulo', USE_TZ=True)
+ def test_date_hierarchy_timezone_dst(self):
+ # This datetime doesn't exist in this timezone due to DST.
+ date = pytz.timezone('America/Sao_Paulo').localize(datetime.datetime(2016, 10, 16, 15), is_dst=None)
+ q = Question.objects.create(question='Why?', expires=date)
+ Answer2.objects.create(question=q, answer='Because.')
+ response = self.client.get(reverse('admin:admin_views_answer2_changelist'))
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, 'question__expires__day=16')
+ self.assertContains(response, 'question__expires__month=10')
+ self.assertContains(response, 'question__expires__year=2016')
+
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',