forked from p34709852/monkey
Common: Add to_mapping in Credentials
This commit is contained in:
parent
77143ee765
commit
7062aaf261
|
@ -200,3 +200,13 @@ class Credentials:
|
||||||
:return: A JSON string representing an array of Credentials objects
|
:return: A JSON string representing an array of Credentials objects
|
||||||
"""
|
"""
|
||||||
return "[" + ",".join([Credentials.to_json(c) for c in credentials]) + "]"
|
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)
|
||||||
|
|
|
@ -56,6 +56,12 @@ def test_credentials_serialization_json():
|
||||||
assert json.loads(serialized_credentials) == CREDENTIALS_DICT
|
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():
|
def test_credentials_deserialization__from_mapping():
|
||||||
deserialized_credentials = Credentials.from_mapping(CREDENTIALS_DICT)
|
deserialized_credentials = Credentials.from_mapping(CREDENTIALS_DICT)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue