'Check we can download files references in a collection.'

def testDownloadCollectionWithFlattenOption(self):

    fd = sequential_collection.GeneralIndexedCollection(self.collection_urn, token=self.token)
    fd.Add(rdfvalue.RDFURN(self.out.Add('testfile1')))
    fd.Add(rdf_client.StatEntry(pathspec=rdf_paths.PathSpec(path='testfile2', pathtype='OS')))
    fd.Add(rdf_file_finder.FileFinderResult(stat_entry=rdf_client.StatEntry(pathspec=rdf_paths.PathSpec(path='testfile5', pathtype='OS'))))
    with utils.TempDirectory() as tmpdir:
        export_utils.DownloadCollection(self.collection_urn, tmpdir, overwrite=True, dump_client_info=True, flatten=True, token=self.token, max_threads=2)
        symlinks = os.listdir(os.path.join(tmpdir, 'files'))
        self.assertEqual(len(symlinks), 3)
        self.assertListEqual(sorted(symlinks), ['C.1000000000000000_fs_os_testfile1', 'C.1000000000000000_fs_os_testfile2', 'C.1000000000000000_fs_os_testfile5'])
        self.assertEqual(os.readlink(os.path.join(tmpdir, 'files', 'C.1000000000000000_fs_os_testfile1')), os.path.join(tmpdir, 'C.1000000000000000', 'fs', 'os', 'testfile1'))
