def test_position_in_dict_ignored(self): a = Request(target=None, body={"a": 1, "b": 2}) b = Request(target=None, body={"b": 2, "a": 1}) c = Request(target=None, body={"a": 2, "b": 1}) assert Amf.get_representation(a) == Amf.get_representation(b) assert Amf.get_representation(a) != Amf.get_representation(c)
def test_limit_recursive_calls(self): a = CustomObject() a.secret = a encoded = generate_amf_request(request_body=[a]) decoded = decode(BytesIO(encoded)) try: Amf.get_representation(decoded) assert False, "should not be called" except Exception as e: assert "maximum number of calls reached" in str(e)
def test_can_parse_custom_object(self): a = CustomObject() a.secret = "a" encoded = generate_amf_request(request_body=[a]) decoded = decode(BytesIO(encoded)) assert Amf.get_representation(decoded) == \ '<Envelope>[<Request target=UserService>[<CustomObject>{"secret": "a"}</CustomObject>]</Request>]</Envelope>'
def amf_parse(self, string, environ): try: res = decode(BytesIO(string)) return urlencode({"request": Amf.get_representation(res)}) except Exception as e: import traceback traceback.print_exc() print(e) return None
def test_order_of_array_preserved(self): a = Request(target=None, body=[1, 2]) b = Request(target=None, body=[2, 1]) assert Amf.get_representation(a) != Amf.get_representation(b)
def test_parse_flex_request_with_envelope(self): encoded = generate_flex_request([{"the": "body"}]) decoded = decode(BytesIO(encoded)) assert Amf.get_representation(decoded) == \ '<Envelope>[<Request target=UserService>[<RemotingMessage operation=retrieveUser>[{"the": "body"}]</RemotingMessage>]</Request>]</Envelope>'
def test_parse_amf_request_with_envelope(self): encoded = generate_amf_request([{"the": "body"}]) decoded = decode(BytesIO(encoded)) assert Amf.get_representation(decoded) == \ '<Envelope>[<Request target=UserService>[{"the": "body"}]</Request>]</Envelope>'