===========================================
Tests for the AT Field Index migration tool
===========================================

Ed Crewe, ILRT (University of Bristol) 
May 2009

    >>> from Products.CMFCore.utils import getToolByName

Lets get the atfitool

    >>> request = getattr(self,'REQUEST',{}) 
    >>> smt = portal.site_migration
    >>> atfit = getattr(smt,'atfit',None)
    >>> atfit == None
    False

Make ourselves a manager so we can do some doc creation

   >>> self.setRoles(['Manager'])

Add a document

   >>> id = portal.invokeFactory(id='document', type_name='Document')
   >>> document = portal[id]
   >>> document.setTitle('Test document')
   
Publish it

   >>> wftool = getToolByName(portal, "portal_workflow")
   >>> wftool.doActionFor(folder,'publish')

Add some keywords

   >>> keywords = ['blue','orange','peaches'] 
   >>> mutator = atfit.getSetter(portal.document,'Subject')
   >>> mutator(keywords) 

Now we will get the portal_catalog

    >>> catalog = getToolByName(portal, 'portal_catalog')
    >>> catalog.manage_reindexIndex(ids=('Subject',))

Now check that the Subject keyword index contains these words

    >>> dict(catalog.Indexes['Subject'].items()).keys() == keywords
    True

Move one of the keywords using the tool

    >>> atfit.moveKeyword(portal,'blue','pink','Subject','Subject')
    1
    >>> 'pink' in dict(catalog.Indexes['Subject'].items()).keys()
    True

Delete one of the keywords using the tool

    >>> 'orange' in dict(catalog.Indexes['Subject'].items()).keys()
    True
    >>> atfit.moveKeyword(portal,'orange','','Subject')
    1 
    >>> 'orange' in dict(catalog.Indexes['Subject'].items()).keys()
    False


