<s> from datetime import date <EOL> import unittest <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . contrib . admin . options import ModelAdmin , TabularInline , HORIZONTAL , VERTICAL <EOL> from django . contrib . admin . sites import AdminSite <EOL> from django . contrib . admin . validation import validate <EOL> from django . contrib . admin . widgets import AdminDateWidget , AdminRadioSelect <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . forms . models import BaseModelFormSet <EOL> from django . forms . widgets import Select <EOL> from django . test import TestCase <EOL> from models import Band , Concert , ValidationTestModel , ValidationTestInlineModel <EOL> request = None <EOL> class ModelAdminTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . band = Band . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> bio = '<STR_LIT>' , <EOL> sign_date = date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ) <EOL> self . site = AdminSite ( ) <EOL> def test_default_fields ( self ) : <EOL> ma = ModelAdmin ( Band , self . site ) <EOL> self . assertEquals ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_default_fieldsets ( self ) : <EOL> ma = ModelAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_fieldsets ( request ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) ] ) <EOL> self . assertEqual ( ma . get_fieldsets ( request , self . band ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] } ) ] ) <EOL> def test_field_arguments ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_fieldsets ( request ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] ) <EOL> self . assertEqual ( ma . get_fieldsets ( request , self . band ) , <EOL> [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] ) <EOL> def test_field_arguments_restricted_on_form ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( ma . get_form ( request , self . band ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' ] } ) ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( ma . get_form ( request , self . band ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = [ '<STR_LIT>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> exclude = ( '<STR_LIT>' , ) <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fields = [ '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> exclude = [ '<STR_LIT>' ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' ] ) <EOL> def test_custom_form_validation ( self ) : <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> delete = forms . BooleanField ( ) <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> type ( ma . get_form ( request ) . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminDateWidget ) <EOL> def test_queryset_override ( self ) : <EOL> band2 = Band ( name = '<STR_LIT>' , bio = '<STR_LIT>' , sign_date = date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> band2 . save ( ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> pass <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> form = ma . get_form ( request ) ( ) <EOL> self . assertEqual ( str ( form [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . band . id , band2 . id ) ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( AdminConcertForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ "<STR_LIT>" ] . queryset = Band . objects . filter ( name = '<STR_LIT>' ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> form = ma . get_form ( request ) ( ) <EOL> self . assertEqual ( str ( form [ "<STR_LIT>" ] ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % self . band . id ) <EOL> def test_default_foreign_key_widget ( self ) : <EOL> cma = ModelAdmin ( Concert , self . site ) <EOL> cmafa = cma . get_form ( request ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , Select ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> Select ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) , ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> def test_foreign_key_as_radio_field ( self ) : <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> radio_fields = { <EOL> '<STR_LIT>' : HORIZONTAL , <EOL> '<STR_LIT>' : VERTICAL , <EOL> '<STR_LIT>' : VERTICAL , <EOL> '<STR_LIT>' : HORIZONTAL , <EOL> } <EOL> cma = ConcertAdmin ( Concert , self . site ) <EOL> cmafa = cma . get_form ( request ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> type ( cmafa . base_fields [ '<STR_LIT>' ] . widget . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( u'<STR_LIT>' , u'<STR_LIT:None>' ) , ( self . band . id , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( type ( cmafa . base_fields [ '<STR_LIT>' ] . widget ) , <EOL> AdminRadioSelect ) <EOL> self . assertEqual ( cmafa . base_fields [ '<STR_LIT>' ] . widget . attrs , <EOL> { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( list ( cmafa . base_fields [ '<STR_LIT>' ] . widget . choices ) , <EOL> [ ( '<STR_LIT>' , u'<STR_LIT:None>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:2> , '<STR_LIT>' ) , ( <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Concert <EOL> exclude = ( '<STR_LIT>' , ) <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class AdminConcertForm ( forms . ModelForm ) : <EOL> extra = forms . CharField ( ) <EOL> class Meta : <EOL> model = Concert <EOL> fields = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class ConcertAdmin ( ModelAdmin ) : <EOL> form = AdminConcertForm <EOL> ma = ConcertAdmin ( Concert , self . site ) <EOL> self . assertEqual ( ma . get_form ( request ) . base_fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ConcertInline ( TabularInline ) : <EOL> form = AdminConcertForm <EOL> model = Concert <EOL> fk_name = '<STR_LIT>' <EOL> can_delete = True <EOL> class BandAdmin ( ModelAdmin ) : <EOL> inlines = [ <EOL> ConcertInline <EOL> ] <EOL> ma = BandAdmin ( Band , self . site ) <EOL> self . assertEqual ( <EOL> list ( ma . get_formsets ( request ) ) [ <NUM_LIT:0> ] ( ) . forms [ <NUM_LIT:0> ] . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ValidationTests ( unittest . TestCase ) : <EOL> def assertRaisesErrorWithMessage ( self , error , message , callable , * args , ** kwargs ) : <EOL> self . assertRaises ( error , callable , * args , ** kwargs ) <EOL> try : <EOL> callable ( * args , ** kwargs ) <EOL> except error , e : <EOL> self . assertEqual ( message , str ( e ) ) <EOL> def test_validation_only_runs_in_debug ( self ) : <EOL> try : <EOL> settings . DEBUG = True <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = <NUM_LIT:10> <EOL> site = AdminSite ( ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> site . register , <EOL> ValidationTestModel , <EOL> ValidationTestModelAdmin , <EOL> ) <EOL> finally : <EOL> settings . DEBUG = False <EOL> site = AdminSite ( ) <EOL> site . register ( ValidationTestModel , ValidationTestModelAdmin ) <EOL> def test_raw_id_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT:name>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> raw_id_fields = ( '<STR_LIT>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_fieldsets_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( { } , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( ) , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , ( ) ) , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { } ) , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT>" , ) } ) , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } ) , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = ( ( "<STR_LIT>" , { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } ) , ) <EOL> fields = [ "<STR_LIT:name>" , ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fieldsets = [ ( None , { '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT:name>' ] } ) ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> fields = [ "<STR_LIT:name>" , "<STR_LIT:name>" ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_form_validation ( self ) : <EOL> class FakeForm ( object ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> form = FakeForm <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_fieldsets_with_custom_form_validation ( self ) : <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> BandAdmin , <EOL> Band , <EOL> ) <EOL> class BandAdmin ( ModelAdmin ) : <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , ) <EOL> } ) , <EOL> ) <EOL> validate ( BandAdmin , Band ) <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> BandAdmin , <EOL> Band , <EOL> ) <EOL> class AdminBandForm ( forms . ModelForm ) : <EOL> delete = forms . BooleanField ( ) <EOL> class Meta : <EOL> model = Band <EOL> class BandAdmin ( ModelAdmin ) : <EOL> form = AdminBandForm <EOL> fieldsets = ( <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ) <EOL> validate ( BandAdmin , Band ) <EOL> def test_filter_vertical_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT>" , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT:name>" , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_vertical = ( "<STR_LIT>" , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_filter_horizontal_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT>" , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT:name>" , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> filter_horizontal = ( "<STR_LIT>" , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_radio_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = ( ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT>" : None } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:name>" : None } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:state>" : None } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> radio_fields = { "<STR_LIT:state>" : VERTICAL } <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_prepopulated_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = ( ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : None } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT>" , ) } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> prepopulated_fields = { "<STR_LIT>" : ( "<STR_LIT:name>" , ) } <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_display_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_display_links_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display_links = ( '<STR_LIT:name>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , ) <EOL> list_display_links = ( '<STR_LIT:name>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_filter_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_per_page_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_per_page = '<STR_LIT:hello>' <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_per_page = <NUM_LIT:100> <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_search_fields_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> search_fields = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_date_hierarchy_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT>' <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT:name>' <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> date_hierarchy = '<STR_LIT>' <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_ordering_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:?>' , '<STR_LIT:name>' ) <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:?>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> ordering = ( '<STR_LIT:name>' , ) <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_list_select_related_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_select_related = <NUM_LIT:1> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> list_select_related = False <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_save_as_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_as = <NUM_LIT:1> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_as = True <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_save_on_top_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_on_top = <NUM_LIT:1> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> save_on_top = True <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_inlines_validation ( self ) : <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = <NUM_LIT:10> <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( object ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> pass <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class SomethingBad ( object ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = SomethingBad <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_fields_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fields = <NUM_LIT:10> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fields = ( "<STR_LIT>" , ) <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> def test_fk_name_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fk_name = "<STR_LIT>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> fk_name = "<STR_LIT>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_extra_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> extra = "<STR_LIT:hello>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> extra = <NUM_LIT:2> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_max_num_validation ( self ) : <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> max_num = "<STR_LIT:hello>" <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> max_num = <NUM_LIT:2> <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) <EOL> def test_formset_validation ( self ) : <EOL> class FakeFormSet ( object ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> formset = FakeFormSet <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> self . assertRaisesErrorWithMessage ( <EOL> ImproperlyConfigured , <EOL> "<STR_LIT>" , <EOL> validate , <EOL> ValidationTestModelAdmin , <EOL> ValidationTestModel , <EOL> ) <EOL> class RealModelFormSet ( BaseModelFormSet ) : <EOL> pass <EOL> class ValidationTestInline ( TabularInline ) : <EOL> model = ValidationTestInlineModel <EOL> formset = RealModelFormSet <EOL> class ValidationTestModelAdmin ( ModelAdmin ) : <EOL> inlines = [ ValidationTestInline ] <EOL> validate ( ValidationTestModelAdmin , ValidationTestModel ) </s>
