diff options
| author | Thomas Chaumeny <thomas.chaumeny@polyconseil.fr> | 2014-09-22 18:46:43 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-09-26 12:12:40 -0400 |
| commit | 17557d068c43bd61cdc6c18caf250ffa469414a1 (patch) | |
| tree | f404b1f0c5f03bcdb14d39282ed6ec686085909a /tests/admin_views | |
| parent | d1ca70110f49f0be90206c8da516ac16aebc8c75 (diff) | |
Fixed #8408 -- Added ModelAdmin.show_full_result_count to avoid COUNT() query.
Thanks lidaobing for the suggestion.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/admin.py | 1 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 19 |
2 files changed, 19 insertions, 1 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 077d64b50d..7caca29c7b 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -327,6 +327,7 @@ class LanguageAdmin(admin.ModelAdmin): class RecommendationAdmin(admin.ModelAdmin): + show_full_result_count = False search_fields = ('=titletranslation__text', '=recommender__titletranslation__text',) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index c9b946ac5e..88539d4684 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -2474,11 +2474,28 @@ class AdminSearchTest(TestCase): """ Test presence of reset link in search bar ("1 result (_x total_)"). """ - response = self.client.get('/test_admin/admin/admin_views/person/?q=Gui') + # 1 query for session + 1 for fetching user + # + 1 for filtered result + 1 for filtered count + # + 1 for total count + with self.assertNumQueries(5): + response = self.client.get('/test_admin/admin/admin_views/person/?q=Gui') self.assertContains(response, """<span class="small quiet">1 result (<a href="?">3 total</a>)</span>""", html=True) + def test_no_total_count(self): + """ + #8408 -- "Show all" should be displayed instead of the total count if + ModelAdmin.show_full_result_count is False. + """ + # 1 query for session + 1 for fetching user + # + 1 for filtered result + 1 for filtered count + with self.assertNumQueries(4): + response = self.client.get('/test_admin/admin/admin_views/recommendation/?q=bar') + self.assertContains(response, + """<span class="small quiet">1 result (<a href="?">Show all</a>)</span>""", + html=True) + @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), ROOT_URLCONF="admin_views.urls") |
