Source

django / tests / regressiontests / admin_widgets / tests.py

The default branch has multiple heads

Diff from to

tests/regressiontests/admin_widgets/tests.py

         )
         
 
-    def test_autocomplete_lookup(self):
+    def test_lookup(self):
         band = self.bands[1]
         self.client.login(username="super", password="secret")
         response = self.client.get('%s/admin_widgets/album/autocomplete/band/?term=johnny' % self.admin_root )
                            'value': band.name,
                            'label': band.name}])
         
+
+    def test_different_id(self):
+        self.client.login(username="super", password="secret")
+        user = models.User.objects.get(username='testser')
+        user.member_set.create(
+            name='Man Named Sue',
+            user=user,
+        )
+        expected = [{'id': user.email, 
+                     'value': user.username,
+                     'label': user.username}]
+        lookup_url = "%s/admin_widgets/member/autocomplete/user/?term=%%s" % self.admin_root
+        lookup_by_id_url = "%s&by_id=1" % lookup_url
+
+        response = self.client.get(lookup_url % user.username[:2])
+        self.assertEqual(simplejson.loads(response.content),
+                         expected)
+        response = self.client.get(lookup_url % user.email[:2])
+        self.assertEqual(simplejson.loads(response.content),
+                         expected)
+        response = self.client.get(lookup_url % user.first_name[:2])
+        self.assertEqual(simplejson.loads(response.content),
+                         expected)
+        response = self.client.get(lookup_by_id_url % user.email)
+        self.assertEqual(simplejson.loads(response.content),
+                         expected)
+