Ticket #14880: ticket_14880_tests_1.2.4.diff

File ticket_14880_tests_1.2.4.diff, 3.1 KB (added by Luke Plant, 14 years ago)

Tests - patch against 1.2.4

  • tests/regressiontests/admin_views/models.py

    diff -r 82628dcefb60 tests/regressiontests/admin_views/models.py
    a b  
    587587class AlbumAdmin(admin.ModelAdmin):
    588588    list_filter = ['title']
    589589
     590class Publisher(models.Model):
     591    name        = models.CharField(max_length=20)
     592    overseas    = models.BooleanField()
     593
     594class PublishedBook(models.Model):
     595    title           = models.CharField(max_length=20)
     596    local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False})
     597
     598class PublishedBookAdmin(admin.ModelAdmin):
     599    raw_id_fields = ['local_publisher',]
     600
     601class PublisherAdmin(admin.ModelAdmin):
     602    list_display = ['name', 'overseas']
     603
    590604admin.site.register(Article, ArticleAdmin)
    591605admin.site.register(CustomArticle, CustomArticleAdmin)
    592606admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    634648admin.site.register(Pizza, PizzaAdmin)
    635649admin.site.register(Topping)
    636650admin.site.register(Album, AlbumAdmin)
     651admin.site.register(PublishedBook, PublishedBookAdmin)
     652admin.site.register(Publisher, PublisherAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff -r 82628dcefb60 tests/regressiontests/admin_views/tests.py
    a b  
    22
    33import re
    44import datetime
     5import urlparse
    56
    67from django.conf import settings
    78from django.core.exceptions import SuspiciousOperation
     
    2829    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    2930    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    3031    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    31     Category, Post, Plot, FunkyTag
     32    Category, Post, Plot, FunkyTag, Publisher
    3233
    3334
    3435class AdminViewBasicTest(TestCase):
     
    21392140        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
    21402141        self.assertEqual(response.status_code, 200)
    21412142
     2143class RawIdFieldsTest(TestCase):
     2144    fixtures = ['admin-views-users.xml']
     2145
     2146    def setUp(self):
     2147        self.client.login(username='super', password='secret')
     2148
     2149    def tearDown(self):
     2150        self.client.logout()
     2151
     2152    def test_limit_choices_to(self):
     2153        """Regression test for 14880"""
     2154        Publisher(name='local-guy', overseas=False).save()
     2155        Publisher(name='overseas-guy', overseas=True).save()
     2156        response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/')
     2157        # Find the link
     2158        m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content)
     2159        self.assertTrue(m) # Got a match
     2160        popup_url = m.groups()[0].replace("&amp;", "&")
     2161
     2162        # Handle relative links
     2163        popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
     2164        # Get the popup
     2165        response2 = self.client.get(popup_url)
     2166        self.assertContains(response2, "local-guy")
     2167        self.assertNotContains(response2, "overseas-guy")
     2168
    21422169class UserAdminTest(TestCase):
    21432170    """
    21442171    Tests user CRUD functionality.
Back to Top