
# file structure heirarchy
$INSTANCE_HOME/Products/CMFManagedFile/tests/topfolder

topfolder
  folder1
    content11
  folder2
    folder21
    content221

# create a repository
tool.createNewRepostiory(id='default', path=$INSTANCE/Products/...,
                         removal_policy=SomePolicy())

# create a folder called 'externalfiles'
# using ScriptableTypeinfo
portal.externalfiles.invokeFactory('topfolder', repository='default',
                                   path='tests/topfolder')
assert 'folder1' in portal.topfolder.contentIdS()

# ensure that files really are on the filesystem
for obj in OFSWalker(externalfiles.topfolder):
    fs_path = path.join(obj.getRepo().base_path, obj.relative_path))
    if obj.isPrincipiaFolderish:
        assert os.isdir(fs_path)
    else:
        assert path.exists(fs_path)


# now ensure that passing in a invalid repository throws a exception

# ensure that adding a relative path doesnt escape otu of the repository
files.invokeFactory('somefolder', repository='default', path='../../passwd')

# import directoy from system, add a ZODB folder that doesnt exist
# on filesystem.  add content to the new folder that is a managed file

# get the tool to see if there are any differences from ODB/FS
# the tool should check a folder on down
obj = files.topfolder.folder1.content11
path = obj.getFullPath()
os.unlink(path)
missing_files = managed_file._compareToFS(files.topfolder)
failUnless(obj.getId() != missing_files[0])

# does import/export work on Managed file.
