Ticket #14880: ticket_14880_tests_1.2.X.diff

File ticket_14880_tests_1.2.X.diff, 3.2 KB (added by Luke Plant, 14 years ago)

Tests - patch against 1.2.X

  • tests/regressiontests/admin_views/models.py

    diff -r f53e259a7214 tests/regressiontests/admin_views/models.py
    a b  
    599599    list_display = ('datum', 'employee')
    600600    list_filter = ('employee',)
    601601
     602class Publisher(models.Model):
     603    name        = models.CharField(max_length=20)
     604    overseas    = models.BooleanField()
     605
     606class PublishedBook(models.Model):
     607    title           = models.CharField(max_length=20)
     608    local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False})
     609
     610class PublishedBookAdmin(admin.ModelAdmin):
     611    raw_id_fields = ['local_publisher',]
     612
     613class PublisherAdmin(admin.ModelAdmin):
     614    list_display = ['name', 'overseas']
     615
    602616admin.site.register(Article, ArticleAdmin)
    603617admin.site.register(CustomArticle, CustomArticleAdmin)
    604618admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    647661admin.site.register(Pizza, PizzaAdmin)
    648662admin.site.register(Topping)
    649663admin.site.register(Album, AlbumAdmin)
     664admin.site.register(PublishedBook, PublishedBookAdmin)
     665admin.site.register(Publisher, PublisherAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff -r f53e259a7214 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, WorkHour, Employee
     32    Category, Post, Plot, FunkyTag, WorkHour, Employee, Publisher
    3233
    3334
    3435class AdminViewBasicTest(TestCase):
     
    21542155        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
    21552156        self.assertEqual(response.status_code, 200)
    21562157
     2158class RawIdFieldsTest(TestCase):
     2159    fixtures = ['admin-views-users.xml']
     2160
     2161    def setUp(self):
     2162        self.client.login(username='super', password='secret')
     2163
     2164    def tearDown(self):
     2165        self.client.logout()
     2166
     2167    def test_limit_choices_to(self):
     2168        """Regression test for 14880"""
     2169        Publisher(name='local-guy', overseas=False).save()
     2170        Publisher(name='overseas-guy', overseas=True).save()
     2171        response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/')
     2172        # Find the link
     2173        m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content)
     2174        self.assertTrue(m) # Got a match
     2175        popup_url = m.groups()[0].replace("&amp;", "&")
     2176
     2177        # Handle relative links
     2178        popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
     2179        # Get the popup
     2180        response2 = self.client.get(popup_url)
     2181        self.assertContains(response2, "local-guy")
     2182        self.assertNotContains(response2, "overseas-guy")
     2183
    21572184class UserAdminTest(TestCase):
    21582185    """
    21592186    Tests user CRUD functionality.
Back to Top