-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |