| 1 | from django.contrib import admin |
| 2 | from django.contrib.admin.views.main import ALL_VAR, SEARCH_VAR, ChangeList |
| 3 | from django.test import TestCase |
| 4 | from django.test.client import RequestFactory |
| 5 | |
| 6 | from .models import Author, Book |
| 7 | from .admin import BookAdmin |
| 8 | |
| 9 | |
| 10 | class ChangeListTests(TestCase): |
| 11 | urls = "regressiontests.admin_changelist.urls" |
| 12 | def setUp(self): |
| 13 | self.factory = RequestFactory() |
| 14 | |
| 15 | def test_b11028(self): |
| 16 | """ |
| 17 | Negative bisect test for #11028: Searching in the admin across a Many2Many |
| 18 | relationship generated a ProgrammingError. |
| 19 | |
| 20 | NOTE: soft linking this test into a regressiontests directory is required |
| 21 | """ |
| 22 | author = Author.objects.create(name='Mary') |
| 23 | book = Book.objects.create() |
| 24 | book.authors.add(author) |
| 25 | |
| 26 | m = BookAdmin(Book, admin.site) |
| 27 | request = self.factory.get('/book/', data={SEARCH_VAR: 'Mary'}) |
| 28 | |
| 29 | with self.assertRaises(Exception): |
| 30 | cl = ChangeList(request, Book, m.list_display, m.list_display_links, |
| 31 | m.list_filter, m.date_hierarchy, m.search_fields, |
| 32 | m.list_select_related, m.list_per_page, |
| 33 | m.list_max_show_all, m.list_editable, m) |
| 34 | |