mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-05-04 13:34:47 +00:00
Pretty simple tests for this one.
This commit is contained in:
parent
1aa4ee36d6
commit
9e29500f5c
2 changed files with 37 additions and 4 deletions
|
|
@ -35,7 +35,7 @@ class PostAdmin(djadmin2.ModelAdmin2):
|
|||
}
|
||||
save_on_top = True
|
||||
date_hierarchy = "published_date"
|
||||
ordering = ["published_date", "title",]
|
||||
ordering = ["-published_date", "title",]
|
||||
|
||||
|
||||
class CommentAdmin(djadmin2.ModelAdmin2):
|
||||
|
|
|
|||
|
|
@ -99,7 +99,16 @@ class PostListTest(BaseIntegrationTest):
|
|||
day=20,
|
||||
year=2012,
|
||||
)
|
||||
)
|
||||
),
|
||||
Post(
|
||||
title="post_5_title",
|
||||
body="body",
|
||||
published_date=datetime(
|
||||
month=6,
|
||||
day=20,
|
||||
year=2012,
|
||||
)
|
||||
),
|
||||
])
|
||||
|
||||
def test_view_ok(self):
|
||||
|
|
@ -182,7 +191,7 @@ class PostListTest(BaseIntegrationTest):
|
|||
|
||||
response = self.client.get(reverse('admin2:blog_post_index'))
|
||||
self.assertContains(response, '<a href="?year=2012">2012</a>')
|
||||
self.assertContains(response, "<tr>", 4)
|
||||
self.assertContains(response, "<tr>", 5)
|
||||
|
||||
response = self.client.get(
|
||||
"%s?%s" % (
|
||||
|
|
@ -199,7 +208,7 @@ class PostListTest(BaseIntegrationTest):
|
|||
response,
|
||||
'All dates',
|
||||
)
|
||||
self.assertContains(response, "<tr>", 3)
|
||||
self.assertContains(response, "<tr>", 4)
|
||||
|
||||
response = self.client.get(
|
||||
"%s?%s" % (
|
||||
|
|
@ -236,6 +245,30 @@ class PostListTest(BaseIntegrationTest):
|
|||
'May 2012'
|
||||
)
|
||||
|
||||
def test_ordering(self):
|
||||
self._create_posts()
|
||||
|
||||
response = self.client.get(reverse("admin2:blog_post_index"))
|
||||
|
||||
model_admin = response.context["view"].model_admin
|
||||
response_queryset = response.context["object_list"]
|
||||
manual_queryset = Post.objects.order_by("-published_date", "title")
|
||||
|
||||
zipped_queryset = zip(
|
||||
list(response_queryset),
|
||||
list(manual_queryset),
|
||||
)
|
||||
|
||||
self.assertTrue(all([
|
||||
model1.pk == model2.pk
|
||||
for model1, model2 in zipped_queryset
|
||||
]))
|
||||
|
||||
self.assertEqual(
|
||||
model_admin.get_ordering(response.request),
|
||||
model_admin.ordering,
|
||||
)
|
||||
|
||||
|
||||
class PostListTestCustomAction(BaseIntegrationTest):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue