Common: Add to_mapping in Credentials

This commit is contained in:
Ilija Lazoroski 2022-07-08 17:26:23 +02:00
parent 77143ee765
commit 7062aaf261
2 changed files with 16 additions and 0 deletions

View File

@ -200,3 +200,13 @@ class Credentials:
:return: A JSON string representing an array of Credentials objects
"""
return "[" + ",".join([Credentials.to_json(c) for c in credentials]) + "]"
@staticmethod
def to_mapping(credentials: Credentials) -> Mapping:
"""
Serialize a Credentials object to Mapping
:param credentials: A Credentials object
:return: A mapping representing a Credentials object
"""
return CredentialsSchema().dump(credentials)

View File

@ -56,6 +56,12 @@ def test_credentials_serialization_json():
assert json.loads(serialized_credentials) == CREDENTIALS_DICT
def test_credentials_serialization_mapping():
serialized_credentials = Credentials.to_mapping(CREDENTIALS_OBJECT)
assert serialized_credentials == CREDENTIALS_DICT
def test_credentials_deserialization__from_mapping():
deserialized_credentials = Credentials.from_mapping(CREDENTIALS_DICT)