import transaction
from floop.migration.migrate import migrate
from floop.migration.tests.base import MigrationTestCase
from Products.ZWiki import addZWikiPage
class TestThisMigration(MigrationTestCase):
"""Test the migration from oldtype to newtype
"""
def afterSetUp(self):
#Create an object to migrate
self.membership = self.portal.portal_membership
self.membership.addMember('new_owner', 'secret', ['Member'], [])
self.folder.manage_addProduct['ZWiki'].manage_addZWikiPage('TestPage')
self.folder.TestPage.setText('Some random wiki text\n\n * With some bullets\n')
self.folder.TestPage.creator = 'new_owner'
#Need this to avoid copy errors
transaction.savepoint(optimistic=True)
def testItemMigrated(self):
#portal_type and meta_type should be of type newtype
oldItem = self.folder.TestPage
###Before the migration
self.assertEqual(oldItem.portal_type, "Wiki Page",
"oldItem.portal_type was %s, but should have been blah" %
oldItem.portal_type)
self.assertEqual(oldItem.meta_type, "ZWiki Page",
"oldItem.meta_type was %s, but should have been blah" %
oldItem.meta_type)
###Run the migration
old = migrate(self.portal)
###After the migration
#Recopy the item, the old object held on to that old type info
newItem = self.folder.TestPage
#The item should now have the new types
self.assertEqual(newItem.portal_type, "Document",
"newItem.portal_type was %s, but should have been blah" %
newItem.portal_type)
self.assertEqual(newItem.meta_type, "ATDocument",
"newItem.meta_type was %s, but should have been blah" %
newItem.meta_type)
#Make sure the field values transferred to the new fields
# import pdb; pdb.set_trace()
self.assertEqual(newItem.getField('text').getContentType(newItem), 'text/structured')
self.assertEqual(newItem.getText(), '<h2>Some random wiki text</h2>\n\n<ul>\n<li>With some bullets</li>\n\n</ul>\n',
'text field did not transfer')
self.assertEqual(newItem.Creator(), 'new_owner', 'Owner did not transfer.')
def test_suite():
from unittest import TestSuite
from unittest import makeSuite
suite = TestSuite()
suite.addTest(makeSuite(TestThisMigration)) #Class from above
return suite