| 239 | |
| 240 | |
| 241 | class MockRequest(object): |
| 242 | pass |
| 243 | |
| 244 | |
| 245 | class AnotherArticleAdmin(admin.ModelAdmin): |
| 246 | list_display = ['title', 'created'] |
| 247 | date_hierarchy = 'created' |
| 248 | |
| 249 | |
| 250 | class DateHierarchyTestCase(TestCase): |
| 251 | fixtures = ['admin_util_anotherarticles.json'] |
| 252 | |
| 253 | def test_nullable_date_hierarchy(self): |
| 254 | """ |
| 255 | Tests to ensure that the ``date_hierarchy`` tag doesn't blow up on |
| 256 | nullable dates. |
| 257 | """ |
| 258 | mock_admin = AnotherArticleAdmin(AnotherArticle, None) |
| 259 | mock_request = MockRequest() |
| 260 | |
| 261 | mock_request.GET = {} |
| 262 | |
| 263 | cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin) |
| 264 | self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__year=2010', 'title': '2010'}, {'link': '?created__year=2011', 'title': '2011'}], 'show': True}) |
| 265 | |
| 266 | mock_request.GET = {'created__year': '2010'} |
| 267 | cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin) |
| 268 | self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__year=2010&created__month=1', 'title': u'January 2010'}, {'link': '?created__year=2010&created__month=10', 'title': u'October 2010'}], 'back': {'link': '?', 'title': u'All dates'}, 'show': True}) |
| 269 | |
| 270 | mock_request.GET = {'created__year': '2010', 'created__month': '10'} |
| 271 | cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin) |
| 272 | self.assertEqual(date_hierarchy(cl), {'choices': [{'link': '?created__day=12&created__year=2010&created__month=10', 'title': u'October 12'}, {'link': '?created__day=13&created__year=2010&created__month=10', 'title': u'October 13'}], 'back': {'link': '?created__year=2010', 'title': '2010'}, 'show': True}) |
| 273 | |
| 274 | mock_request.GET = {'created__year': '2010', 'created__month': '10', 'created__day': '13'} |
| 275 | cl = ChangeList(mock_request, AnotherArticle, mock_admin.list_display, mock_admin.list_filter, [], mock_admin.date_hierarchy, [], None, 50, False, mock_admin) |
| 276 | self.assertEqual(date_hierarchy(cl), {'choices': [{'title': u'October 13'}], 'back': {'link': '?created__year=2010&created__month=10', 'title': u'October 2010'}, 'show': True}) |