2010-09-12 02:34:40 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
from django import forms
|
2010-10-15 10:35:51 +08:00
|
|
|
from django.conf import settings
|
2009-01-16 23:32:31 +08:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.contrib.admin import widgets
|
2010-11-23 05:55:29 +08:00
|
|
|
from django.contrib.admin.widgets import (FilteredSelectMultiple,
|
|
|
|
AdminSplitDateTime, AdminFileWidget, ForeignKeyRawIdWidget, AdminRadioSelect,
|
2011-04-22 20:03:50 +08:00
|
|
|
RelatedFieldWidgetWrapper, ManyToManyRawIdWidget,
|
|
|
|
url_params_from_lookup_dict)
|
2010-10-15 10:35:51 +08:00
|
|
|
from django.core.files.storage import default_storage
|
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
2009-12-31 06:11:48 +08:00
|
|
|
from django.db.models import DateField
|
2010-10-11 20:55:17 +08:00
|
|
|
from django.test import TestCase as DjangoTestCase
|
2010-10-15 10:35:51 +08:00
|
|
|
from django.utils.html import conditional_escape
|
|
|
|
from django.utils.translation import activate, deactivate
|
2010-10-11 20:55:17 +08:00
|
|
|
from django.utils.unittest import TestCase
|
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
import models
|
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
class AdminFormfieldForDBFieldTests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests for correct behavior of ModelAdmin.formfield_for_dbfield
|
|
|
|
"""
|
|
|
|
|
|
|
|
def assertFormfield(self, model, fieldname, widgetclass, **admin_overrides):
|
|
|
|
"""
|
|
|
|
Helper to call formfield_for_dbfield for a given model and field name
|
|
|
|
and verify that the returned formfield is appropriate.
|
|
|
|
"""
|
|
|
|
# Override any settings on the model admin
|
2010-11-23 05:55:29 +08:00
|
|
|
class MyModelAdmin(admin.ModelAdmin):
|
|
|
|
pass
|
2009-01-16 23:32:31 +08:00
|
|
|
for k in admin_overrides:
|
|
|
|
setattr(MyModelAdmin, k, admin_overrides[k])
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
# Construct the admin, and ask it for a formfield
|
|
|
|
ma = MyModelAdmin(model, admin.site)
|
|
|
|
ff = ma.formfield_for_dbfield(model._meta.get_field(fieldname), request=None)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
# "unwrap" the widget wrapper, if needed
|
|
|
|
if isinstance(ff.widget, widgets.RelatedFieldWidgetWrapper):
|
|
|
|
widget = ff.widget.widget
|
|
|
|
else:
|
|
|
|
widget = ff.widget
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
# Check that we got a field of the right type
|
2011-03-03 23:04:39 +08:00
|
|
|
self.assertTrue(
|
2009-01-17 05:18:21 +08:00
|
|
|
isinstance(widget, widgetclass),
|
2009-01-16 23:32:31 +08:00
|
|
|
"Wrong widget for %s.%s: expected %s, got %s" % \
|
|
|
|
(model.__class__.__name__, fieldname, widgetclass, type(widget))
|
|
|
|
)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
# Return the formfield so that other tests can continue
|
|
|
|
return ff
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testDateField(self):
|
2009-01-17 05:18:21 +08:00
|
|
|
self.assertFormfield(models.Event, 'start_date', widgets.AdminDateWidget)
|
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testDateTimeField(self):
|
|
|
|
self.assertFormfield(models.Member, 'birthdate', widgets.AdminSplitDateTime)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testTimeField(self):
|
|
|
|
self.assertFormfield(models.Event, 'start_time', widgets.AdminTimeWidget)
|
|
|
|
|
|
|
|
def testTextField(self):
|
|
|
|
self.assertFormfield(models.Event, 'description', widgets.AdminTextareaWidget)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testURLField(self):
|
|
|
|
self.assertFormfield(models.Event, 'link', widgets.AdminURLFieldWidget)
|
|
|
|
|
|
|
|
def testIntegerField(self):
|
|
|
|
self.assertFormfield(models.Event, 'min_age', widgets.AdminIntegerFieldWidget)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testCharField(self):
|
|
|
|
self.assertFormfield(models.Member, 'name', widgets.AdminTextInputWidget)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testFileField(self):
|
|
|
|
self.assertFormfield(models.Album, 'cover_art', widgets.AdminFileWidget)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testForeignKey(self):
|
|
|
|
self.assertFormfield(models.Event, 'band', forms.Select)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testRawIDForeignKey(self):
|
|
|
|
self.assertFormfield(models.Event, 'band', widgets.ForeignKeyRawIdWidget,
|
|
|
|
raw_id_fields=['band'])
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testRadioFieldsForeignKey(self):
|
2009-01-17 05:18:21 +08:00
|
|
|
ff = self.assertFormfield(models.Event, 'band', widgets.AdminRadioSelect,
|
2009-01-16 23:32:31 +08:00
|
|
|
radio_fields={'band':admin.VERTICAL})
|
|
|
|
self.assertEqual(ff.empty_label, None)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testManyToMany(self):
|
|
|
|
self.assertFormfield(models.Band, 'members', forms.SelectMultiple)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testRawIDManyTOMany(self):
|
|
|
|
self.assertFormfield(models.Band, 'members', widgets.ManyToManyRawIdWidget,
|
|
|
|
raw_id_fields=['members'])
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testFilteredManyToMany(self):
|
|
|
|
self.assertFormfield(models.Band, 'members', widgets.FilteredSelectMultiple,
|
|
|
|
filter_vertical=['members'])
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testFormfieldOverrides(self):
|
2009-01-17 05:18:21 +08:00
|
|
|
self.assertFormfield(models.Event, 'start_date', forms.TextInput,
|
2009-12-31 06:11:48 +08:00
|
|
|
formfield_overrides={DateField: {'widget': forms.TextInput}})
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testFieldWithChoices(self):
|
|
|
|
self.assertFormfield(models.Member, 'gender', forms.Select)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testChoicesWithRadioFields(self):
|
2009-01-17 05:18:21 +08:00
|
|
|
self.assertFormfield(models.Member, 'gender', widgets.AdminRadioSelect,
|
2009-01-16 23:32:31 +08:00
|
|
|
radio_fields={'gender':admin.VERTICAL})
|
|
|
|
|
2009-04-09 04:25:56 +08:00
|
|
|
def testInheritance(self):
|
|
|
|
self.assertFormfield(models.Album, 'backside_art', widgets.AdminFileWidget)
|
2009-01-16 23:32:31 +08:00
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
|
|
|
|
fixtures = ["admin-widgets-users.xml"]
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
def testFilterChoicesByRequestUser(self):
|
|
|
|
"""
|
|
|
|
Ensure the user can only see their own cars in the foreign key dropdown.
|
|
|
|
"""
|
|
|
|
self.client.login(username="super", password="secret")
|
|
|
|
response = self.client.get("/widget_admin/admin_widgets/cartire/add/")
|
2011-03-03 23:04:39 +08:00
|
|
|
self.assertTrue("BMW M3" not in response.content)
|
|
|
|
self.assertTrue("Volkswagon Passat" in response.content)
|
2009-03-31 07:16:34 +08:00
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
class AdminForeignKeyWidgetChangeList(DjangoTestCase):
|
|
|
|
fixtures = ["admin-widgets-users.xml"]
|
2009-07-23 22:31:33 +08:00
|
|
|
admin_root = '/widget_admin'
|
2009-04-09 04:25:56 +08:00
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
def setUp(self):
|
|
|
|
self.client.login(username="super", password="secret")
|
2009-04-09 04:25:56 +08:00
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
def tearDown(self):
|
|
|
|
self.client.logout()
|
2009-04-09 04:25:56 +08:00
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
def test_changelist_foreignkey(self):
|
2009-07-23 22:31:33 +08:00
|
|
|
response = self.client.get('%s/admin_widgets/car/' % self.admin_root)
|
2010-12-04 15:28:12 +08:00
|
|
|
self.assertTrue('%s/auth/user/add/' % self.admin_root in response.content)
|
2010-03-02 10:28:49 +08:00
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
|
2010-03-02 10:28:49 +08:00
|
|
|
class AdminForeignKeyRawIdWidget(DjangoTestCase):
|
|
|
|
fixtures = ["admin-widgets-users.xml"]
|
|
|
|
admin_root = '/widget_admin'
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client.login(username="super", password="secret")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.client.logout()
|
|
|
|
|
|
|
|
def test_nonexistent_target_id(self):
|
|
|
|
band = models.Band.objects.create(name='Bogey Blues')
|
|
|
|
pk = band.pk
|
|
|
|
band.delete()
|
|
|
|
post_data = {
|
|
|
|
"band": u'%s' % pk,
|
|
|
|
}
|
|
|
|
# Try posting with a non-existent pk in a raw id field: this
|
|
|
|
# should result in an error message, not a server exception.
|
|
|
|
response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root,
|
|
|
|
post_data)
|
|
|
|
self.assertContains(response,
|
|
|
|
'Select a valid choice. That choice is not one of the available choices.')
|
2010-09-12 02:34:40 +08:00
|
|
|
|
|
|
|
def test_invalid_target_id(self):
|
|
|
|
|
|
|
|
for test_str in ('Iñtërnâtiônàlizætiøn', "1234'", -1234):
|
|
|
|
# This should result in an error message, not a server exception.
|
|
|
|
response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root,
|
|
|
|
{"band": test_str})
|
|
|
|
|
|
|
|
self.assertContains(response,
|
|
|
|
'Select a valid choice. That choice is not one of the available choices.')
|
2010-10-15 10:35:51 +08:00
|
|
|
|
2011-04-22 20:03:50 +08:00
|
|
|
def test_url_params_from_lookup_dict_any_iterable(self):
|
|
|
|
lookup1 = url_params_from_lookup_dict({'color__in': ('red', 'blue')})
|
|
|
|
lookup2 = url_params_from_lookup_dict({'color__in': ['red', 'blue']})
|
|
|
|
self.assertEqual(lookup1, {'color__in': 'red,blue'})
|
|
|
|
self.assertEqual(lookup1, lookup2)
|
|
|
|
|
2010-10-15 10:35:51 +08:00
|
|
|
|
|
|
|
class FilteredSelectMultipleWidgetTest(TestCase):
|
|
|
|
def test_render(self):
|
|
|
|
w = FilteredSelectMultiple('test', False)
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', 'test')),
|
|
|
|
'<select multiple="multiple" name="test" class="selectfilter">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 0, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX}
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_stacked_render(self):
|
|
|
|
w = FilteredSelectMultiple('test', True)
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', 'test')),
|
|
|
|
'<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_MEDIA_PREFIX)s"); });</script>\n' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class AdminSplitDateTimeWidgetTest(TestCase):
|
|
|
|
def test_render(self):
|
|
|
|
w = AdminSplitDateTime()
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
|
|
|
|
'<p class="datetime">Date: <input value="2007-12-01" type="text" class="vDateField" name="test_0" size="10" /><br />Time: <input value="09:30:00" type="text" class="vTimeField" name="test_1" size="8" /></p>',
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_localization(self):
|
|
|
|
w = AdminSplitDateTime()
|
|
|
|
|
|
|
|
activate('de-at')
|
|
|
|
old_USE_L10N = settings.USE_L10N
|
2011-02-04 23:45:52 +08:00
|
|
|
try:
|
|
|
|
settings.USE_L10N = True
|
|
|
|
w.is_localized = True
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))),
|
|
|
|
'<p class="datetime">Datum: <input value="01.12.2007" type="text" class="vDateField" name="test_0" size="10" /><br />Zeit: <input value="09:30:00" type="text" class="vTimeField" name="test_1" size="8" /></p>',
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
deactivate()
|
|
|
|
settings.USE_L10N = old_USE_L10N
|
2010-10-15 10:35:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
class AdminFileWidgetTest(DjangoTestCase):
|
|
|
|
def test_render(self):
|
|
|
|
band = models.Band.objects.create(name='Linkin Park')
|
|
|
|
album = band.album_set.create(
|
|
|
|
name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
|
|
|
|
)
|
|
|
|
|
|
|
|
w = AdminFileWidget()
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', album.cover_art)),
|
2011-02-06 04:06:49 +08:00
|
|
|
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <span class="clearable-file-input"><input type="checkbox" name="test-clear" id="test-clear_id" /> <label for="test-clear_id">Clear</label></span><br />Change: <input type="file" name="test" /></p>' % { 'STORAGE_URL': default_storage.url('') },
|
2010-10-15 10:35:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))),
|
|
|
|
'<input type="file" name="test" />',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ForeignKeyRawIdWidgetTest(DjangoTestCase):
|
|
|
|
def test_render(self):
|
|
|
|
band = models.Band.objects.create(name='Linkin Park')
|
|
|
|
band.album_set.create(
|
|
|
|
name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
|
|
|
|
)
|
|
|
|
rel = models.Album._meta.get_field('band').rel
|
|
|
|
|
|
|
|
w = ForeignKeyRawIdWidget(rel)
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', band.pk, attrs={})),
|
|
|
|
'<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Linkin Park</strong>' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX, "bandpk": band.pk},
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_relations_to_non_primary_key(self):
|
|
|
|
# Check that ForeignKeyRawIdWidget works with fields which aren't
|
|
|
|
# related to the model's primary key.
|
|
|
|
apple = models.Inventory.objects.create(barcode=86, name='Apple')
|
|
|
|
models.Inventory.objects.create(barcode=22, name='Pear')
|
|
|
|
core = models.Inventory.objects.create(
|
|
|
|
barcode=87, name='Core', parent=apple
|
|
|
|
)
|
|
|
|
rel = models.Inventory._meta.get_field('parent').rel
|
|
|
|
w = ForeignKeyRawIdWidget(rel)
|
|
|
|
self.assertEqual(
|
|
|
|
w.render('test', core.parent_id, attrs={}),
|
|
|
|
'<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Apple</strong>' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_proper_manager_for_label_lookup(self):
|
|
|
|
# see #9258
|
|
|
|
rel = models.Inventory._meta.get_field('parent').rel
|
|
|
|
w = ForeignKeyRawIdWidget(rel)
|
|
|
|
|
|
|
|
hidden = models.Inventory.objects.create(
|
|
|
|
barcode=93, name='Hidden', hidden=True
|
|
|
|
)
|
|
|
|
child_of_hidden = models.Inventory.objects.create(
|
|
|
|
barcode=94, name='Child of hidden', parent=hidden
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
w.render('test', child_of_hidden.parent_id, attrs={}),
|
|
|
|
'<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Hidden</strong>' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ManyToManyRawIdWidgetTest(DjangoTestCase):
|
|
|
|
def test_render(self):
|
|
|
|
band = models.Band.objects.create(name='Linkin Park')
|
|
|
|
band.album_set.create(
|
|
|
|
name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
|
|
|
|
)
|
|
|
|
|
|
|
|
m1 = models.Member.objects.create(name='Chester')
|
|
|
|
m2 = models.Member.objects.create(name='Mike')
|
|
|
|
band.members.add(m1, m2)
|
|
|
|
rel = models.Band._meta.get_field('members').rel
|
|
|
|
|
|
|
|
w = ManyToManyRawIdWidget(rel)
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={})),
|
|
|
|
'<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="../../../admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX, "m1pk": m1.pk, "m2pk": m2.pk},
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
conditional_escape(w.render('test', [m1.pk])),
|
|
|
|
'<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="../../../admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % {"ADMIN_MEDIA_PREFIX": settings.ADMIN_MEDIA_PREFIX, "m1pk": m1.pk},
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(w._has_changed(None, None), False)
|
|
|
|
self.assertEqual(w._has_changed([], None), False)
|
|
|
|
self.assertEqual(w._has_changed(None, [u'1']), True)
|
|
|
|
self.assertEqual(w._has_changed([1, 2], [u'1', u'2']), False)
|
|
|
|
self.assertEqual(w._has_changed([1, 2], [u'1']), True)
|
|
|
|
self.assertEqual(w._has_changed([1, 2], [u'1', u'3']), True)
|
2010-11-23 05:55:29 +08:00
|
|
|
|
|
|
|
class RelatedFieldWidgetWrapperTests(DjangoTestCase):
|
|
|
|
def test_no_can_add_related(self):
|
|
|
|
rel = models.Inventory._meta.get_field('parent').rel
|
|
|
|
w = AdminRadioSelect()
|
|
|
|
# Used to fail with a name error.
|
|
|
|
w = RelatedFieldWidgetWrapper(w, rel, admin.site)
|
|
|
|
self.assertFalse(w.can_add_related)
|