Code

Ticket #14880: ticket_14880_tests_trunk.diff

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

Tests - patch against trunk

Line 
1diff -r 60a71b474c6f tests/regressiontests/admin_views/models.py
2--- a/tests/regressiontests/admin_views/models.py       Wed Jan 12 23:30:47 2011 +0000
3+++ b/tests/regressiontests/admin_views/models.py       Thu Jan 13 01:59:34 2011 +0000
4@@ -626,6 +626,20 @@
5     list_display = ('datum', 'employee')
6     list_filter = ('employee',)
7 
8+class Publisher(models.Model):
9+    name        = models.CharField(max_length=20)
10+    overseas    = models.BooleanField()
11+
12+class PublishedBook(models.Model):
13+    title           = models.CharField(max_length=20)
14+    local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False})
15+
16+class PublishedBookAdmin(admin.ModelAdmin):
17+    raw_id_fields = ['local_publisher',]
18+
19+class PublisherAdmin(admin.ModelAdmin):
20+    list_display = ['name', 'overseas']
21+
22 admin.site.register(Article, ArticleAdmin)
23 admin.site.register(CustomArticle, CustomArticleAdmin)
24 admin.site.register(Section, save_as=True, inlines=[ArticleInline])
25@@ -674,3 +688,5 @@
26 admin.site.register(Pizza, PizzaAdmin)
27 admin.site.register(Topping)
28 admin.site.register(Album, AlbumAdmin)
29+admin.site.register(PublishedBook, PublishedBookAdmin)
30+admin.site.register(Publisher, PublisherAdmin)
31diff -r 60a71b474c6f tests/regressiontests/admin_views/tests.py
32--- a/tests/regressiontests/admin_views/tests.py        Wed Jan 12 23:30:47 2011 +0000
33+++ b/tests/regressiontests/admin_views/tests.py        Thu Jan 13 01:59:34 2011 +0000
34@@ -2,6 +2,7 @@
35 
36 import re
37 import datetime
38+import urlparse
39 
40 from django.conf import settings
41 from django.core import mail
42@@ -33,7 +34,8 @@
43     FooAccount, Gallery, ModelWithStringPrimaryKey, \
44     Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
45     Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
46-    Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee
47+    Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, \
48+    Publisher
49 
50 
51 class AdminViewBasicTest(TestCase):
52@@ -2307,6 +2309,32 @@
53         response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
54         self.assertEqual(response.status_code, 200)
55 
56+class RawIdFieldsTest(TestCase):
57+    fixtures = ['admin-views-users.xml']
58+
59+    def setUp(self):
60+        self.client.login(username='super', password='secret')
61+
62+    def tearDown(self):
63+        self.client.logout()
64+
65+    def test_limit_choices_to(self):
66+        """Regression test for 14880"""
67+        Publisher(name='local-guy', overseas=False).save()
68+        Publisher(name='overseas-guy', overseas=True).save()
69+        response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/')
70+        # Find the link
71+        m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content)
72+        self.assertTrue(m) # Got a match
73+        popup_url = m.groups()[0].replace("&amp;", "&")
74+
75+        # Handle relative links
76+        popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
77+        # Get the popup
78+        response2 = self.client.get(popup_url)
79+        self.assertContains(response2, "local-guy")
80+        self.assertNotContains(response2, "overseas-guy")
81+
82 class UserAdminTest(TestCase):
83     """
84     Tests user CRUD functionality.