<s> from django . contrib import admin <EOL> from django . contrib . auth . models import User <EOL> from hvad . test_utils . testcase import HvadTestCase <EOL> from hvad . test_utils . fixtures import NormalFixture , UsersFixture <EOL> from hvad . test_utils . project . app . models import LimitedChoice <EOL> class LimitChoicesToTests ( HvadTestCase , UsersFixture , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_limit_choices_to ( self ) : <EOL> """<STR_LIT>""" <EOL> limited_choice_admin = admin . site . _registry [ LimitedChoice ] <EOL> with self . login_user_context ( '<STR_LIT>' ) : <EOL> rf = self . request_factory <EOL> get_request = rf . get ( '<STR_LIT>' ) <EOL> get_request . session = self . client . session <EOL> get_request . user = User . objects . get ( pk = self . user_id [ '<STR_LIT>' ] ) <EOL> Form = limited_choice_admin . get_form ( get_request ) <EOL> form = Form ( ) <EOL> qs_fk = form . fields [ '<STR_LIT>' ] . queryset <EOL> self . assertTrue ( qs_fk . filter ( shared_field = '<STR_LIT>' ) . exists ( ) ) <EOL> self . assertFalse ( qs_fk . filter ( shared_field = '<STR_LIT>' ) . exists ( ) ) <EOL> qs_mm = form . fields [ '<STR_LIT>' ] . queryset <EOL> self . assertTrue ( qs_mm . filter ( shared_field = '<STR_LIT>' ) . exists ( ) ) <EOL> self . assertFalse ( qs_mm . filter ( shared_field = '<STR_LIT>' ) . exists ( ) ) </s>
