Skip to content
Snippets Groups Projects
Verified Commit 3f2099c2 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: mypy

parent e00a4a2e
No related branches found
No related tags found
2 merge requests!175BUG: Request responses without the "Set-Cookie" header no longer overwrite the...,!164Fix mypy errors
Pipeline #58012 failed
...@@ -275,8 +275,10 @@ def compare_entities(entity0: Optional[Entity] = None, ...@@ -275,8 +275,10 @@ def compare_entities(entity0: Optional[Entity] = None,
if entity1 is not None: if entity1 is not None:
raise ValueError("You cannot use both entity1 and new_entity") raise ValueError("You cannot use both entity1 and new_entity")
entity1 = new_entity entity1 = new_entity
assert entity0 is not None
assert entity1 is not None
diff: tuple = ({"properties": {}, "parents": []}, diff: tuple[dict[str, Any], dict[str, Any]] = ({"properties": {}, "parents": []},
{"properties": {}, "parents": []}) {"properties": {}, "parents": []})
if entity0 is entity1: if entity0 is entity1:
...@@ -550,7 +552,8 @@ def merge_entities(entity_a: Entity, ...@@ -550,7 +552,8 @@ def merge_entities(entity_a: Entity,
""" """
# Compare both entities: # Compare both entities:
diff_r1, diff_r2 = compare_entities(entity_a, entity_b, diff_r1, diff_r2 = compare_entities(
entity_a, entity_b,
entity_name_id_equivalency=merge_id_with_resolved_entity, entity_name_id_equivalency=merge_id_with_resolved_entity,
compare_referenced_records=merge_references_with_empty_diffs) compare_referenced_records=merge_references_with_empty_diffs)
......
...@@ -91,7 +91,7 @@ def get_server_properties() -> dict[str, Optional[str]]: ...@@ -91,7 +91,7 @@ def get_server_properties() -> dict[str, Optional[str]]:
props: dict[str, Optional[str]] = dict() props: dict[str, Optional[str]] = dict()
for elem in xml.getroot(): for elem in xml.getroot():
props[elem.tag] = elem.text props[elem.tag] = str(elem.text)
return props return props
...@@ -156,7 +156,10 @@ def generate_password(length: int): ...@@ -156,7 +156,10 @@ def generate_password(length: int):
def _retrieve_user(name: str, realm: Optional[str] = None, **kwargs): def _retrieve_user(name: str, realm: Optional[str] = None, **kwargs):
con = get_connection() con = get_connection()
try: try:
return con._http_request(method="GET", path="User/" + (realm + "/" + name if realm is not None else name), **kwargs).read() return con._http_request(
method="GET",
path="User/" + (realm + "/" + name if realm is not None else name),
**kwargs).read()
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to retrieve this user." e.msg = "You are not permitted to retrieve this user."
raise raise
...@@ -198,7 +201,9 @@ def _update_user(name: str, ...@@ -198,7 +201,9 @@ def _update_user(name: str,
if entity is not None: if entity is not None:
params["entity"] = str(entity) params["entity"] = str(entity)
try: try:
return con.put_form_data(entity_uri_segment="User/" + (realm + "/" + name if realm is not None else name), params=params, **kwargs).read() return con.put_form_data(entity_uri_segment="User/" + (realm + "/" +
name if realm is not None else name),
params=params, **kwargs).read()
except HTTPResourceNotFoundError as e: except HTTPResourceNotFoundError as e:
e.msg = "User does not exist." e.msg = "User does not exist."
raise e raise e
...@@ -246,7 +251,9 @@ def _insert_user(name: str, ...@@ -246,7 +251,9 @@ def _insert_user(name: str,
def _insert_role(name, description, **kwargs): def _insert_role(name, description, **kwargs):
con = get_connection() con = get_connection()
try: try:
return con.post_form_data(entity_uri_segment="Role", params={"role_name": name, "role_description": description}, **kwargs).read() return con.post_form_data(entity_uri_segment="Role",
params={"role_name": name, "role_description": description},
**kwargs).read()
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to insert a new role." e.msg = "You are not permitted to insert a new role."
raise raise
...@@ -259,7 +266,9 @@ def _insert_role(name, description, **kwargs): ...@@ -259,7 +266,9 @@ def _insert_role(name, description, **kwargs):
def _update_role(name, description, **kwargs): def _update_role(name, description, **kwargs):
con = get_connection() con = get_connection()
try: try:
return con.put_form_data(entity_uri_segment="Role/" + name, params={"role_description": description}, **kwargs).read() return con.put_form_data(entity_uri_segment="Role/" + name,
params={"role_description": description},
**kwargs).read()
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to update this role." e.msg = "You are not permitted to update this role."
raise raise
...@@ -301,8 +310,10 @@ def _set_roles(username, roles, realm=None, **kwargs): ...@@ -301,8 +310,10 @@ def _set_roles(username, roles, realm=None, **kwargs):
body = xml2str(xml) body = xml2str(xml)
con = get_connection() con = get_connection()
try: try:
body = con._http_request(method="PUT", path="UserRoles/" + (realm + "/" + body = con._http_request(method="PUT",
username if realm is not None else username), body=body, **kwargs).read() path="UserRoles/" + (realm + "/" +
username if realm is not None else username),
body=body, **kwargs).read()
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to set this user's roles." e.msg = "You are not permitted to set this user's roles."
raise raise
...@@ -369,7 +380,8 @@ def _set_permissions(role, permission_rules, **kwargs): ...@@ -369,7 +380,8 @@ def _set_permissions(role, permission_rules, **kwargs):
body = xml2str(xml) body = xml2str(xml)
con = get_connection() con = get_connection()
try: try:
return con._http_request(method="PUT", path="PermissionRules/" + role, body=body, **kwargs).read() return con._http_request(method="PUT", path="PermissionRules/" + role, body=body,
**kwargs).read()
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to set this role's permissions." e.msg = "You are not permitted to set this role's permissions."
raise raise
...@@ -381,7 +393,9 @@ def _set_permissions(role, permission_rules, **kwargs): ...@@ -381,7 +393,9 @@ def _set_permissions(role, permission_rules, **kwargs):
def _get_permissions(role, **kwargs): def _get_permissions(role, **kwargs):
con = get_connection() con = get_connection()
try: try:
return PermissionRule._parse_body(con._http_request(method="GET", path="PermissionRules/" + role, **kwargs).read()) return PermissionRule._parse_body(con._http_request(method="GET",
path="PermissionRules/" + role,
**kwargs).read())
except HTTPForbiddenError as e: except HTTPForbiddenError as e:
e.msg = "You are not permitted to retrieve this role's permissions." e.msg = "You are not permitted to retrieve this role's permissions."
raise raise
...@@ -429,7 +443,8 @@ class PermissionRule(): ...@@ -429,7 +443,8 @@ class PermissionRule():
if permission is None: if permission is None:
raise ValueError(f"Permission is missing in PermissionRule xml: {elem}") raise ValueError(f"Permission is missing in PermissionRule xml: {elem}")
priority = PermissionRule._parse_boolean(elem.get("priority")) priority = PermissionRule._parse_boolean(elem.get("priority"))
return PermissionRule(elem.tag, permission, priority if priority is not None else False) return PermissionRule(str(elem.tag), permission,
priority if priority is not None else False)
@staticmethod @staticmethod
def _parse_body(body: str): def _parse_body(body: str):
......
...@@ -130,9 +130,9 @@ def recordtypes_to_plantuml_string(iterable, ...@@ -130,9 +130,9 @@ def recordtypes_to_plantuml_string(iterable,
classes = [el for el in iterable classes = [el for el in iterable
if isinstance(el, db.RecordType)] if isinstance(el, db.RecordType)]
dependencies = {} dependencies: dict = {}
inheritances = {} inheritances: dict = {}
properties = [p for p in iterable if isinstance(p, db.Property)] properties: list = [p for p in iterable if isinstance(p, db.Property)]
grouped = [g for g in iterable if isinstance(g, Grouped)] grouped = [g for g in iterable if isinstance(g, Grouped)]
def _add_properties(c, importance=None): def _add_properties(c, importance=None):
...@@ -272,7 +272,8 @@ package \"The property P references an instance of D\" <<Rectangle>> { ...@@ -272,7 +272,8 @@ package \"The property P references an instance of D\" <<Rectangle>> {
return result return result
def retrieve_substructure(start_record_types, depth, result_id_set=None, result_container=None, cleanup=True): def retrieve_substructure(start_record_types, depth, result_id_set=None, result_container=None,
cleanup=True):
"""Recursively retrieves LinkAhead record types and properties, starting """Recursively retrieves LinkAhead record types and properties, starting
from given initial types up to a specific depth. from given initial types up to a specific depth.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment