Ticket #14880: ticket_14880_tests_trunk.diff

File ticket_14880_tests_trunk.diff, 3.2 KB (added by lukeplant, 5 years ago)

Tests - patch against trunk

  • tests/regressiontests/admin_views/models.py

    diff -r 60a71b474c6f tests/regressiontests/admin_views/models.py
    a b  
    626626    list_display = ('datum', 'employee')
    627627    list_filter = ('employee',)
    628628
     629class Publisher(models.Model):
     630    name        = models.CharField(max_length=20)
     631    overseas    = models.BooleanField()
     632
     633class PublishedBook(models.Model):
     634    title           = models.CharField(max_length=20)
     635    local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False})
     636
     637class PublishedBookAdmin(admin.ModelAdmin):
     638    raw_id_fields = ['local_publisher',]
     639
     640class PublisherAdmin(admin.ModelAdmin):
     641    list_display = ['name', 'overseas']
     642
    629643admin.site.register(Article, ArticleAdmin)
    630644admin.site.register(CustomArticle, CustomArticleAdmin)
    631645admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    674688admin.site.register(Pizza, PizzaAdmin)
    675689admin.site.register(Topping)
    676690admin.site.register(Album, AlbumAdmin)
     691admin.site.register(PublishedBook, PublishedBookAdmin)
     692admin.site.register(Publisher, PublisherAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff -r 60a71b474c6f tests/regressiontests/admin_views/tests.py
    a b  
    22
    33import re
    44import datetime
     5import urlparse
    56
    67from django.conf import settings
    78from django.core import mail
     
    3334    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    3435    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    3536    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    36     Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee
     37    Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, \
     38    Publisher
    3739
    3840
    3941class AdminViewBasicTest(TestCase):
     
    23072309        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
    23082310        self.assertEqual(response.status_code, 200)
    23092311
     2312class RawIdFieldsTest(TestCase):
     2313    fixtures = ['admin-views-users.xml']
     2314
     2315    def setUp(self):
     2316        self.client.login(username='super', password='secret')
     2317
     2318    def tearDown(self):
     2319        self.client.logout()
     2320
     2321    def test_limit_choices_to(self):
     2322        """Regression test for 14880"""
     2323        Publisher(name='local-guy', overseas=False).save()
     2324        Publisher(name='overseas-guy', overseas=True).save()
     2325        response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/')
     2326        # Find the link
     2327        m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content)
     2328        self.assertTrue(m) # Got a match
     2329        popup_url = m.groups()[0].replace("&amp;", "&")
     2330
     2331        # Handle relative links
     2332        popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
     2333        # Get the popup
     2334        response2 = self.client.get(popup_url)
     2335        self.assertContains(response2, "local-guy")
     2336        self.assertNotContains(response2, "overseas-guy")
     2337
    23102338class UserAdminTest(TestCase):
    23112339    """
    23122340    Tests user CRUD functionality.
Back to Top