mirror of
https://github.com/enpaul/keyosk.git
synced 2024-12-25 17:23:31 +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:
parent
f59afcccf7
commit
a302d69c7a
@ -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])})"
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
13
tests/test_serializers_account.py
Normal file
13
tests/test_serializers_account.py
Normal 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)
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user