<s> from django . test import TestCase <EOL> from django . core . exceptions import PermissionDenied <EOL> from permission . utils . handlers import registry <EOL> from permission . decorators . functionbase import permission_required <EOL> from permission . tests . test_decorators . utils import create_mock_handler <EOL> from permission . tests . test_decorators . utils import create_mock_request <EOL> from permission . tests . test_decorators . utils import create_mock_view_func <EOL> from permission . tests . test_decorators . utils import create_mock_queryset <EOL> from permission . tests . test_decorators . utils import create_mock_model <EOL> class PermissionFunctionDecoratorsTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . handler = create_mock_handler ( ) <EOL> self . request = create_mock_request ( self . handler ) <EOL> self . model = create_mock_model ( ) <EOL> self . model_instance = self . model ( ) <EOL> self . queryset = create_mock_queryset ( self . model_instance ) <EOL> self . view_func = create_mock_view_func ( ) <EOL> self . decorated = permission_required ( <EOL> '<STR_LIT>' ) ( self . view_func ) <EOL> self . decorated_exc = permission_required ( <EOL> '<STR_LIT>' , raise_exception = True ) ( self . view_func ) <EOL> self . _original_registry = registry . _registry <EOL> registry . _registry = { } <EOL> registry . register ( <EOL> self . model , <EOL> self . handler , <EOL> ) <EOL> def tearDown ( self ) : <EOL> registry . _registry = self . _original_registry <EOL> def test_list_detail_object_id ( self ) : <EOL> self . view_func . called = False <EOL> self . handler . has_perm . return_value = False <EOL> self . decorated ( self . request , <EOL> queryset = self . queryset , <EOL> object_id = <NUM_LIT:1> ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertFalse ( self . view_func . called ) <EOL> self . assertRaises ( PermissionDenied , self . decorated_exc , <EOL> self . request , queryset = self . queryset , <EOL> object_id = <NUM_LIT:1> ) <EOL> self . assertFalse ( self . view_func . called ) <EOL> self . handler . has_perm . return_value = True <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> object_id = <NUM_LIT:1> ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertTrue ( self . view_func . called ) <EOL> def test_list_detail_slug ( self ) : <EOL> self . view_func . called = False <EOL> self . handler . has_perm . return_value = False <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> slug = '<STR_LIT>' , <EOL> slug_field = '<STR_LIT:title>' ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertFalse ( self . view_func . called ) <EOL> self . handler . has_perm . return_value = True <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> slug = '<STR_LIT>' , <EOL> slug_field = '<STR_LIT:title>' ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertTrue ( self . view_func . called ) <EOL> def test_date_based_object_id ( self ) : <EOL> self . view_func . called = False <EOL> self . handler . has_perm . return_value = False <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> year = '<STR_LIT>' , month = '<STR_LIT:1>' , day = '<STR_LIT:1>' , <EOL> date_field = '<STR_LIT>' , <EOL> month_format = '<STR_LIT>' , <EOL> object_id = <NUM_LIT:1> ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertFalse ( self . view_func . called ) <EOL> self . handler . has_perm . return_value = True <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> year = '<STR_LIT>' , month = '<STR_LIT:1>' , day = '<STR_LIT:1>' , <EOL> date_field = '<STR_LIT>' , <EOL> month_format = '<STR_LIT>' , <EOL> object_id = <NUM_LIT:1> ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertTrue ( self . view_func . called ) <EOL> def test_date_based_slug ( self ) : <EOL> self . view_func . called = False <EOL> self . handler . has_perm . return_value = False <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> year = '<STR_LIT>' , month = '<STR_LIT:1>' , day = '<STR_LIT:1>' , <EOL> date_field = '<STR_LIT>' , <EOL> month_format = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> slug_field = '<STR_LIT:title>' ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertFalse ( self . view_func . called ) <EOL> self . handler . has_perm . return_value = True <EOL> self . decorated ( <EOL> self . request , <EOL> queryset = self . queryset , <EOL> year = '<STR_LIT>' , month = '<STR_LIT:1>' , day = '<STR_LIT:1>' , <EOL> date_field = '<STR_LIT>' , <EOL> month_format = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> slug_field = '<STR_LIT:title>' ) <EOL> self . request . user . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . handler . has_perm . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> obj = self . model_instance , <EOL> ) <EOL> self . assertTrue ( self . view_func . called ) </s>
