MCPcopy
hub / github.com/django/django / test_dynamic_ordering

Method test_dynamic_ordering

tests/admin_ordering/tests.py:83–96  ·  view source on GitHub ↗

Let's use a custom ModelAdmin that changes the ordering dynamically.

(self)

Source from the content-addressed store, hash-verified

81 self.assertEqual(["Aerosmith", "Van Halen", "Radiohead"], names)
82
83 def test_dynamic_ordering(self):
84 """
85 Let's use a custom ModelAdmin that changes the ordering dynamically.
86 """
87 super_user = User.objects.create(username="admin", is_superuser=True)
88 other_user = User.objects.create(username="other")
89 request = self.request_factory.get("/")
90 request.user = super_user
91 ma = DynOrderingBandAdmin(Band, site)
92 names = [b.name for b in ma.get_queryset(request)]
93 self.assertEqual(["Radiohead", "Van Halen", "Aerosmith"], names)
94 request.user = other_user
95 names = [b.name for b in ma.get_queryset(request)]
96 self.assertEqual(["Aerosmith", "Radiohead", "Van Halen"], names)
97
98
99class TestInlineModelAdminOrdering(TestCase):

Callers

nothing calls this directly

Calls 4

createMethod · 0.45
getMethod · 0.45
get_querysetMethod · 0.45

Tested by

no test coverage detected