コード例 #1
0
    def test_individual_serialization(self):
        """
        Make sure a marker with children as IDs
        which is the state they would be in after loading
        from the persistence layer, the children maintain
        through serialization
        """
        from furious.marker_tree.identity_utils import leaf_persistence_id_from_group_id
        from furious.marker_tree.marker import Marker
        from furious.job_utils import encode_callbacks
        from furious.tests.marker_tree import dummy_success_callback

        marker = Marker.from_dict({"id": "test", "callbacks": encode_callbacks({"success": dummy_success_callback})})
        self.assertEqual(marker.id, "test")
        marker2 = Marker.from_dict(marker.to_dict())
        self.assertEqual(marker2.to_dict(), marker.to_dict())

        root_marker = Marker(id="fun")
        children = []
        for x in xrange(10):
            children.append(Marker(id=leaf_persistence_id_from_group_id(root_marker.id, x)))

        root_marker.children = [marker.id for marker in children]

        root_dict = root_marker.to_dict()

        self.assertTrue("children" in root_dict.keys())
        self.assertEqual(len(children), len(root_dict["children"]))

        for index, child_id in enumerate(root_dict["children"]):
            self.assertEqual(children[index].id, child_id)

        reconstituted_root = Marker.from_dict(root_dict)

        self.assertEqual(len(reconstituted_root.children), len(reconstituted_root.children_to_dict()))
コード例 #2
0
    def test_graph_serialization(self):
        """
        Make sure when a marker tree graph is serialized
        (to_dict), it gets deserialized(from_dict) with
        all it's children intact as Markers
        """
        from furious.marker_tree.identity_utils import leaf_persistence_id_from_group_id
        from furious.marker_tree.marker import Marker

        root_marker = Marker(id="jolly")
        for x in xrange(3):
            root_marker.children.append(Marker(id=leaf_persistence_id_from_group_id(root_marker.id, x)))

        root_dict = root_marker.to_dict()

        self.assertTrue("children" in root_dict.keys())
        self.assertEqual(len(root_marker.children), len(root_dict["children"]))

        reconstituted_root = Marker.from_dict(root_dict)

        self.assertIsInstance(reconstituted_root, Marker)
        self.assertEqual(len(reconstituted_root.children), len(root_marker.children))
        self.assertEqual(len(reconstituted_root.children), len(reconstituted_root.children_to_dict()))
        for child in reconstituted_root.children:
            self.assertIsInstance(child, Marker)