Coverage for src/pypermission/exc.py: 100%
31 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-14 14:14 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-14 14:14 +0000
1################################################################################
2#### Generic Errors
3################################################################################
6class PyPermissionError(Exception):
7 """
8 PyPermissionError is the standard error of PyPermission.
10 Attributes
11 ----------
12 message : str
13 A detailed description of the occurred error.
14 """
16 message: str
18 def __init__(self, message: str = ""):
19 self.message = message
22class PermissionNotGrantedError(PyPermissionError):
23 """
24 PermissionNotGrantedError will be thrown if an `assert_permission()` fails!
26 Attributes
27 ----------
28 message : str
29 A constant error description.
30 """
32 message = "RBAC: Permission not granted!"
35################################################################################
36#### Testing only:
37################################################################################
40class ERR_MSG:
41 # conflict
42 conflict_role_exists = "Role '{role}' already exists!"
43 conflict_subject_exists = "Subject '{subject}' already exists!"
44 conflict_hierarchy_exists = "Hierarchy '{parent_role}' -> '{child_role}' exists!"
45 conflict_permission_exists = "Permission '{permission_str}' does already exist!"
46 conflict_cycle_detected = "Desired hierarchy would create a cycle!"
47 conflicting_role_ids = "RoleIDs must not be equal: '{role}'!"
49 # empty string not allowed
50 empty_subject = "Subject name cannot be empty!"
51 empty_role = "Role name cannot be empty!"
52 empty_parent_role = "Role name cannot be empty, but `parent_role` is empty!"
53 empty_child_role = "Role name cannot be empty, but `child_role` is empty!"
54 empty_resource_type = "Resource type cannot be empty!"
55 empty_action = "Action cannot be empty!"
57 # non_existent
58 non_existent_subject_role = "Subject '{subject}' or Role '{role}' does not exist!"
59 non_existent_subject = "Subject '{subject}' does not exist!"
60 non_existent_role = "Role '{role}' does not exist!"
61 non_existent_hierarchy = (
62 "Hierarchy '{parent_role}' -> '{child_role}' does not exist!"
63 )
64 non_existent_parent_child_roles = (
65 "Roles '{parent_role}' and '{child_role}' do not exist!"
66 )
67 non_existent_role_assignment = (
68 "Role '{role}' is not assigned to Subject '{subject}'!"
69 )
70 non_existent_permission = "Permission '{permission_str}' does not exist!"
72 # permission_not_granted
73 permission_not_granted_for_role = (
74 "Permission '{permission_str}' is not granted for Role '{role}'!"
75 )
76 permission_not_granted_for_subject = (
77 "Permission '{permission_str}' is not granted for Subject '{subject}'!"
78 )
80 # other
81 unexpected_integrity = "Unexpected IntegrityError!"
82 foreign_keys_pragma_not_set = (
83 "Foreign keys pragma appears to not be set! Please use the 'set_sqlite_pragma' function"
84 " on your SQLite engine before interacting with the database!"
85 )
86 frozen_attributes_cannot_be_modified = "Frozen attributes cannot be modified!"