Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 13, 2023
1 parent e14058e commit bd6ea6a
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 40 deletions.
5 changes: 1 addition & 4 deletions dsp_permissions_scripts/doap/doap_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from dsp_permissions_scripts.doap.doap_model import Doap, DoapTargetType


def _get_file_path(
shortcode: str,
mode: Literal["original", "modified"]
) -> Path:
def _get_file_path(shortcode: str, mode: Literal["original", "modified"]) -> Path:
return Path(f"project_data/{shortcode}/DOAPs_{mode}.json")


Expand Down
1 change: 1 addition & 0 deletions dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

logger = get_logger(__name__)


def _update_doap_scope(
doap_iri: str,
scope: PermissionScope,
Expand Down
3 changes: 2 additions & 1 deletion dsp_permissions_scripts/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PermissionScope(BaseModel):
A scope is an object encoding the information:
"Which user group gets which permissions on a resource/value?"
"""

model_config = ConfigDict(frozen=True)

CR: frozenset[str] = frozenset()
Expand Down Expand Up @@ -62,7 +63,7 @@ def add(
if perm != permission:
kwargs[perm] = getattr(self, perm)
return PermissionScope.create(**kwargs)

def remove(
self,
permission: Literal["CR", "D", "M", "V", "RV"],
Expand Down
26 changes: 13 additions & 13 deletions dsp_permissions_scripts/oap/oap_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ def _update_permissions_for_resource_and_values(
context = _get_context(resource)
values = _get_value_iris(resource)
_update_permissions_for_resource(
resource_iri=resource_iri,
lmd=lmd,
resource_type=resource_type,
context=context,
scope=scope,
host=host,
resource_iri=resource_iri,
lmd=lmd,
resource_type=resource_type,
context=context,
scope=scope,
host=host,
token=token,
)
for v in values:
_update_permissions_for_value(
resource_iri=resource_iri,
value=v,
resource_type=resource_type,
context=context,
scope=scope,
host=host,
resource_iri=resource_iri,
value=v,
resource_type=resource_type,
context=context,
scope=scope,
host=host,
token=token,
)

Expand Down Expand Up @@ -223,7 +223,7 @@ def apply_updated_oaps_on_server(
if failed_res_iris:
filename = "FAILED_RESOURCES.txt"
_write_failed_res_iris_to_file(
failed_res_iris=failed_res_iris,
failed_res_iris=failed_res_iris,
shortcode=shortcode,
host=host,
filename=filename,
Expand Down
5 changes: 1 addition & 4 deletions dsp_permissions_scripts/oap/oap_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from dsp_permissions_scripts.oap.oap_model import Oap


def _get_project_data_path(
shortcode: str,
mode: Literal["original", "modified"]
) -> Path:
def _get_project_data_path(shortcode: str, mode: Literal["original", "modified"]) -> Path:
return Path(f"project_data/{shortcode}/OAPs_{mode}")


Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def modify_doaps(doaps: list[Doap]) -> list[Doap]:
"""Adapt this sample to your needs."""
for doap in doaps:
for doap in doaps:
if doap.target.group in [builtin_groups.PROJECT_MEMBER, builtin_groups.PROJECT_ADMIN]:
doap.scope = PUBLIC
return doaps
Expand Down
14 changes: 7 additions & 7 deletions dsp_permissions_scripts/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def dereference_prefix(
identifier: str,
identifier: str,
context: dict[str, str],
) -> str:
prefix, actual_id = identifier.split(":")
Expand All @@ -18,12 +18,12 @@ def _get_sort_pos_of_custom_group(group: str) -> int:
def sort_groups(groups_original: list[str]) -> list[str]:
"""Sorts groups, first according to their power (most powerful first), then alphabetically."""
sort_key = [
builtin_groups.SYSTEM_ADMIN,
builtin_groups.CREATOR,
builtin_groups.PROJECT_ADMIN,
builtin_groups.PROJECT_MEMBER,
builtin_groups.KNOWN_USER,
builtin_groups.UNKNOWN_USER
builtin_groups.SYSTEM_ADMIN,
builtin_groups.CREATOR,
builtin_groups.PROJECT_ADMIN,
builtin_groups.PROJECT_MEMBER,
builtin_groups.KNOWN_USER,
builtin_groups.UNKNOWN_USER,
]
groups = groups_original.copy()
groups.sort(key=lambda x: sort_key.index(x) if x in sort_key else _get_sort_pos_of_custom_group(x))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_doap_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def tearDown(self) -> None:
testdata_dir = Path(f"project_data/{self.shortcode}")
if testdata_dir.is_dir():
shutil.rmtree(testdata_dir)

def test_doap_serialization(self):
doap1 = Doap(
target=DoapTarget(
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_doap_serialization(self):
mode="original",
)
deserialized_doaps = deserialize_doaps_of_project(
shortcode=self.shortcode,
shortcode=self.shortcode,
mode="original",
)
self._compare_doaps(deserialized_doaps[0], doap1)
Expand Down
1 change: 0 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class TestHelpers(unittest.TestCase):

def test_sort_groups(self) -> None:
groups_original = [
"http://www.knora.org/ontology/knora-admin#C_CustomGroup",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_oap_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def tearDown(self) -> None:
testdata_dir = Path(f"project_data/{self.shortcode}")
if testdata_dir.is_dir():
shutil.rmtree(testdata_dir)

def test_oap_serialization(self):
oap1 = Oap(
scope=PermissionScope.create(
Expand All @@ -41,7 +41,7 @@ def test_oap_serialization(self):
mode="original",
)
deserialized_oaps = deserialize_resource_oaps(
shortcode=self.shortcode,
shortcode=self.shortcode,
mode="original",
)
deserialized_oaps.sort(key=lambda oap: oap.object_iri)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestScope(unittest.TestCase):

def test_scope_validation_on_creation(self) -> None:
with self.assertRaisesRegex(ValueError, "must not occur in more than one field"):
PermissionScope.create(
Expand All @@ -21,8 +20,7 @@ def test_scope_validation_on_add_to_same_permission(self) -> None:
V={builtin_groups.UNKNOWN_USER, builtin_groups.KNOWN_USER},
)
with self.assertRaisesRegex(
ValueError,
"Group 'http://www.knora.org/ontology/knora-admin#ProjectAdmin' is already in permission 'CR'"
ValueError, "Group 'http://www.knora.org/ontology/knora-admin#ProjectAdmin' is already in permission 'CR'"
):
_ = scope.add("CR", builtin_groups.PROJECT_ADMIN)

Expand Down Expand Up @@ -56,7 +54,7 @@ def test_remove_inexisting_group(self) -> None:
)
with self.assertRaisesRegex(ValueError, "is not in permission 'D'"):
_ = scope.remove("D", builtin_groups.UNKNOWN_USER)

def test_remove_from_empty_perm(self) -> None:
scope = PermissionScope.create(
D={builtin_groups.PROJECT_ADMIN},
Expand All @@ -80,5 +78,6 @@ def test_remove_from_scope(self) -> None:
),
)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_scope_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def compare_scopes(
scope1: PermissionScope,
scope1: PermissionScope,
scope2: PermissionScope,
msg: str | None = None,
) -> None:
Expand Down

0 comments on commit bd6ea6a

Please sign in to comment.