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 addZWikiPage(self.folder, 'test_oldtype', 'Test Title') # self.folder.invokeFactory('Wiki Page', 'test_oldtype') #A direct assignment doesn't work here, you have to use the setter or #the value will come out blank. #The field migrator uses obj.getRawFieldName() self.folder.test_oldtype.setText('Some random wiki text\n\n * With some bullets\n') #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.test_oldtype ###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.test_oldtype #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') def test_suite(): from unittest import TestSuite from unittest import makeSuite suite = TestSuite() suite.addTest(makeSuite(TestThisMigration)) #Class from above return suite