<s> from __future__ import unicode_literals <EOL> import datetime <EOL> from django . contrib import admin <EOL> from django . contrib . admin . models import LogEntry <EOL> from django . contrib . admin . options import IncorrectLookupParameters <EOL> from django . contrib . admin . templatetags . admin_list import pagination <EOL> from django . contrib . admin . tests import AdminSeleniumTestCase <EOL> from django . contrib . admin . views . main import ALL_VAR , SEARCH_VAR , ChangeList <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . template import Context , Template <EOL> from django . test import TestCase , ignore_warnings , override_settings <EOL> from django . test . client import RequestFactory <EOL> from django . urls import reverse <EOL> from django . utils import formats , six <EOL> from django . utils . deprecation import RemovedInDjango20Warning <EOL> from . admin import ( <EOL> BandAdmin , ChildAdmin , ChordsBandAdmin , ConcertAdmin , <EOL> CustomPaginationAdmin , CustomPaginator , DynamicListDisplayChildAdmin , <EOL> DynamicListDisplayLinksChildAdmin , DynamicListFilterChildAdmin , <EOL> DynamicSearchFieldsChildAdmin , EmptyValueChildAdmin , EventAdmin , <EOL> FilteredChildAdmin , GroupAdmin , InvitationAdmin , <EOL> NoListDisplayLinksParentAdmin , ParentAdmin , QuartetAdmin , SwallowAdmin , <EOL> site as custom_site , <EOL> ) <EOL> from . models import ( <EOL> Band , Child , ChordsBand , ChordsMusician , Concert , CustomIdUser , Event , <EOL> Genre , Group , Invitation , Membership , Musician , OrderedObject , Parent , <EOL> Quartet , Swallow , SwallowOneToOne , UnorderedObject , <EOL> ) <EOL> def get_changelist_args ( modeladmin , ** kwargs ) : <EOL> m = modeladmin <EOL> args = ( <EOL> kwargs . pop ( '<STR_LIT>' , m . list_display ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_display_links ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_filter ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . date_hierarchy ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . search_fields ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_select_related ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_per_page ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_max_show_all ) , <EOL> kwargs . pop ( '<STR_LIT>' , m . list_editable ) , <EOL> m , <EOL> ) <EOL> assert not kwargs , "<STR_LIT>" % kwargs <EOL> return args <EOL> @ override_settings ( ROOT_URLCONF = "<STR_LIT>" ) <EOL> class ChangeListTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = RequestFactory ( ) <EOL> def _create_superuser ( self , username ) : <EOL> return User . objects . create_superuser ( username = username , email = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> def _mocked_authenticated_request ( self , url , user ) : <EOL> request = self . factory . get ( url ) <EOL> request . user = user <EOL> return request <EOL> def test_select_related_preserved ( self ) : <EOL> """<STR_LIT>""" <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> cl = ChangeList ( <EOL> request , Child , <EOL> * get_changelist_args ( m , list_select_related = m . get_list_select_related ( request ) ) <EOL> ) <EOL> self . assertEqual ( cl . queryset . query . select_related , { '<STR_LIT>' : { } } ) <EOL> def test_select_related_as_tuple ( self ) : <EOL> ia = InvitationAdmin ( Invitation , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> cl = ChangeList ( <EOL> request , Child , <EOL> * get_changelist_args ( ia , list_select_related = ia . get_list_select_related ( request ) ) <EOL> ) <EOL> self . assertEqual ( cl . queryset . query . select_related , { '<STR_LIT>' : { } } ) <EOL> def test_select_related_as_empty_tuple ( self ) : <EOL> ia = InvitationAdmin ( Invitation , custom_site ) <EOL> ia . list_select_related = ( ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> cl = ChangeList ( <EOL> request , Child , <EOL> * get_changelist_args ( ia , list_select_related = ia . get_list_select_related ( request ) ) <EOL> ) <EOL> self . assertEqual ( cl . queryset . query . select_related , False ) <EOL> def test_get_select_related_custom_method ( self ) : <EOL> class GetListSelectRelatedAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_list_select_related ( self , request ) : <EOL> return ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ia = GetListSelectRelatedAdmin ( Invitation , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> cl = ChangeList ( <EOL> request , Child , <EOL> * get_changelist_args ( ia , list_select_related = ia . get_list_select_related ( request ) ) <EOL> ) <EOL> self . assertEqual ( cl . queryset . query . select_related , { '<STR_LIT>' : { } , '<STR_LIT>' : { } } ) <EOL> def test_result_list_empty_changelist_value ( self ) : <EOL> """<STR_LIT>""" <EOL> new_child = Child . objects . create ( name = '<STR_LIT:name>' , parent = None ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . formset = None <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> link = reverse ( '<STR_LIT>' , args = ( new_child . id , ) ) <EOL> row_html = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % link <EOL> ) <EOL> self . assertNotEqual ( table_output . find ( row_html ) , - <NUM_LIT:1> , '<STR_LIT>' % table_output ) <EOL> def test_result_list_set_empty_value_display_on_admin_site ( self ) : <EOL> """<STR_LIT>""" <EOL> new_child = Child . objects . create ( name = '<STR_LIT:name>' , parent = None ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> admin . site . empty_value_display = '<STR_LIT>' <EOL> m = ChildAdmin ( Child , admin . site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . formset = None <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> link = reverse ( '<STR_LIT>' , args = ( new_child . id , ) ) <EOL> row_html = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % link <EOL> ) <EOL> self . assertNotEqual ( table_output . find ( row_html ) , - <NUM_LIT:1> , '<STR_LIT>' % table_output ) <EOL> def test_result_list_set_empty_value_display_in_model_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> new_child = Child . objects . create ( name = '<STR_LIT:name>' , parent = None ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = EmptyValueChildAdmin ( Child , admin . site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . formset = None <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> link = reverse ( '<STR_LIT>' , args = ( new_child . id , ) ) <EOL> row_html = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % link <EOL> ) <EOL> self . assertNotEqual ( table_output . find ( row_html ) , - <NUM_LIT:1> , '<STR_LIT>' % table_output ) <EOL> def test_result_list_html ( self ) : <EOL> """<STR_LIT>""" <EOL> new_parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> new_child = Child . objects . create ( name = '<STR_LIT:name>' , parent = new_parent ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . formset = None <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> link = reverse ( '<STR_LIT>' , args = ( new_child . id , ) ) <EOL> row_html = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % link <EOL> ) <EOL> self . assertNotEqual ( table_output . find ( row_html ) , - <NUM_LIT:1> , '<STR_LIT>' % table_output ) <EOL> def test_result_list_editable_html ( self ) : <EOL> """<STR_LIT>""" <EOL> new_parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> new_child = Child . objects . create ( name = '<STR_LIT:name>' , parent = new_parent ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> m . list_display = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> m . list_display_links = [ '<STR_LIT:id>' ] <EOL> m . list_editable = [ '<STR_LIT:name>' ] <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> FormSet = m . get_changelist_formset ( request ) <EOL> cl . formset = FormSet ( queryset = cl . result_list ) <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> hiddenfields_div = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) % new_child . id <EOL> self . assertInHTML ( hiddenfields_div , table_output , msg_prefix = '<STR_LIT>' ) <EOL> editable_name_field = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertInHTML ( <EOL> '<STR_LIT>' % editable_name_field , <EOL> table_output , <EOL> msg_prefix = '<STR_LIT>' , <EOL> ) <EOL> def test_result_list_editable ( self ) : <EOL> """<STR_LIT>""" <EOL> new_parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:200> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = new_parent ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT:p>' : - <NUM_LIT:1> } ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> m . list_display = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> m . list_display_links = [ '<STR_LIT:id>' ] <EOL> m . list_editable = [ '<STR_LIT:name>' ] <EOL> with self . assertRaises ( IncorrectLookupParameters ) : <EOL> ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> @ ignore_warnings ( category = RemovedInDjango20Warning ) <EOL> def test_result_list_with_allow_tags ( self ) : <EOL> """<STR_LIT>""" <EOL> new_parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = new_parent ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> def custom_method ( self , obj = None ) : <EOL> return '<STR_LIT>' <EOL> custom_method . allow_tags = True <EOL> m . custom_method = custom_method <EOL> m . list_display = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> FormSet = m . get_changelist_formset ( request ) <EOL> cl . formset = FormSet ( queryset = cl . result_list ) <EOL> template = Template ( '<STR_LIT>' ) <EOL> context = Context ( { '<STR_LIT>' : cl } ) <EOL> table_output = template . render ( context ) <EOL> custom_field_html = '<STR_LIT>' <EOL> self . assertInHTML ( custom_field_html , table_output ) <EOL> def test_custom_paginator ( self ) : <EOL> new_parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:200> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = new_parent ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = CustomPaginationAdmin ( Child , custom_site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertIsInstance ( cl . paginator , CustomPaginator ) <EOL> def test_distinct_for_m2m_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> blues = Genre . objects . create ( name = '<STR_LIT>' ) <EOL> band = Band . objects . create ( name = '<STR_LIT>' , nr_of_members = <NUM_LIT:11> ) <EOL> band . genres . add ( blues ) <EOL> band . genres . add ( blues ) <EOL> m = BandAdmin ( Band , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : blues . pk } ) <EOL> cl = ChangeList ( request , Band , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( cl . result_count , <NUM_LIT:1> ) <EOL> def test_distinct_for_through_m2m_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> lead = Musician . objects . create ( name = '<STR_LIT>' ) <EOL> band = Group . objects . create ( name = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> m = GroupAdmin ( Group , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : lead . pk } ) <EOL> cl = ChangeList ( request , Group , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( cl . result_count , <NUM_LIT:1> ) <EOL> def test_distinct_for_through_m2m_at_second_level_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> lead = Musician . objects . create ( name = '<STR_LIT>' ) <EOL> band = Group . objects . create ( name = '<STR_LIT>' ) <EOL> Concert . objects . create ( name = '<STR_LIT>' , group = band ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> m = ConcertAdmin ( Concert , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : lead . pk } ) <EOL> cl = ChangeList ( request , Concert , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( cl . result_count , <NUM_LIT:1> ) <EOL> def test_distinct_for_inherited_m2m_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> lead = Musician . objects . create ( name = '<STR_LIT>' ) <EOL> four = Quartet . objects . create ( name = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = four , music = lead , role = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = four , music = lead , role = '<STR_LIT>' ) <EOL> m = QuartetAdmin ( Quartet , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : lead . pk } ) <EOL> cl = ChangeList ( request , Quartet , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( cl . result_count , <NUM_LIT:1> ) <EOL> def test_distinct_for_m2m_to_inherited_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> lead = ChordsMusician . objects . create ( name = '<STR_LIT>' ) <EOL> three = ChordsBand . objects . create ( name = '<STR_LIT>' ) <EOL> Invitation . objects . create ( band = three , player = lead , instrument = '<STR_LIT>' ) <EOL> Invitation . objects . create ( band = three , player = lead , instrument = '<STR_LIT>' ) <EOL> m = ChordsBandAdmin ( ChordsBand , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : lead . pk } ) <EOL> cl = ChangeList ( request , ChordsBand , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( cl . result_count , <NUM_LIT:1> ) <EOL> def test_distinct_for_non_unique_related_object_in_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> Child . objects . create ( parent = parent , name = '<STR_LIT>' ) <EOL> Child . objects . create ( parent = parent , name = '<STR_LIT>' ) <EOL> m = ParentAdmin ( Parent , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> cl = ChangeList ( request , Parent , * get_changelist_args ( m ) ) <EOL> self . assertEqual ( cl . queryset . count ( ) , <NUM_LIT:1> ) <EOL> def test_distinct_for_non_unique_related_object_in_search_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> Child . objects . create ( parent = parent , name = '<STR_LIT>' ) <EOL> Child . objects . create ( parent = parent , name = '<STR_LIT>' ) <EOL> m = ParentAdmin ( Parent , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { SEARCH_VAR : '<STR_LIT>' } ) <EOL> cl = ChangeList ( request , Parent , * get_changelist_args ( m ) ) <EOL> self . assertEqual ( cl . queryset . count ( ) , <NUM_LIT:1> ) <EOL> def test_distinct_for_many_to_many_at_second_level_in_search_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> lead = Musician . objects . create ( name = '<STR_LIT>' ) <EOL> band = Group . objects . create ( name = '<STR_LIT>' ) <EOL> Concert . objects . create ( name = '<STR_LIT>' , group = band ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> Membership . objects . create ( group = band , music = lead , role = '<STR_LIT>' ) <EOL> m = ConcertAdmin ( Concert , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { SEARCH_VAR : '<STR_LIT>' } ) <EOL> cl = ChangeList ( request , Concert , * get_changelist_args ( m ) ) <EOL> self . assertEqual ( cl . queryset . count ( ) , <NUM_LIT:1> ) <EOL> def test_pagination ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:30> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> self . assertEqual ( cl . queryset . count ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( cl . paginator . count , <NUM_LIT> ) <EOL> self . assertEqual ( list ( cl . paginator . page_range ) , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) <EOL> m = FilteredChildAdmin ( Child , custom_site ) <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> self . assertEqual ( cl . queryset . count ( ) , <NUM_LIT:30> ) <EOL> self . assertEqual ( cl . paginator . count , <NUM_LIT:30> ) <EOL> self . assertEqual ( list ( cl . paginator . page_range ) , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def test_computed_list_display_localization ( self ) : <EOL> """<STR_LIT>""" <EOL> superuser = User . objects . create_superuser ( username = '<STR_LIT>' , email = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . force_login ( superuser ) <EOL> event = Event . objects . create ( date = datetime . date . today ( ) ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertContains ( response , formats . localize ( event . date ) ) <EOL> self . assertNotContains ( response , six . text_type ( event . date ) ) <EOL> def test_dynamic_list_display ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> user_noparents = self . _create_superuser ( '<STR_LIT>' ) <EOL> user_parents = self . _create_superuser ( '<STR_LIT>' ) <EOL> m = custom_site . _registry [ Child ] <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , user_noparents ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertNotContains ( response , '<STR_LIT>' ) <EOL> list_display = m . get_list_display ( request ) <EOL> list_display_links = m . get_list_display_links ( request , list_display ) <EOL> self . assertEqual ( list_display , [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( list_display_links , [ '<STR_LIT:name>' ] ) <EOL> m = DynamicListDisplayChildAdmin ( Child , custom_site ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , user_parents ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> custom_site . unregister ( Child ) <EOL> list_display = m . get_list_display ( request ) <EOL> list_display_links = m . get_list_display_links ( request , list_display ) <EOL> self . assertEqual ( list_display , ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( list_display_links , [ '<STR_LIT>' ] ) <EOL> custom_site . register ( Child , ChildAdmin ) <EOL> m = custom_site . _registry [ Child ] <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , user_noparents ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> def test_show_all ( self ) : <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:30> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> request = self . factory . get ( '<STR_LIT>' , data = { ALL_VAR : '<STR_LIT>' } ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> m . list_max_show_all = <NUM_LIT:200> <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( len ( cl . result_list ) , <NUM_LIT> ) <EOL> m = ChildAdmin ( Child , custom_site ) <EOL> m . list_max_show_all = <NUM_LIT:30> <EOL> cl = ChangeList ( request , Child , * get_changelist_args ( m ) ) <EOL> cl . get_results ( request ) <EOL> self . assertEqual ( len ( cl . result_list ) , <NUM_LIT:10> ) <EOL> def test_dynamic_list_display_links ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> Child . objects . create ( id = i , name = '<STR_LIT>' % i , parent = parent , age = i ) <EOL> m = DynamicListDisplayLinksChildAdmin ( Child , custom_site ) <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , superuser ) <EOL> response = m . changelist_view ( request ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:10> ) : <EOL> link = reverse ( '<STR_LIT>' , args = ( i , ) ) <EOL> self . assertContains ( response , '<STR_LIT>' % ( link , i ) ) <EOL> list_display = m . get_list_display ( request ) <EOL> list_display_links = m . get_list_display_links ( request , list_display ) <EOL> self . assertEqual ( list_display , ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( list_display_links , [ '<STR_LIT>' ] ) <EOL> def test_no_list_display_links ( self ) : <EOL> """<STR_LIT>""" <EOL> p = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> m = NoListDisplayLinksParentAdmin ( Parent , custom_site ) <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , superuser ) <EOL> response = m . changelist_view ( request ) <EOL> link = reverse ( '<STR_LIT>' , args = ( p . pk , ) ) <EOL> self . assertNotContains ( response , '<STR_LIT>' % link ) <EOL> def test_tuple_list_display ( self ) : <EOL> """<STR_LIT>""" <EOL> swallow = Swallow . objects . create ( origin = '<STR_LIT>' , load = '<STR_LIT>' , speed = '<STR_LIT>' ) <EOL> swallow2 = Swallow . objects . create ( origin = '<STR_LIT>' , load = '<STR_LIT>' , speed = '<STR_LIT>' ) <EOL> swallow_o2o = SwallowOneToOne . objects . create ( swallow = swallow2 ) <EOL> model_admin = SwallowAdmin ( Swallow , custom_site ) <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , superuser ) <EOL> response = model_admin . changelist_view ( request ) <EOL> self . assertContains ( response , six . text_type ( swallow . origin ) ) <EOL> self . assertContains ( response , six . text_type ( swallow . load ) ) <EOL> self . assertContains ( response , six . text_type ( swallow . speed ) ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' % swallow_o2o ) <EOL> def test_multiuser_edit ( self ) : <EOL> """<STR_LIT>""" <EOL> a = Swallow . objects . create ( origin = '<STR_LIT>' , load = <NUM_LIT:4> , speed = <NUM_LIT:1> ) <EOL> b = Swallow . objects . create ( origin = '<STR_LIT>' , load = <NUM_LIT:2> , speed = <NUM_LIT:2> ) <EOL> c = Swallow . objects . create ( origin = '<STR_LIT>' , load = <NUM_LIT:5> , speed = <NUM_LIT:5> ) <EOL> d = Swallow . objects . create ( origin = '<STR_LIT>' , load = <NUM_LIT:9> , speed = <NUM_LIT:9> ) <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> self . client . force_login ( superuser ) <EOL> changelist_url = reverse ( '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( d . pk ) , <EOL> '<STR_LIT>' : str ( c . pk ) , <EOL> '<STR_LIT>' : str ( a . pk ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> response = self . client . post ( changelist_url , data , follow = True , extra = { '<STR_LIT:o>' : '<STR_LIT>' } ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , a . origin ) <EOL> a . refresh_from_db ( ) <EOL> self . assertEqual ( a . load , float ( data [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( a . speed , float ( data [ '<STR_LIT>' ] ) ) <EOL> b . refresh_from_db ( ) <EOL> self . assertEqual ( b . load , <NUM_LIT:2> ) <EOL> self . assertEqual ( b . speed , <NUM_LIT:2> ) <EOL> c . refresh_from_db ( ) <EOL> self . assertEqual ( c . load , float ( data [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( c . speed , float ( data [ '<STR_LIT>' ] ) ) <EOL> d . refresh_from_db ( ) <EOL> self . assertEqual ( d . load , float ( data [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( d . speed , float ( data [ '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( len ( Swallow . objects . all ( ) ) , <NUM_LIT:4> ) <EOL> def test_deterministic_order_for_unordered_model ( self ) : <EOL> """<STR_LIT>""" <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> for counter in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> UnorderedObject . objects . create ( id = counter , bool = True ) <EOL> class UnorderedObjectAdmin ( admin . ModelAdmin ) : <EOL> list_per_page = <NUM_LIT:10> <EOL> def check_results_order ( ascending = False ) : <EOL> custom_site . register ( UnorderedObject , UnorderedObjectAdmin ) <EOL> model_admin = UnorderedObjectAdmin ( UnorderedObject , custom_site ) <EOL> counter = <NUM_LIT:0> if ascending else <NUM_LIT> <EOL> for page in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' % page , superuser ) <EOL> response = model_admin . changelist_view ( request ) <EOL> for result in response . context_data [ '<STR_LIT>' ] . result_list : <EOL> counter += <NUM_LIT:1> if ascending else - <NUM_LIT:1> <EOL> self . assertEqual ( result . id , counter ) <EOL> custom_site . unregister ( UnorderedObject ) <EOL> check_results_order ( ) <EOL> UnorderedObjectAdmin . ordering = [ '<STR_LIT:bool>' ] <EOL> check_results_order ( ) <EOL> UnorderedObjectAdmin . ordering = [ '<STR_LIT:bool>' , '<STR_LIT>' ] <EOL> check_results_order ( ) <EOL> UnorderedObjectAdmin . ordering = [ '<STR_LIT:bool>' , '<STR_LIT>' ] <EOL> check_results_order ( ascending = True ) <EOL> UnorderedObjectAdmin . ordering = [ '<STR_LIT>' , '<STR_LIT:bool>' ] <EOL> check_results_order ( ) <EOL> UnorderedObjectAdmin . ordering = [ '<STR_LIT:id>' , '<STR_LIT:bool>' ] <EOL> check_results_order ( ascending = True ) <EOL> def test_deterministic_order_for_model_ordered_by_its_manager ( self ) : <EOL> """<STR_LIT>""" <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> for counter in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> OrderedObject . objects . create ( id = counter , bool = True , number = counter ) <EOL> class OrderedObjectAdmin ( admin . ModelAdmin ) : <EOL> list_per_page = <NUM_LIT:10> <EOL> def check_results_order ( ascending = False ) : <EOL> custom_site . register ( OrderedObject , OrderedObjectAdmin ) <EOL> model_admin = OrderedObjectAdmin ( OrderedObject , custom_site ) <EOL> counter = <NUM_LIT:0> if ascending else <NUM_LIT> <EOL> for page in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' % page , superuser ) <EOL> response = model_admin . changelist_view ( request ) <EOL> for result in response . context_data [ '<STR_LIT>' ] . result_list : <EOL> counter += <NUM_LIT:1> if ascending else - <NUM_LIT:1> <EOL> self . assertEqual ( result . id , counter ) <EOL> custom_site . unregister ( OrderedObject ) <EOL> check_results_order ( ascending = True ) <EOL> OrderedObjectAdmin . ordering = [ '<STR_LIT:bool>' ] <EOL> check_results_order ( ) <EOL> OrderedObjectAdmin . ordering = [ '<STR_LIT:bool>' , '<STR_LIT>' ] <EOL> check_results_order ( ) <EOL> OrderedObjectAdmin . ordering = [ '<STR_LIT:bool>' , '<STR_LIT>' ] <EOL> check_results_order ( ascending = True ) <EOL> OrderedObjectAdmin . ordering = [ '<STR_LIT>' , '<STR_LIT:bool>' ] <EOL> check_results_order ( ) <EOL> OrderedObjectAdmin . ordering = [ '<STR_LIT:id>' , '<STR_LIT:bool>' ] <EOL> check_results_order ( ascending = True ) <EOL> def test_dynamic_list_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> parent = Parent . objects . create ( name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> Child . objects . create ( name = '<STR_LIT>' % i , parent = parent ) <EOL> user_noparents = self . _create_superuser ( '<STR_LIT>' ) <EOL> user_parents = self . _create_superuser ( '<STR_LIT>' ) <EOL> m = DynamicListFilterChildAdmin ( Child , custom_site ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , user_noparents ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertEqual ( response . context_data [ '<STR_LIT>' ] . list_filter , [ '<STR_LIT:name>' , '<STR_LIT>' ] ) <EOL> m = DynamicListFilterChildAdmin ( Child , custom_site ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , user_parents ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertEqual ( response . context_data [ '<STR_LIT>' ] . list_filter , ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> def test_dynamic_search_fields ( self ) : <EOL> child = self . _create_superuser ( '<STR_LIT>' ) <EOL> m = DynamicSearchFieldsChildAdmin ( Child , custom_site ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , child ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertEqual ( response . context_data [ '<STR_LIT>' ] . search_fields , ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> def test_pagination_page_range ( self ) : <EOL> """<STR_LIT>""" <EOL> m = GroupAdmin ( Group , custom_site ) <EOL> request = self . factory . get ( '<STR_LIT>' ) <EOL> cl = ChangeList ( request , Group , * get_changelist_args ( m ) ) <EOL> per_page = cl . list_per_page = <NUM_LIT:10> <EOL> for page_num , objects_count , expected_page_range in [ <EOL> ( <NUM_LIT:0> , per_page , [ ] ) , <EOL> ( <NUM_LIT:0> , per_page * <NUM_LIT:2> , list ( range ( <NUM_LIT:2> ) ) ) , <EOL> ( <NUM_LIT:5> , per_page * <NUM_LIT:11> , list ( range ( <NUM_LIT:11> ) ) ) , <EOL> ( <NUM_LIT:5> , per_page * <NUM_LIT:12> , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , '<STR_LIT:.>' , <NUM_LIT:10> , <NUM_LIT:11> ] ) , <EOL> ( <NUM_LIT:6> , per_page * <NUM_LIT:12> , [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:.>' , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> ] ) , <EOL> ( <NUM_LIT:6> , per_page * <NUM_LIT> , [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:.>' , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , '<STR_LIT:.>' , <NUM_LIT:11> , <NUM_LIT:12> ] ) , <EOL> ] : <EOL> Group . objects . all ( ) . delete ( ) <EOL> for i in range ( objects_count ) : <EOL> Group . objects . create ( name = '<STR_LIT>' ) <EOL> cl . page_num = page_num <EOL> cl . get_results ( request ) <EOL> real_page_range = pagination ( cl ) [ '<STR_LIT>' ] <EOL> self . assertListEqual ( <EOL> expected_page_range , <EOL> list ( real_page_range ) , <EOL> ) <EOL> def test_object_tools_displayed_no_add_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> superuser = self . _create_superuser ( '<STR_LIT>' ) <EOL> m = EventAdmin ( Event , custom_site ) <EOL> request = self . _mocked_authenticated_request ( '<STR_LIT>' , superuser ) <EOL> self . assertFalse ( m . has_add_permission ( request ) ) <EOL> response = m . changelist_view ( request ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> class AdminLogNodeTestCase ( TestCase ) : <EOL> def test_get_admin_log_templatetag_custom_user ( self ) : <EOL> """<STR_LIT>""" <EOL> context = Context ( { '<STR_LIT:user>' : CustomIdUser ( ) } ) <EOL> template_string = '<STR_LIT>' <EOL> template = Template ( template_string ) <EOL> self . assertEqual ( template . render ( context ) , '<STR_LIT>' ) <EOL> def test_get_admin_log_templatetag_no_user ( self ) : <EOL> """<STR_LIT>""" <EOL> user = User ( username = '<STR_LIT>' , password = '<STR_LIT>' , email = '<STR_LIT>' ) <EOL> user . save ( ) <EOL> ct = ContentType . objects . get_for_model ( User ) <EOL> LogEntry . objects . log_action ( user . pk , ct . pk , user . pk , repr ( user ) , <NUM_LIT:1> ) <EOL> t = Template ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( t . render ( Context ( { } ) ) , '<STR_LIT>' ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> class SeleniumTests ( AdminSeleniumTestCase ) : <EOL> available_apps = [ '<STR_LIT>' ] + AdminSeleniumTestCase . available_apps <EOL> def setUp ( self ) : <EOL> User . objects . create_superuser ( username = '<STR_LIT>' , password = '<STR_LIT>' , email = None ) <EOL> def test_add_row_selection ( self ) : <EOL> """<STR_LIT>""" <EOL> self . admin_login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . selenium . get ( self . live_server_url + reverse ( '<STR_LIT>' ) ) <EOL> form_id = '<STR_LIT>' <EOL> rows = self . selenium . find_elements_by_css_selector ( <EOL> '<STR_LIT>' % form_id ) <EOL> self . assertEqual ( len ( rows ) , <NUM_LIT:1> ) <EOL> selection_indicator = self . selenium . find_element_by_css_selector ( <EOL> '<STR_LIT>' % form_id ) <EOL> self . assertEqual ( selection_indicator . text , "<STR_LIT>" ) <EOL> row_selector = self . selenium . find_element_by_css_selector ( <EOL> '<STR_LIT>' % form_id ) <EOL> row_selector . click ( ) <EOL> self . assertEqual ( selection_indicator . text , "<STR_LIT>" ) </s>
