def test_get_all_nodes_with_max_generation_and_limit_only_from_volume(
            self):
        """Test get_all_nodes wiht max_generation and limit for a UDF."""
        # make some files on a UDF...
        udf = self.factory.make_user_volume(
            owner=self.user._user, path='~/thepath/thename')
        udf_dao = DAOUserVolume(udf, self.user)
        udf_vgw = ReadWriteVolumeGateway(self.user, udf=udf_dao)
        udf_root_id = udf_vgw.get_root().id
        # make files on the root and make sure only they are returned
        dirs = []
        files = []
        for i in range(10):
            d = udf_vgw.make_subdirectory(udf_root_id, '%sd' % i)
            f = udf_vgw.make_file(d.id, '%sfile.txt' % i)
            dirs.append(d)
            files.append(f)
        nodes = dirs + files
        nodes.append(udf_vgw.get_root())
        all_nodes = udf_vgw.get_all_nodes()
        self.assertEqual(len(all_nodes), 21)
        # the lists are not sorted so not equal
        self.assertNotEquals(all_nodes, nodes)
        # sort them in the right order
        nodes.sort(key=attrgetter('path', 'name'))
        self.assertEqual(all_nodes, nodes)

        # with a max_generation
        nodes_gen_10 = udf_vgw.get_all_nodes(max_generation=10)
        self.assertEqual(
            nodes_gen_10, [n for n in nodes if n.generation <= 10])
        nodes_gen_20 = udf_vgw.get_all_nodes(max_generation=20)
        self.assertEqual(nodes_gen_20, nodes)

        # with max_generation and limit
        nodes_limit_5 = udf_vgw.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 += udf_vgw.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 += udf_vgw.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 gen.
        nodes_limit_10 = udf_vgw.get_all_nodes(max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes[:10])
        last_node = nodes_limit_10[-1]
        nodes_limit_10 += udf_vgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes[:20])
        last_node = nodes_limit_10[-1]
        nodes_limit_10 += udf_vgw.get_all_nodes(
            start_from_path=(last_node.path, last_node.name),
            max_generation=20, limit=10)
        self.assertEqual(nodes_limit_10, nodes)