#NEWLINE# def test_simplelistfilter( self ) : #NEWLINE# #INDENT# modeladmin = DecadeFilterBookAdmin ( Book , site ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , list ( Book . objects . all ( ) . order_by ( '-id' ) ) ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'publication decade' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'display' ] , 'All' ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'query_string' ] , '?' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'publication-decade' : 'the 80s' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'publication decade' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'display' ] , "the 1980's" ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'query_string' ] , '?publication-decade=the+80s' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'publication-decade' : 'the 90s' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . bio_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'publication decade' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'display' ] , "the 1990's" ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'query_string' ] , '?publication-decade=the+90s' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'publication-decade' : 'the 00s' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . guitar_book , self . djangonaut_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'publication decade' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'display' ] , "the 2000's" ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'query_string' ] , '?publication-decade=the+00s' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'publication-decade' : 'the 00s' , #NEWLINE# 'author__id__exact' : self . alfred . pk , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . djangonaut_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'publication decade' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'display' ] , "the 2000's" ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 3 ] [ 'query_string' ] , ( '?author__id__exact=%s&publication-decade=the+00s' % self . alfred . pk ) ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 0 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'Verbose Author' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'alfred' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , ( '?author__id__exact=%s&publication-decade=the+00s' % self . alfred . pk ) )