From dc2e5232f701f215d27e462befc18c17d2db194a Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 3 Jan 2010 17:36:01 +0000 Subject: [PATCH] fix migration tests. do not use transactions during unit testing. svn path=/plone.app.discussion/trunk/; revision=32805 --- plone/app/discussion/browser/migration.py | 20 ++++++++++++++------ plone/app/discussion/tests/test_migration.py | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plone/app/discussion/browser/migration.py b/plone/app/discussion/browser/migration.py index 545eab2..886c8e5 100644 --- a/plone/app/discussion/browser/migration.py +++ b/plone/app/discussion/browser/migration.py @@ -34,8 +34,15 @@ class View(BrowserView): out = [] self.total_comments_migrated = 0 self.total_comments_deleted = 0 - - transaction.begin() + + dry_run = self.request.has_key("dry_run") + + # This is for testing only. + # Do not use transactions during a test. + test = self.request.has_key("test") + + if not test: + transaction.begin() catalog = getToolByName(context, 'portal_catalog') dtool = context.portal_discussion @@ -137,7 +144,8 @@ class View(BrowserView): log("Something went wrong during migration. The number of migrated comments (%s)\ differs from the number of deleted comments (%s)." % (self.total_comments_migrated, self.total_comments_deleted)) - transaction.abort() + if not test: + transaction.abort() log("Abort transaction") log("\n") @@ -151,10 +159,10 @@ class View(BrowserView): log("%s comments could not be migrated." % (count_comments_old - self.total_comments_migrated)) log("Please make sure your portal catalog is up-to-date.") - if self.request.has_key("dry_run"): + if dry_run and not test: transaction.abort() log("Dry run") log("Abort transaction") - - transaction.commit() + if not test: + transaction.commit() return '\n'.join(out) diff --git a/plone/app/discussion/tests/test_migration.py b/plone/app/discussion/tests/test_migration.py index d428730..32b8793 100644 --- a/plone/app/discussion/tests/test_migration.py +++ b/plone/app/discussion/tests/test_migration.py @@ -29,6 +29,7 @@ class MigrationTest(PloneTestCase): self.workflow.doActionFor(self.portal.doc, 'publish') request = self.app.REQUEST + request.set("test", True) context = getattr(self.portal, 'doc') self.view = View(context, request) self.workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow')