Source

django / tests / regressiontests / admin_widgets / tests.py

The default branch has multiple heads

Diff from to

tests/regressiontests/admin_widgets/tests.py

 
         widget_settings = {
             'fields': ('name',),
-            'id': 'pk',
+            'id': 'id',
             'limit': 5,
             'value': lambda o: unicode(o),
             'label': lambda o: unicode(o),
         )
         self.bands = (band, band2)
     
-    def _get_expected(self, name, bands):
+    def _get_expected(self, name, bands, show_search=False):
         bands = [] if bands is None else bands
         expected = [
             '<input type="hidden" name="%(field_name)s" value="%(band_pks)s" id="id_hidden_%(field_name)s" />',
             '<input type="text" value="" />',  # input is for data entry only
             ]
+        if show_search:
+            expected.append('<a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % (name, settings.ADMIN_MEDIA_PREFIX))
         if bands:                
                 expected += ['<ul class="ui-autocomplete-values">']
                 expected += ['<li>%s</li>' % b.name for b in bands]
 
         widget_settings = {
             'fields': ('name',),
-            'id': 'pk',
+            'id': 'id',
             'limit': 5,
             'value': lambda o: unicode(o),
             'label': lambda o: unicode(o),
             'queryset': models.Band.objects.all(),
+            'show_search': False,
             }
+        with_search_settings = widget_settings.copy()
+        with_search_settings['show_search'] = True
 
         w = MultipleAutocompleteWidget(widget_settings)
         expected_multiple = self._get_expected('test_multiple', bands)
             expected_none,
         )
 
+        w = MultipleAutocompleteWidget(with_search_settings)
+        bands_none = None
+        expected_none = self._get_expected('test_none', bands_none, True)
+        self.assertEqual(
+            conditional_escape(w.render('test_none', bands_none, attrs={})),
+            expected_none,
+        )
+        
 
     def test_autocomplete_lookup(self):
         band = self.bands[1]