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)
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)
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)
def __init__(self, json_def={}): self.Westeros = ChunkyJson.deserialize(json_def, field="Westeros", classObject=Westeros, defaultValue=None)
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)
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)