Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converted the modeladmin tests to run on python 2 and 3.

  • Loading branch information...
commit cca01c96d18f72cfc156ccfade769735b9de4f98 1 parent 54afdbf
Alex Gaynor alex authored Alex Gaynor committed
Showing with 29 additions and 29 deletions.
  1. +29 −29 tests/regressiontests/modeladmin/tests.py
58 tests/regressiontests/modeladmin/tests.py
View
@@ -5,7 +5,7 @@
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.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 @@
class MockRequest(object):
pass
+
class MockSuperUser(object):
def has_perm(self, perm):
return True
@@ -47,7 +48,7 @@ def setUp(self):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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 Meta:
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 @@ def get_form(self, request, obj=None, **kwargs):
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 BandAdmin(ModelAdmin):
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 ConcertAdmin(ModelAdmin):
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 ConcertAdmin(ModelAdmin):
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 BandAdmin(ModelAdmin):
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'])
Please sign in to comment.
Something went wrong with that request. Please try again.