Managed File Tool
=================

The tool keeps track of repositories and acts as some sort of
'trashcan' when objects get deleted. It can purge deleted objects from
the trashcan after a certain time has passed.

Give test user the Manager role and login:

  >>> from Testing.ZopeTestCase import user_name, user_password, folder_name
  >>> self.setRoles(['Manager'])
  >>> self.login(user_name)
  >>> request = self.portal.REQUEST

Check for tool's available policies:

  >>> from Products.CMFManagedFile.config import *
  >>> del_policies = self.tool.availableDeletePolicies()
  >>> DELETE_IMMEDIATE in del_policies
  True

  >>> DELETE_DEFERRED in del_policies
  True

  >>> DELETE_MANUAL in del_policies
  True

  >>> GENERATE_POLICY in del_policies
  False

  >>> fname_policies = self.tool.availableFilenamePolicies()
  >>> DELETE_IMMEDIATE in fname_policies
  False

  >>> GENERATE_POLICY in fname_policies
  True

  >>> ORIGINAL_POLICY in fname_policies
  True

  >>> path_policies = self.tool.availablePathPolicies()
  >>> FS_BASE in path_policies
  True

  >>> FS_RELATIVE in path_policies
  True

  >>> FS_PORTAL_TYPE in path_policies
  True

Check for default settings and getting properties through the
PropertySheet API:

  >>> from Products.CMFManagedFile.tool import DEFAULT_PATH
  >>> self.tool.getProperty('basedir') == DEFAULT_PATH
  True

  >>> self.tool.getBaseDir() == DEFAULT_PATH
  True

  >>> self.tool.getPathPolicy() == FS_PHYSICAL
  True

  >>> self.tool.getProperty('path_policy') == FS_PHYSICAL
  True

  >>> self.tool.getFilenamePolicy() == ORIGINAL_POLICY
  True

  >>> self.tool.getProperty('filename_policy') == ORIGINAL_POLICY
  True

  >>> self.tool.getDays() == self.tool.getProperty('purgeDays') == 30
  True

  >>> self.tool.getTempDays() == self.tool.getProperty('tempDays') == 2
  True

  >>> self.tool.edit(path_policy=FS_BASE,
  ...                filename_policy=GENERATE_POLICY,
  ...                days=12, temp=1)

  >>> self.tool.getDays() == self.tool.getProperty('purgeDays') == 12
  True

  >>> self.tool.getTempDays() == self.tool.getProperty('tempDays') == 1
  True

  >>> self.tool.getPathPolicy() == FS_BASE
  True

  >>> self.tool.getProperty('path_policy') == FS_BASE
  True

  >>> self.tool.getFilenamePolicy() == GENERATE_POLICY
  True

  >>> self.tool.getProperty('filename_policy') == GENERATE_POLICY
  True

A repository should exist by default, and it should use the tool's
defaults for path, path_policy and filename_policy:

  >>> repos = self.tool.getRepositories()
  >>> 'default' in repos.keys()
  True

  >>> p, fs, fn = repos['default']
  >>> p == DEFAULT_PATH
  True

  >>> fs == FS_BASE
  True

  >>> fn == GENERATE_POLICY
  True

Should be able to change the default repository to point to a
different path, and use different path and filename policies:

  >>> repo = self.tool.getRepository('default')
  >>> repo.edit(path='/tmp', path_policy=FS_RELATIVE,
  ...           filename_policy=ORIGINAL_POLICY)

  >>> repos = self.tool.getRepositories()

  >>> p, fs, fn = repos['default']
  >>> p == '/tmp'
  True

  >>> fs == FS_RELATIVE
  True

  >>> fn == ORIGINAL_POLICY
  True

And if we set the path to an empty string, it should go back to the
default path configured on the tool, while retaining the other
settings:

  >>> repo = self.tool.getRepository('default')
  >>> repo.edit(path='')
  >>> repos = self.tool.getRepositories()

  >>> p, fs, fn = repos['default']
  >>> p == DEFAULT_PATH
  True

  >>> fs == FS_RELATIVE
  True

  >>> fn == ORIGINAL_POLICY
  True

  >>> self.tool.getRepositoryInfo('default') == repos['default']
  True

Adding a new repository is an easy task:

  >>> repo = self.tool.addRepository('temp',
  ...   path='/tmp',
  ...   path_policy=FS_BASE,
  ...   filename_policy=ORIGINAL_POLICY)

  >>> print len(self.tool.getRepositories())
  2

  >>> p, fs, fn = self.tool.getRepositories()['temp']
  >>> p == '/tmp'
  True

  >>> fs == FS_BASE
  True

  >>> fn == ORIGINAL_POLICY
  True

One can also add a new repository through the web, using the ZMI. The
ZMI calls manage_editRepositories:

  >>> repo = self.tool.manage_editRepositories(
  ...   repository_name='another',
  ...   add_repository=True,
  ...   repository_path='/tmp',
  ...   repository_policy=FS_BASE,
  ...   filename_policy=ORIGINAL_POLICY,
  ...   visible=True)

  >>> print len(self.tool.getRepositories())
  3

  >>> p, fs, fn = self.tool.getRepositories()['another']
  >>> p == '/tmp'
  True

  >>> fs == FS_BASE
  True

  >>> fn == ORIGINAL_POLICY
  True

Now remove the newly added repository through the same method:

  >>> repo = self.tool.manage_editRepositories(
  ...   delete_repository=True,
  ...   chosen=('another',))

  >>> print len(self.tool.getRepositories())
  2

Removing twice shouldn't blow:

  >>> repo = self.tool.manage_editRepositories(
  ...   delete_repository=True,
  ...   chosen=('another',))

  >>> print len(self.tool.getRepositories())
  2

Remove through the base API:

  >>> self.tool.delRepository('temp')

  >>> print len(self.tool.getRepositories())
  1

Get a non-existing repository should return default value:

  >>> marker = object()
  >>> self.tool.getRepository('foobar', marker) == marker
  True
