Ticket #14880: ticket_14880_tests_1.2.3.diff

File ticket_14880_tests_1.2.3.diff, 3.2 KB (added by lukeplant, 4 years ago)

Tests - patch against 1.2.3

  • tests/regressiontests/admin_views/models.py

    diff -r 07edcd36e455 tests/regressiontests/admin_views/models.py
    a b  
    584584    owner = models.ForeignKey(User)
    585585    title = models.CharField(max_length=30)
    586586
     587class Publisher(models.Model):
     588    name        = models.CharField(max_length=20)
     589    overseas    = models.BooleanField()
     590
     591class PublishedBook(models.Model):
     592    title           = models.CharField(max_length=20)
     593    local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False})
     594
     595class PublishedBookAdmin(admin.ModelAdmin):
     596    raw_id_fields = ['local_publisher',]
     597
     598class PublisherAdmin(admin.ModelAdmin):
     599    list_display = ['name', 'overseas']
     600
    587601admin.site.register(Article, ArticleAdmin)
    588602admin.site.register(CustomArticle, CustomArticleAdmin)
    589603admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    631645admin.site.register(Pizza, PizzaAdmin)
    632646admin.site.register(Topping)
    633647admin.site.register(Album)
     648admin.site.register(PublishedBook, PublishedBookAdmin)
     649admin.site.register(Publisher, PublisherAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff -r 07edcd36e455 tests/regressiontests/admin_views/tests.py
    a b  
    22
    33import re
    44import datetime
     5import urlparse
    56from django.conf import settings
    67from django.core.files import temp as tempfile
    78from django.contrib.auth import admin # Register auth models with the admin.
     
    2425    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    2526    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    2627    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    27     Category, Post, Plot, FunkyTag
     28    Category, Post, Plot, FunkyTag, Publisher
    2829
    2930
    3031class AdminViewBasicTest(TestCase):
     
    21282129        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
    21292130        self.assertEqual(response.status_code, 200)
    21302131
     2132class RawIdFieldsTest(TestCase):
     2133    fixtures = ['admin-views-users.xml']
     2134
     2135    def setUp(self):
     2136        self.client.login(username='super', password='secret')
     2137
     2138    def tearDown(self):
     2139        self.client.logout()
     2140
     2141    def test_limit_choices_to(self):
     2142        """Regression test for 14880"""
     2143        Publisher(name='local-guy', overseas=False).save()
     2144        Publisher(name='overseas-guy', overseas=True).save()
     2145        response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/')
     2146        # Find the link
     2147        m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content)
     2148        self.assertTrue(m) # Got a match
     2149        popup_url = m.groups()[0].replace("&amp;", "&")
     2150
     2151        # Handle relative links
     2152        popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
     2153        # Get the popup
     2154        response2 = self.client.get(popup_url)
     2155        self.assertContains(response2, "local-guy")
     2156        self.assertNotContains(response2, "overseas-guy")
     2157
    21312158class UserAdminTest(TestCase):
    21322159    """
    21332160    Tests user CRUD functionality.
Back to Top