Ticket #11028: test11028.diff

File test11028.diff, 2.2 KB (added by albertoconnor, 10 years ago)

Patch to add a negative test case for bisecting

  • new file tests/b11028/admin.py

    diff --git a/tests/b11028/__init__.py b/tests/b11028/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/b11028/admin.py b/tests/b11028/admin.py
    new file mode 100644
    index 0000000..20b79d3
    - +  
     1from django.contrib import admin
     2
     3
     4from .models import Book
     5
     6class BookAdmin(admin.ModelAdmin):
     7    search_fields = ('authors__name',)
     8
     9admin.site.register(Book, BookAdmin)
  • new file tests/b11028/models.py

    diff --git a/tests/b11028/models.py b/tests/b11028/models.py
    new file mode 100644
    index 0000000..aff5e02
    - +  
     1from django.db import models
     2
     3
     4class Author(models.Model):
     5    name = models.CharField(max_length=256)
     6
     7class Book(models.Model):
     8    authors = models.ManyToManyField(Author)
  • new file tests/b11028/tests.py

    diff --git a/tests/b11028/tests.py b/tests/b11028/tests.py
    new file mode 100644
    index 0000000..17fc8c1
    - +  
     1from django.contrib import admin
     2from django.contrib.admin.views.main import ALL_VAR, SEARCH_VAR, ChangeList
     3from django.test import TestCase
     4from django.test.client import RequestFactory
     5
     6from .models import Author, Book
     7from .admin import BookAdmin
     8
     9
     10class 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
Back to Top