Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update deps / handle sourcery warnings #154

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dsp_permissions_scripts/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create(
def from_dict(d: dict[str, list[str]], dsp_client: DspClient) -> PermissionScope:
purged_kwargs = PermissionScope._remove_duplicates_from_kwargs(d)
purged_kwargs = {
k: [get_prefixed_iri_from_full_iri(v, dsp_client) if not is_valid_prefixed_group_iri(v) else v for v in vs]
k: [v if is_valid_prefixed_group_iri(v) else get_prefixed_iri_from_full_iri(v, dsp_client) for v in vs]
for k, vs in purged_kwargs.items()
}
return PermissionScope.model_validate({k: [group_builder(v) for v in vs] for k, vs in purged_kwargs.items()})
Expand Down Expand Up @@ -83,7 +83,7 @@ def check_group_occurs_only_once(self) -> PermissionScope:

@model_validator(mode="after")
def check_scope_not_empty(self) -> PermissionScope:
if not any([len(self.get(field)) > 0 for field in self.model_fields]):
if not any(self.get(field) for field in self.model_fields):
raise EmptyScopeError()
return self

Expand All @@ -98,7 +98,7 @@ def add(
self,
permission: Literal["CR", "D", "M", "V", "RV"],
group: Group,
) -> PermissionScope:
) -> PermissionScope: # sourcery skip: class-extract-method
"""Return a copy of the PermissionScope instance with group added to permission."""
groups = self.get(permission)
if group.prefixed_iri in [g.prefixed_iri for g in groups]:
Expand Down
3 changes: 1 addition & 2 deletions dsp_permissions_scripts/oap/oap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def apply_updated_oaps_on_server(
msg = f"Updating {res_oap_count} resource OAPs and {value_oap_count} value OAPs on {dsp_client.server}..."
logger.info(f"******* {msg} *******")

failed_iris = _launch_thread_pool(oaps, nthreads, dsp_client)
if failed_iris:
if failed_iris := _launch_thread_pool(oaps, nthreads, dsp_client):
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"FAILED_RESOURCES_AND_VALUES_{timestamp}.txt"
_write_failed_iris_to_file(
Expand Down
7 changes: 3 additions & 4 deletions dsp_permissions_scripts/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def modify_aps(aps: list[Ap]) -> list[Ap]:
"""Adapt this sample to your needs."""
modified_aps = []
for ap in copy.deepcopy(aps):
if ap.forGroup == group.PROJECT_ADMIN:
if ApValue.ProjectAdminRightsAllPermission not in ap.hasPermissions:
ap.add_permission(ApValue.ProjectAdminRightsAllPermission)
modified_aps.append(ap)
if ap.forGroup == group.PROJECT_ADMIN and ApValue.ProjectAdminRightsAllPermission not in ap.hasPermissions:
ap.add_permission(ApValue.ProjectAdminRightsAllPermission)
modified_aps.append(ap)
return modified_aps


Expand Down
7 changes: 3 additions & 4 deletions dsp_permissions_scripts/utils/dsp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get(
self,
route: str,
headers: dict[str, str] | None = None,
) -> dict[str, Any]:
) -> dict[str, Any]: # sourcery skip: class-extract-method
"""
Make an HTTP GET request to the server to which this connection has been established.

Expand Down Expand Up @@ -257,8 +257,7 @@ def _handle_non_ok_responses(self, response: Response, retry_counter: int) -> No
return None

already = "dsp.errors.BadRequestException: The submitted permissions are the same as the current ones"
should_break = response.status_code == 400 and response.text and already in response.text
if should_break:
if response.status_code == 400 and response.text and already in response.text:
raise PermissionsAlreadyUpToDate()

raise ApiError("Permanently unable to execute the network action", response.text, response.status_code)
Expand Down Expand Up @@ -296,7 +295,7 @@ def _anonymize(self, data: dict[str, Any] | None) -> dict[str, Any] | None:
data["Set-Cookie"] = self._mask(data["Set-Cookie"])
if "Authorization" in data:
if match := re.search(r"^Bearer (.+)", data["Authorization"]):
data["Authorization"] = f"Bearer {self._mask(match.group(1))}"
data["Authorization"] = f"Bearer {self._mask(match[1])}"
if "password" in data:
data["password"] = "*" * len(data["password"])
return data
Expand Down
340 changes: 182 additions & 158 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/test_oap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def test_get_oaps_of_one_kb_resclass_4_results_on_2_pages(
class Test_get_oaps_of_kb_resclasses:
def test_get_oaps_of_kb_resclasses_all_resclasses_all_values(
self, _enrich_with_value_oaps: Mock, _get_oaps_of_specified_kb_resclasses: Mock
) -> None:
) -> None: # sourcery skip: class-extract-method
dsp_client = Mock(spec=DspClient)
oap_config = OapRetrieveConfig(
retrieve_resources="all",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_oap_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_oap_multiple_vals(self) -> None:


class TestOapRetrieveConfig:
def test_all_resources_all_values(self) -> None:
def test_all_resources_all_values(self) -> None: # sourcery skip: class-extract-method
conf = OapRetrieveConfig(retrieve_resources="all", retrieve_values="all")
assert conf.retrieve_resources == "all"
assert conf.specified_res_classes == []
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def dsp_client() -> DspClient:


class TestScopeCreation:
def test_valid_scope(self) -> None:
def test_valid_scope(self) -> None: # sourcery skip: class-extract-method
scope = PermissionScope(
CR=frozenset({group.SYSTEM_ADMIN}),
D=frozenset({group.PROJECT_ADMIN}),
Expand Down