Coverage for src/pypermission/exc.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2025-12-01 18:06 +0000

1################################################################################ 

2#### Generic Errors 

3################################################################################ 

4 

5 

6class PyPermissionError(Exception): 

7 """ 

8 PyPermissionError is the standard error of PyPermission. 

9 

10 Attributes 

11 ---------- 

12 message : str 

13 A detailed description of the occurred error. 

14 """ 

15 

16 message: str 

17 

18 def __init__(self, message: str = ""): 

19 self.message = message 

20 

21 

22class PermissionNotGrantedError(PyPermissionError): 

23 """ 

24 PermissionNotGrantedError will be thrown if an `assert_permission()` fails! 

25 

26 Attributes 

27 ---------- 

28 message : str 

29 A constant error description. 

30 """ 

31 

32 message = "RBAC: Permission not granted!" 

33 

34 

35################################################################################ 

36#### Testing only: 

37################################################################################ 

38 

39 

40class ERR_MSG_CONFLICT: 

41 role_exists = "Conflict: Role with ID '{role}' already exists!" 

42 subject_exists = "Conflict: Subject with ID '{subject}' already exists!" 

43 hierarchy_exists = ( 

44 "Conflict: Role Hierarchy '{parent_role}' -> '{child_role}' exists!" 

45 ) 

46 policy_exists = "Conflict: Policy '{policy_str}' already exists!" 

47 cycle_detected = "Conflict: Desired Role Hierarchy would create a cycle!" 

48 role_ids = ( 

49 "Conflict: A Role Hierarchy requires distinct RoleIDs, received '{role}' twice!" 

50 ) 

51 role_assigned_to_subject = "Conflict: Role with ID '{role}' already assigned to Subject with ID '{subject}'!" 

52 

53 

54# Do not template this for now, makes tests more read and searchable 

55class ERR_STR_EMPTY: 

56 subject = "Argument `subject` cannot be empty!" 

57 role = "Argument `role` cannot be empty!" 

58 parent_role = "Argument `parent_role` cannot be empty!" 

59 child_role = "Argument `child_role` cannot be empty!" 

60 resource_type = "Argument `resource_type` cannot be empty!" 

61 action = "Argument `action` cannot be empty!" 

62 

63 

64class ERR_STR_WHITESPACE: 

65 subject = "`subject` cannot have leading or trailing spaces!" 

66 role = "`role` cannot have leading or trailing spaces!" 

67 parent_role = "`parent_role` cannot have leading or trailing spaces!" 

68 child_role = "`child_role` cannot have leading or trailing spaces!" 

69 resource_type = "`resource_type` cannot have leading or trailing spaces!" 

70 action = "`action` cannot have leading or trailing spaces!" 

71 

72 

73class ERR_MSG: 

74 # non_existent 

75 non_existent_subject_role = "Subject '{subject}' or Role '{role}' does not exist!" 

76 non_existent_subject = "Subject '{subject}' does not exist!" 

77 non_existent_role = "Role '{role}' does not exist!" 

78 non_existent_hierarchy = ( 

79 "Hierarchy '{parent_role}' -> '{child_role}' does not exist!" 

80 ) 

81 non_existent_parent_child_roles = ( 

82 "Roles '{parent_role}' and '{child_role}' do not exist!" 

83 ) 

84 non_existent_role_assignment = ( 

85 "Role '{role}' is not assigned to Subject '{subject}'!" 

86 ) 

87 non_existent_policy = "Policy '{policy_str}' does not exist!" 

88 

89 # permission_not_granted 

90 permission_not_granted_for_role = ( 

91 "Permission '{permission_str}' is not granted for Role '{role}'!" 

92 ) 

93 permission_not_granted_for_subject = ( 

94 "Permission '{permission_str}' is not granted for Subject '{subject}'!" 

95 ) 

96 

97 # other 

98 unexpected_integrity = "Unexpected IntegrityError!" 

99 foreign_keys_pragma_not_set = ( 

100 "Foreign keys pragma appears to not be set! Please use the 'set_sqlite_pragma' function" 

101 " on your SQLite engine before interacting with the database!" 

102 ) 

103 frozen_attributes_cannot_be_modified = "Frozen attributes cannot be modified!"