Beispiel #1
0
 def test_deserialize_properties_raises_on_unknown_signature_keys(self):
     with self.assertRaises(AssertionError):
         deserialize.deserialize_properties({
             "foo": {
                 deserialize.SPECIAL_SIG_KEY: "foobar",
             },
         })
Beispiel #2
0
 def test_deserialize_properties_raises_on_unsupported_asset_values(self):
     with self.assertRaises(AssertionError):
         deserialize.deserialize_properties({
             "foo": {
                 deserialize.SPECIAL_SIG_KEY: deserialize.SPECIAL_ASSET_SIG,
             },
         })
Beispiel #3
0
    def unmarshalls_fully(self, obj: Any, assertObj: Callable[[Any], None]):
        props = {
            "regular": "a normal value",
            "list": ["a normal value", "another value", obj],
            "map": {
                "regular": "a normal value",
                "obj": obj
            },
            "mapWithList": {
                "regular": "a normal value",
                "list": ["a normal value", obj],
            },
            "listWithMap": [
                {
                    "regular": "a normal value",
                    "obj": obj,
                },
            ],
        }

        result = deserialize.deserialize_properties(props)

        # Regular is returned as is.
        self.assertEqual(result["regular"], "a normal value")

        # One of the elements in the list was a special object.
        self.assertNotIn(deserialize.SPECIAL_SIG_KEY, result["list"])
        self.assertEqual(result["list"][0], "a normal value")
        self.assertEqual(result["list"][1], "another value")
        assertObj(result["list"][2])

        # One of the values of the map was a special object.
        self.assertNotIn(deserialize.SPECIAL_SIG_KEY, result["map"])
        self.assertEqual(result["map"]["regular"], "a normal value")
        assertObj(result["map"]["obj"])

        # The nested map had a special object in one of the values.
        self.assertNotIn(deserialize.SPECIAL_SIG_KEY, result["mapWithList"])
        self.assertEqual(result["mapWithList"]["regular"], "a normal value")
        self.assertEqual(result["mapWithList"]["list"][0], "a normal value")
        assertObj(result["mapWithList"]["list"][1])

        # An array element contained a special object (via a nested map).
        self.assertNotIn(deserialize.SPECIAL_SIG_KEY, result["listWithMap"])
        self.assertEqual(result["listWithMap"][0]["regular"], "a normal value")
        assertObj(result["listWithMap"][0]["obj"])