示例#1
0
 def __init__(self, json_def={}):
     self.Factions = ChunkyJson.deserialize(json_def,
                                            field="Factions",
                                            classObject=list,
                                            defaultValue=None)
     self.IsAtWar = ChunkyJson.deserialize(json_def,
                                           field="IsAtWar",
                                           defaultValue=False)
示例#2
0
    def test_serialize_array(self):
        json = {
            "Westeros":
                {
                    "Factions": "derp",
                    "NorthFamilies": [
                        {
                            "Name": "Starks",
                            "Masters": True
                        },
                        {
                            "Name": "Mormont"
                        }
                    ]
                }
        }
        classed_objs = GameOfThrones(json)

        self.assertEqual(classed_objs.Westeros.Factions, json["Westeros"]["Factions"])
        self.assertEqual(len(classed_objs.Westeros.NorthFamilies), len(classed_objs.Westeros.NorthFamilies))
        self.assertEqual(classed_objs.Westeros.NorthFamilies[0].Name, json["Westeros"]["NorthFamilies"][0]["Name"])
        serialized_obj = ChunkyJson.serialize(classed_objs)
        self.assertEqual(serialized_obj, serialized_obj)
示例#3
0
    def test_serialize_array(self):
        json = {
            "Westeros": {
                "Factions":
                ["DragonLady", "TooMuchLoveBrothers", "SuperRightGuy"]
            }
        }
        classed_objs = GameOfThrones(json)
        self.assertEqual(classed_objs.Westeros.Factions[0],
                         json["Westeros"]["Factions"][0])

        # Default Value is False
        self.assertFalse(classed_objs.Westeros.IsAtWar)

        classed_objs.Westeros.war_is_on()
        self.assertTrue(classed_objs.Westeros.IsAtWar)

        classed_objs.Westeros.dragons_kicked_ass()
        self.assertFalse(classed_objs.Westeros.IsAtWar)

        serialized_obj = ChunkyJson.serialize(classed_objs)

        # TODO proper dict testing
        self.assertEqual(serialized_obj, serialized_obj)
示例#4
0
 def __init__(self, json_def={}):
     self.Westeros = ChunkyJson.deserialize(json_def,
                                            field="Westeros",
                                            classObject=Westeros,
                                            defaultValue=None)
示例#5
0
 def __init__(self, json_def={}):
     self.Name = ChunkyJson.deserialize(json_def, field="Name", defaultValue=None)
     self.Masters = ChunkyJson.deserialize(json_def, field="Masters", defaultValue=None)
示例#6
0
 def __init__(self, json_def={}):
     self.Factions = ChunkyJson.deserialize(json_def, field="Factions", defaultValue=None)
     self.NorthFamilies = ChunkyJson.deserialize(json_def, field="NorthFamilies", classObject=list, childType = Family, defaultValue=None)