Converted the modeladmin tests to run on python 2 and 3.
This commit is contained in:
parent
54afdbf378
commit
cca01c96d1
|
@ -5,7 +5,7 @@ from datetime import date
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.options import (ModelAdmin, TabularInline,
|
||||
InlineModelAdmin, HORIZONTAL, VERTICAL)
|
||||
HORIZONTAL, VERTICAL)
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.contrib.admin.validation import validate
|
||||
from django.contrib.admin.widgets import AdminDateWidget, AdminRadioSelect
|
||||
|
@ -15,7 +15,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.forms.models import BaseModelFormSet
|
||||
from django.forms.widgets import Select
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings, str_prefix
|
||||
from django.test.utils import str_prefix
|
||||
from django.utils import unittest
|
||||
|
||||
from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
|
||||
|
@ -24,6 +24,7 @@ from .models import Band, Concert, ValidationTestModel, ValidationTestInlineMode
|
|||
class MockRequest(object):
|
||||
pass
|
||||
|
||||
|
||||
class MockSuperUser(object):
|
||||
def has_perm(self, perm):
|
||||
return True
|
||||
|
@ -47,7 +48,7 @@ class ModelAdminTests(TestCase):
|
|||
def test_default_fields(self):
|
||||
ma = ModelAdmin(Band, self.site)
|
||||
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name', 'bio', 'sign_date'])
|
||||
|
||||
def test_default_fieldsets(self):
|
||||
|
@ -72,7 +73,7 @@ class ModelAdminTests(TestCase):
|
|||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
|
||||
self.assertEqual( ma.get_fieldsets(request),
|
||||
self.assertEqual(ma.get_fieldsets(request),
|
||||
[(None, {'fields': ['name']})])
|
||||
|
||||
self.assertEqual(ma.get_fieldsets(request, self.band),
|
||||
|
@ -90,8 +91,8 @@ class ModelAdminTests(TestCase):
|
|||
fields = ['name']
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(), ['name'])
|
||||
self.assertEqual(ma.get_form(request, self.band).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields), ['name'])
|
||||
self.assertEqual(list(ma.get_form(request, self.band).base_fields),
|
||||
['name'])
|
||||
|
||||
# Using `fieldsets`.
|
||||
|
@ -99,8 +100,8 @@ class ModelAdminTests(TestCase):
|
|||
fieldsets = [(None, {'fields': ['name']})]
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(), ['name'])
|
||||
self.assertEqual(ma.get_form(request, self.band).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields), ['name'])
|
||||
self.assertEqual(list(ma.get_form(request, self.band).base_fields),
|
||||
['name'])
|
||||
|
||||
# Using `exclude`.
|
||||
|
@ -108,7 +109,7 @@ class ModelAdminTests(TestCase):
|
|||
exclude = ['bio']
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name', 'sign_date'])
|
||||
|
||||
# You can also pass a tuple to `exclude`.
|
||||
|
@ -116,7 +117,7 @@ class ModelAdminTests(TestCase):
|
|||
exclude = ('bio',)
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name', 'sign_date'])
|
||||
|
||||
# Using `fields` and `exclude`.
|
||||
|
@ -125,7 +126,7 @@ class ModelAdminTests(TestCase):
|
|||
exclude = ['bio']
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name'])
|
||||
|
||||
def test_custom_form_meta_exclude_with_readonly(self):
|
||||
|
@ -148,8 +149,8 @@ class ModelAdminTests(TestCase):
|
|||
form = AdminBandForm
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
['sign_date',])
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['sign_date'])
|
||||
|
||||
# Then, with `InlineModelAdmin` -----------------
|
||||
|
||||
|
@ -172,8 +173,8 @@ class ModelAdminTests(TestCase):
|
|||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(
|
||||
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
||||
['main_band', 'opening_band', 'id', 'DELETE',])
|
||||
list(list(ma.get_formsets(request))[0]().forms[0].fields),
|
||||
['main_band', 'opening_band', 'id', 'DELETE'])
|
||||
|
||||
def test_custom_form_meta_exclude(self):
|
||||
"""
|
||||
|
@ -194,8 +195,8 @@ class ModelAdminTests(TestCase):
|
|||
form = AdminBandForm
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
['bio', 'sign_date',])
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['bio', 'sign_date'])
|
||||
|
||||
# Then, with `InlineModelAdmin` -----------------
|
||||
|
||||
|
@ -218,8 +219,8 @@ class ModelAdminTests(TestCase):
|
|||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(
|
||||
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
||||
['main_band', 'opening_band', 'day', 'id', 'DELETE',])
|
||||
list(list(ma.get_formsets(request))[0]().forms[0].fields),
|
||||
['main_band', 'opening_band', 'day', 'id', 'DELETE'])
|
||||
|
||||
def test_custom_form_validation(self):
|
||||
# If we specify a form, it should use it allowing custom validation to work
|
||||
|
@ -235,7 +236,7 @@ class ModelAdminTests(TestCase):
|
|||
form = AdminBandForm
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name', 'bio', 'sign_date', 'delete'])
|
||||
|
||||
self.assertEqual(
|
||||
|
@ -255,7 +256,7 @@ class ModelAdminTests(TestCase):
|
|||
exclude = ['name']
|
||||
|
||||
class BandAdmin(ModelAdmin):
|
||||
exclude = ['sign_date',]
|
||||
exclude = ['sign_date']
|
||||
form = AdminBandForm
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
|
@ -263,9 +264,8 @@ class ModelAdminTests(TestCase):
|
|||
return super(BandAdmin, self).get_form(request, obj, **kwargs)
|
||||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
['name', 'sign_date',])
|
||||
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['name', 'sign_date'])
|
||||
|
||||
def test_formset_exclude_kwarg_override(self):
|
||||
"""
|
||||
|
@ -296,8 +296,8 @@ class ModelAdminTests(TestCase):
|
|||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(
|
||||
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
||||
['main_band', 'day', 'transport', 'id', 'DELETE',])
|
||||
list(list(ma.get_formsets(request))[0]().forms[0].fields),
|
||||
['main_band', 'day', 'transport', 'id', 'DELETE'])
|
||||
|
||||
def test_queryset_override(self):
|
||||
# If we need to override the queryset of a ModelChoiceField in our custom form
|
||||
|
@ -461,7 +461,7 @@ class ModelAdminTests(TestCase):
|
|||
form = AdminConcertForm
|
||||
|
||||
ma = ConcertAdmin(Concert, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['main_band', 'opening_band', 'day'])
|
||||
|
||||
class AdminConcertForm(forms.ModelForm):
|
||||
|
@ -475,7 +475,7 @@ class ModelAdminTests(TestCase):
|
|||
form = AdminConcertForm
|
||||
|
||||
ma = ConcertAdmin(Concert, self.site)
|
||||
self.assertEqual(ma.get_form(request).base_fields.keys(),
|
||||
self.assertEqual(list(ma.get_form(request).base_fields),
|
||||
['extra', 'transport'])
|
||||
|
||||
class ConcertInline(TabularInline):
|
||||
|
@ -491,7 +491,7 @@ class ModelAdminTests(TestCase):
|
|||
|
||||
ma = BandAdmin(Band, self.site)
|
||||
self.assertEqual(
|
||||
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
||||
list(list(ma.get_formsets(request))[0]().forms[0].fields),
|
||||
['extra', 'transport', 'id', 'DELETE', 'main_band'])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue