<s> from django . test import TestCase <EOL> from permission import add_permission_logic <EOL> from permission . logics import AuthorPermissionLogic <EOL> from permission . tests . utils import create_user <EOL> from permission . tests . utils import create_anonymous <EOL> from permission . tests . utils import create_article <EOL> from permission . tests . compat import MagicMock <EOL> from permission . tests . compat import override_settings <EOL> @ override_settings ( <EOL> PERMISSION_DEFAULT_APL_FIELD_NAME = '<STR_LIT>' , <EOL> PERMISSION_DEFAULT_APL_ANY_PERMISSION = True , <EOL> PERMISSION_DEFAULT_APL_CHANGE_PERMISSION = True , <EOL> PERMISSION_DEFAULT_APL_DELETE_PERMISSION = True , <EOL> ) <EOL> class PermissionLogicsAuthorPermissionLogicTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user1 = create_user ( '<STR_LIT>' ) <EOL> self . user2 = create_user ( '<STR_LIT>' ) <EOL> self . anonymous = create_anonymous ( ) <EOL> self . perm1 = '<STR_LIT>' <EOL> self . perm2 = '<STR_LIT>' <EOL> self . perm3 = '<STR_LIT>' <EOL> self . article = create_article ( '<STR_LIT:test>' , user = self . user2 ) <EOL> def test_constructor ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( isinstance ( permission_logic , AuthorPermissionLogic ) ) <EOL> self . assertEqual ( permission_logic . field_name , '<STR_LIT>' ) <EOL> self . assertEqual ( permission_logic . any_permission , True ) <EOL> self . assertEqual ( permission_logic . change_permission , True ) <EOL> self . assertEqual ( permission_logic . delete_permission , True ) <EOL> def test_constructor_with_specifing_field_name ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( field_name = '<STR_LIT>' ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( isinstance ( permission_logic , AuthorPermissionLogic ) ) <EOL> self . assertEqual ( permission_logic . field_name , '<STR_LIT>' ) <EOL> def test_constructor_with_specifing_any_permission ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( isinstance ( permission_logic , AuthorPermissionLogic ) ) <EOL> self . assertEqual ( permission_logic . any_permission , False ) <EOL> def test_constructor_with_specifing_change_permission ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( change_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( isinstance ( permission_logic , AuthorPermissionLogic ) ) <EOL> self . assertEqual ( permission_logic . change_permission , False ) <EOL> def test_constructor_with_specifing_delete_permission ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( delete_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( isinstance ( permission_logic , AuthorPermissionLogic ) ) <EOL> self . assertEqual ( permission_logic . delete_permission , False ) <EOL> def test_has_perm_add_without_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( permission_logic . has_perm ( self . user1 , self . perm1 ) ) <EOL> def test_has_perm_change_without_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( permission_logic . has_perm ( self . user1 , self . perm2 ) ) <EOL> def test_has_perm_delete_without_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( permission_logic . has_perm ( self . user1 , self . perm3 ) ) <EOL> def test_has_perm_add_without_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( permission_logic . has_perm ( self . anonymous , self . perm1 ) ) <EOL> def test_has_perm_change_without_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( permission_logic . has_perm ( self . anonymous , self . perm2 ) ) <EOL> def test_has_perm_delete_without_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( permission_logic . has_perm ( self . anonymous , self . perm3 ) ) <EOL> def test_has_perm_add_with_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user1 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user1 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user1 , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . anonymous , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . anonymous , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_with_anonymous ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . anonymous , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_author ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_author ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_author ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_author_diff_field_name ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( field_name = '<STR_LIT>' ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_author_diff_field_name ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( field_name = '<STR_LIT>' ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_author_diff_field_name ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( field_name = '<STR_LIT>' ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_author_non_any ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_author_non_any ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_non_any ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_author_non_any_no_change ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> change_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_author_non_any_no_change ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> change_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_non_any_no_change ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> change_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm3 , self . article ) ) <EOL> def test_has_perm_add_with_obj_author_non_any_no_delete ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> delete_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm1 , self . article ) ) <EOL> def test_has_perm_change_with_obj_author_non_any_no_delete ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> delete_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertTrue ( <EOL> permission_logic . has_perm ( self . user2 , self . perm2 , self . article ) ) <EOL> def test_has_perm_delete_with_obj_non_any_no_delete ( self ) : <EOL> permission_logic = AuthorPermissionLogic ( any_permission = False , <EOL> delete_permission = False ) <EOL> add_permission_logic ( self . article . __class__ , permission_logic ) <EOL> self . assertFalse ( <EOL> permission_logic . has_perm ( self . user2 , self . perm3 , self . article ) ) </s>
