Skip to content

Commit

Permalink
test oap serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 11, 2023
1 parent 997bc60 commit 6b5a61a
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_oap_serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import shutil
import unittest
from pathlib import Path

from dsp_permissions_scripts.models import scope
from dsp_permissions_scripts.models.groups import BuiltinGroup
from dsp_permissions_scripts.models.oap import Oap
from dsp_permissions_scripts.utils.oap_serialize import (
deserialize_resource_oaps,
serialize_resource_oaps,
)
from tests.test_scope_serialization import compare_scopes


class TestOapSerialization(unittest.TestCase):
shortcode = "1234"

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=scope.PermissionScope.create(
CR=[BuiltinGroup.PROJECT_ADMIN],
V=[BuiltinGroup.PROJECT_MEMBER],
),
object_iri=f"http://rdfh.ch/{self.shortcode}/resource-1",
)
oap2 = Oap(
scope=scope.PermissionScope.create(
D=[BuiltinGroup.SYSTEM_ADMIN],
M=[BuiltinGroup.KNOWN_USER],
),
object_iri=f"http://rdfh.ch/{self.shortcode}/resource-2",
)
serialize_resource_oaps(
resource_oaps=[oap1, oap2],
shortcode=self.shortcode,
mode="original",
)
deserialized_oaps = deserialize_resource_oaps(
shortcode=self.shortcode,
mode="original",
)
self._compare_oaps(deserialized_oaps[0], oap1)
self._compare_oaps(deserialized_oaps[1], oap2)

def _compare_oaps(self, oap1: Oap, oap2: Oap) -> None:
compare_scopes(oap1.scope, oap2.scope)
self.assertEqual(oap1.object_iri, oap2.object_iri)


if __name__ == "__main__":
unittest.main()

0 comments on commit 6b5a61a

Please sign in to comment.