Exemplo n.º 1
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)
Exemplo n.º 2
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)