diff --git a/keyosk/database/scope.py b/keyosk/database/scope.py index 2028f3b..d74c791 100644 --- a/keyosk/database/scope.py +++ b/keyosk/database/scope.py @@ -42,4 +42,4 @@ class KeyoskAccountScope(KeyoskBaseModel): with_client_secret = peewee.BooleanField(null=False) def __str__(self): - return f"ACL {self.permission.name}@{self.access_list.name} (scope:{'+'.join([item for item in ['server' if self.with_server_secret else '', 'client' if self.with_client_secret else ''] if item])})" + return f"Scope {self.permission.name}@{self.access_list.name} (with:{'+'.join([item for item in ['server' if self.with_server_secret else '', 'client' if self.with_client_secret else ''] if item])})" diff --git a/keyosk/serializers/scope.py b/keyosk/serializers/scope.py index 73a7ded..e38088b 100644 --- a/keyosk/serializers/scope.py +++ b/keyosk/serializers/scope.py @@ -1,5 +1,6 @@ from typing import Any from typing import Dict +from typing import Union import marshmallow as msh from playhouse import shortcuts @@ -18,12 +19,14 @@ class AccountScopeSerializer(msh.Schema): required=True, data_key="with-client-secret" ) - @staticmethod @msh.post_load - def _make_model(data: Dict[str, Any], **kwargs) -> KeyoskAccountScope: + def _make_model(self, data: Dict[str, Any], **kwargs) -> KeyoskAccountScope: return KeyoskAccountScope(**data) - @staticmethod @msh.pre_dump - def _unmake_model(data: KeyoskAccountScope, **kwargs) -> Dict[str, Any]: - return shortcuts.model_to_dict(data, recurse=False, backrefs=False,) + def _unmake_model( + self, data: Union[Dict[str, Any], KeyoskAccountScope], **kwargs + ) -> Dict[str, Any]: + if isinstance(data, KeyoskAccountScope): + return shortcuts.model_to_dict(data, recurse=False, backrefs=False) + return data diff --git a/tests/test_database_account.py b/tests/test_database_account.py index 533a6f6..bc39261 100644 --- a/tests/test_database_account.py +++ b/tests/test_database_account.py @@ -10,9 +10,15 @@ from keyosk import database def test_formatting(demo_database): - for account in database.KeyoskAccount.select(): + for account in ( + database.KeyoskAccount.select().join(database.KeyoskAccountScope).select() + ): assert str(account.uuid) in str(account) assert account.username in str(account) + for scope in account.scopes: + assert str(scope.uuid) not in str(scope) + assert scope.permission.name in str(scope) + assert scope.access_list.name in str(scope) def test_extras(demo_database): diff --git a/tests/test_serializers_account.py b/tests/test_serializers_account.py new file mode 100644 index 0000000..b2f03da --- /dev/null +++ b/tests/test_serializers_account.py @@ -0,0 +1,13 @@ +# pylint: disable=unused-argument,redefined-outer-name,unused-import +from fixtures import demo_database + +from keyosk import database +from keyosk import serializers + + +def test_compatibility(demo_database): + serializer = serializers.AccountSerializer() + + for domain in database.KeyoskAccount.select(): + dumped = serializer.dump(domain) + assert domain == serializer.load(dumped) diff --git a/tests/test_serializers_domain.py b/tests/test_serializers_domain.py index ade2942..892cc0e 100644 --- a/tests/test_serializers_domain.py +++ b/tests/test_serializers_domain.py @@ -1,12 +1,11 @@ # pylint: disable=unused-argument,redefined-outer-name,unused-import -import pytest from fixtures import demo_database from keyosk import database from keyosk import serializers -def test_roundtrip(demo_database): +def test_compatibility(demo_database): serializer = serializers.DomainSerializer() for domain in database.KeyoskDomain.select():