def test_get_all_nodes_with_max_generation_and_limit(self):
        """Test get_all_nodes with max_generation and limit."""
        share_dao = SharedDirectory(self.rw_share, by_user=self.sharer)
        sgw = ReadWriteVolumeGateway(self.user, share=share_dao)
        root = sgw.get_root()
        root_id = root.id
        # make dirs and put files in them
        dirs = []
        files = []
        for i in range(10):
            d = sgw.make_subdirectory(root_id, '%sd' % i)
            f = sgw.make_file(d.id, '%sfile.txt' % i)
            dirs.append(d)
            files.append(f)
        all_nodes = dirs + files
        all_nodes.append(root)
        # sort them in the right order
        all_nodes.sort(key=attrgetter('path', 'name'))
        # with max_generation and limit
        # first get all the nodes at gen_10
        nodes_gen_10 = sgw.get_all_nodes(max_generation=10)
        # now get them in chunks
        nodes_limit_5 = sgw.get_all_nodes(max_generation=10, limit=5)
        self.assertEqual(nodes_limit_5, nodes_gen_10[:5])
        last_node = nodes_limit_5[-1]
        nodes_limit_5 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=10, limit=5)
        self.assertEqual(nodes_limit_5, nodes_gen_10[:10])
        last_node = nodes_limit_5[-1]
        nodes_limit_5 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=10, limit=5)
        self.assertEqual(nodes_limit_5, nodes_gen_10)

        # same but with the last generation
        nodes_20 = [n for n in all_nodes if n.generation <= 20]
        nodes_limit_10 = sgw.get_all_nodes(max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes_20[:10])
        last_node = nodes_limit_10[-1]
        nodes_limit_10 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes_20[:20])
        last_node = nodes_limit_10[-1]
        nodes_limit_10 += sgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes_20)