1
0
mirror of https://github.com/enpaul/keyosk.git synced 2024-11-24 23:47:49 +00:00

Add tests for account serializer

Fix bugs with account scope de/serializing
Fix bugs with domain serializer tests
Fix bugs with database account tests
This commit is contained in:
Ethan Paul 2020-03-12 22:58:33 -04:00
parent f59afcccf7
commit a302d69c7a
5 changed files with 30 additions and 9 deletions

View File

@ -42,4 +42,4 @@ class KeyoskAccountScope(KeyoskBaseModel):
with_client_secret = peewee.BooleanField(null=False) with_client_secret = peewee.BooleanField(null=False)
def __str__(self): 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])})"

View File

@ -1,5 +1,6 @@
from typing import Any from typing import Any
from typing import Dict from typing import Dict
from typing import Union
import marshmallow as msh import marshmallow as msh
from playhouse import shortcuts from playhouse import shortcuts
@ -18,12 +19,14 @@ class AccountScopeSerializer(msh.Schema):
required=True, data_key="with-client-secret" required=True, data_key="with-client-secret"
) )
@staticmethod
@msh.post_load @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) return KeyoskAccountScope(**data)
@staticmethod
@msh.pre_dump @msh.pre_dump
def _unmake_model(data: KeyoskAccountScope, **kwargs) -> Dict[str, Any]: def _unmake_model(
return shortcuts.model_to_dict(data, recurse=False, backrefs=False,) 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

View File

@ -10,9 +10,15 @@ from keyosk import database
def test_formatting(demo_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 str(account.uuid) in str(account)
assert account.username 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): def test_extras(demo_database):

View File

@ -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)

View File

@ -1,12 +1,11 @@
# pylint: disable=unused-argument,redefined-outer-name,unused-import # pylint: disable=unused-argument,redefined-outer-name,unused-import
import pytest
from fixtures import demo_database from fixtures import demo_database
from keyosk import database from keyosk import database
from keyosk import serializers from keyosk import serializers
def test_roundtrip(demo_database): def test_compatibility(demo_database):
serializer = serializers.DomainSerializer() serializer = serializers.DomainSerializer()
for domain in database.KeyoskDomain.select(): for domain in database.KeyoskDomain.select():