forked from p15670423/monkey
UT: Add IJSONSerializable to representations test
This commit is contained in:
parent
4357251394
commit
ba9dda8d10
|
@ -5,6 +5,7 @@ from enum import Enum
|
|||
|
||||
import bson
|
||||
|
||||
from common.utils import IJSONSerializable
|
||||
from monkey_island.cc.services.representations import APIEncoder
|
||||
|
||||
|
||||
|
@ -72,3 +73,22 @@ def test_api_encoder_tuple():
|
|||
bogus_tuple = [{"my_tuple": (bogus_object1, bogus_object2, "string")}]
|
||||
expected_tuple = [{"my_tuple": ({"a": 1}, {"a": 2}, "string")}]
|
||||
assert json.dumps(expected_tuple) == json.dumps(bogus_tuple, cls=APIEncoder)
|
||||
|
||||
|
||||
class BogusClass(IJSONSerializable):
|
||||
def __init__(self, a):
|
||||
self.a = a
|
||||
|
||||
@classmethod
|
||||
def to_json(cls, class_object: IJSONSerializable) -> str:
|
||||
return json.dumps({"wacky": class_object.a})
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json_string: str) -> IJSONSerializable:
|
||||
pass
|
||||
|
||||
|
||||
def test_api_encoder_json_serializable():
|
||||
bogus_data = {"target": [BogusClass("macky")]}
|
||||
expected_result = {"target": [{"wacky": "macky"}]}
|
||||
assert json.dumps(expected_result) == json.dumps(bogus_data, cls=APIEncoder)
|
||||
|
|
Loading…
Reference in New Issue