From 79f0064502db564710da42095cc80f8ed313cc11 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Thu, 22 Dec 2016 15:04:14 +0100 Subject: [PATCH] remove unittest2 --- CHANGES.rst | 3 + plone/app/iterate/base.py | 99 +++++++++++++++++++ plone/app/iterate/configure.zcml | 2 +- plone/app/iterate/dexterity/policy.py | 62 ++++++------ plone/app/iterate/policy.py | 84 ++++------------ .../portal_placeful_workflow/working-copy.xml | 2 +- plone/app/iterate/testing.py | 3 +- plone/app/iterate/tests/test_interfaces.py | 2 +- plone/app/iterate/tests/test_iterate.py | 2 +- 9 files changed, 156 insertions(+), 103 deletions(-) create mode 100644 plone/app/iterate/base.py diff --git a/CHANGES.rst b/CHANGES.rst index f28d97d..5d4bda7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,9 @@ New features: Bug fixes: +- Do not use unittest2 anymore. + [jensens] + - Cleanup: isort, zca decorators, etc. [jensens] diff --git a/plone/app/iterate/base.py b/plone/app/iterate/base.py new file mode 100644 index 0000000..c2e895b --- /dev/null +++ b/plone/app/iterate/base.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +################################################################## +# +# (C) Copyright 2006-2007 ObjectRealms, LLC +# (C) Copyright 2007-2017 Plone Foundation +# All Rights Reserved +# +# This file is part of iterate. +# +# iterate is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# iterate is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with CMFDeployment; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +################################################################## +""" +Base Checkin Checkout Policy For Content + +""" + +from Acquisition import aq_inner +from Acquisition import aq_parent +from plone.app.iterate.event import BeforeCheckoutEvent +from plone.app.iterate.event import CancelCheckoutEvent +from plone.app.iterate.event import CheckoutEvent +from plone.app.iterate.interfaces import ICheckinCheckoutPolicy +from plone.app.iterate.interfaces import IObjectCopier +from plone.app.iterate.util import get_storage +from zope.component import queryAdapter +from zope.event import notify +from zope.interface import implementer + + +@implementer(ICheckinCheckoutPolicy) +class CheckinCheckoutBasePolicyAdapter(object): + """Base Checkin Checkout Policy For Content + + - on checkout context is the baseline + - on checkin context is the working copy. + + """ + + # used when creating baseline version for first time + default_base_message = 'Created Baseline' + + def __init__(self, context): + self.context = context + + def checkin(self, checkin_message): + raise NotImplemented() + + def checkout(self, container): + # see interface + notify(BeforeCheckoutEvent(self.context)) + + # use the object copier to checkout the content to the container + copier = queryAdapter(self.context, IObjectCopier) + working_copy, relation = copier.copyTo(container) + + # publish the event for any subscribers + notify(CheckoutEvent(self.context, working_copy, relation)) + + # finally return the working copy + return working_copy + + def cancelCheckout(self): + # see interface + + # get the baseline + baseline = self._getBaseline() + + # publish an event + notify(CancelCheckoutEvent(self.context, baseline)) + + # delete the working copy + wc_container = aq_parent(aq_inner(self.context)) + wc_container.manage_delObjects([self.context.getId()]) + + return baseline + + ################################# + # Checkin Support Methods + + def getBaseline(self): + raise NotImplemented() + + def getWorkingCopy(self): + raise NotImplemented() + + def getProperties(self, obj, default=None): + return get_storage(obj, default=default) diff --git a/plone/app/iterate/configure.zcml b/plone/app/iterate/configure.zcml index 7d15fdc..39a2f62 100644 --- a/plone/app/iterate/configure.zcml +++ b/plone/app/iterate/configure.zcml @@ -96,6 +96,6 @@ /> - + diff --git a/plone/app/iterate/dexterity/policy.py b/plone/app/iterate/dexterity/policy.py index a7496fc..14d1ea4 100644 --- a/plone/app/iterate/dexterity/policy.py +++ b/plone/app/iterate/dexterity/policy.py @@ -1,63 +1,57 @@ # -*- coding: utf-8 -*- -from plone.app import iterate +from plone.app.iterate.base import CheckinCheckoutBasePolicyAdapter +from plone.app.iterate.dexterity.interfaces import IDexterityIterateAware from plone.app.iterate.dexterity.utils import get_baseline from plone.app.iterate.dexterity.utils import get_checkout_relation from plone.app.iterate.dexterity.utils import get_relations from plone.app.iterate.dexterity.utils import get_working_copy +from plone.app.iterate.event import AfterCheckinEvent +from plone.app.iterate.event import CheckinEvent +from plone.app.iterate.interfaces import CheckinException +from plone.app.iterate.interfaces import IObjectCopier from plone.app.iterate.util import get_storage -from zope import component +from zope.component import adapter +from zope.component import queryAdapter from zope.event import notify -from zope.interface import implementer -@implementer(iterate.interfaces.ICheckinCheckoutPolicy) -class CheckinCheckoutPolicyAdapter( - iterate.policy.CheckinCheckoutPolicyAdapter -): +@adapter(IDexterityIterateAware) +class CheckinCheckoutPolicyAdapter(CheckinCheckoutBasePolicyAdapter): """ Dexterity Checkin Checkout Policy """ + def checkin(self, checkin_message): + # get the baseline for this working copy, raise if not found + baseline = self._getBaseline() + # get a hold of the relation object + relation = self._get_relation_to_baseline() + # publish the event for subscribers, early because contexts are about + # to be manipulated + notify(CheckinEvent(self.context, baseline, relation, checkin_message)) + # merge the object back to the baseline with a copier + copier = queryAdapter(self.context, IObjectCopier) + new_baseline = copier.merge() + # don't need to unlock the lock disappears with old baseline deletion + notify(AfterCheckinEvent(new_baseline, checkin_message)) + return new_baseline + def _get_relation_to_baseline(self): # do we have a baseline in our relations? relations = get_relations(self.context) - if relations and not len(relations) == 1: - raise iterate.interfaces.CheckinException( - 'Baseline count mismatch') - + raise CheckinException('Baseline count mismatch') if not relations or not relations[0]: - raise iterate.interfaces.CheckinException( - 'Baseline has disappeared') + raise CheckinException('Baseline has disappeared') return relations[0] def _getBaseline(self): baseline = get_baseline(self.context) if not baseline: - raise iterate.interfaces.CheckinException( - 'Baseline has disappeared') + raise CheckinException('Baseline has disappeared') return baseline - def checkin(self, checkin_message): - # get the baseline for this working copy, raise if not found - baseline = self._getBaseline() - # get a hold of the relation object - relation = self._get_relation_to_baseline() - # publish the event for subscribers, early because contexts are about - # to be manipulated - notify(iterate.event.CheckinEvent(self.context, - baseline, - relation, - checkin_message)) - # merge the object back to the baseline with a copier - copier = component.queryAdapter(self.context, - iterate.interfaces.IObjectCopier) - new_baseline = copier.merge() - # don't need to unlock the lock disappears with old baseline deletion - notify(iterate.event.AfterCheckinEvent(new_baseline, checkin_message)) - return new_baseline - def getBaseline(self): return get_baseline(self.context) diff --git a/plone/app/iterate/policy.py b/plone/app/iterate/policy.py index fc34ebd..ac0fa4e 100644 --- a/plone/app/iterate/policy.py +++ b/plone/app/iterate/policy.py @@ -24,55 +24,28 @@ Archetypes Checkin Checkout Policy For Content """ - -from Acquisition import aq_inner -from Acquisition import aq_parent +from plone.app.iterate.base import CheckinCheckoutBasePolicyAdapter +from plone.app.iterate.event import AfterCheckinEvent +from plone.app.iterate.event import CheckinEvent +from plone.app.iterate.interfaces import CheckinException +from plone.app.iterate.interfaces import IIterateAware +from plone.app.iterate.interfaces import IObjectCopier +from plone.app.iterate.relation import WorkingCopyRelation from plone.app.iterate.util import get_storage from Products.Archetypes.interfaces import IReferenceable -from relation import WorkingCopyRelation -from zope import component +from zope.component import adapter +from zope.component import queryAdapter from zope.event import notify -from zope.interface import implementer - -import event -import interfaces - - -@implementer(interfaces.ICheckinCheckoutPolicy) -@component.adapter(interfaces.IIterateAware) -class CheckinCheckoutPolicyAdapter(object): - """ - Default Checkin Checkout Policy For Content - - on checkout context is the baseline - on checkin context is the working copy. - This default Policy works with Archetypes. +@adapter(IIterateAware) +class CheckinCheckoutPolicyAdapter(CheckinCheckoutBasePolicyAdapter): + """Checkin Checkout Policy For Archetypes Content - dexterity folder has dexterity compatible one + - on checkout context is the baseline + - on checkin context is the working copy. """ - # used when creating baseline version for first time - default_base_message = 'Created Baseline' - - def __init__(self, context): - self.context = context - - def checkout(self, container): - # see interface - notify(event.BeforeCheckoutEvent(self.context)) - - # use the object copier to checkout the content to the container - copier = component.queryAdapter(self.context, interfaces.IObjectCopier) - working_copy, relation = copier.copyTo(container) - - # publish the event for any subscribers - notify(event.CheckoutEvent(self.context, working_copy, relation)) - - # finally return the working copy - return working_copy - def checkin(self, checkin_message): # see interface @@ -81,40 +54,25 @@ def checkin(self, checkin_message): # get a hold of the relation object wc_ref = self.context.getReferenceImpl( - WorkingCopyRelation.relationship)[0] + WorkingCopyRelation.relationship + )[0] # publish the event for subscribers, early because contexts are about # to be manipulated - notify(event.CheckinEvent(self.context, - baseline, wc_ref, checkin_message)) + notify(CheckinEvent(self.context, baseline, wc_ref, checkin_message)) # merge the object back to the baseline with a copier # XXX by gotcha # bug we should or use a getAdapter call or test if copier is None - copier = component.queryAdapter(self.context, interfaces.IObjectCopier) + copier = queryAdapter(self.context, IObjectCopier) new_baseline = copier.merge() # don't need to unlock the lock disappears with old baseline deletion - notify(event.AfterCheckinEvent(new_baseline, checkin_message)) + notify(AfterCheckinEvent(new_baseline, checkin_message)) return new_baseline - def cancelCheckout(self): - # see interface - - # get the baseline - baseline = self._getBaseline() - - # publish an event - notify(event.CancelCheckoutEvent(self.context, baseline)) - - # delete the working copy - wc_container = aq_parent(aq_inner(self.context)) - wc_container.manage_delObjects([self.context.getId()]) - - return baseline - ################################# # Checkin Support Methods @@ -123,10 +81,10 @@ def _getBaseline(self): refs = self.context.getReferences(WorkingCopyRelation.relationship) if not len(refs) == 1: - raise interfaces.CheckinException('Baseline count mismatch') + raise CheckinException('Baseline count mismatch') if not refs or refs[0] is None: - raise interfaces.CheckinException('Baseline has disappeared') + raise CheckinException('Baseline has disappeared') baseline = refs[0] return baseline diff --git a/plone/app/iterate/profiles/test/portal_placeful_workflow/working-copy.xml b/plone/app/iterate/profiles/test/portal_placeful_workflow/working-copy.xml index 938d3a3..a999931 100644 --- a/plone/app/iterate/profiles/test/portal_placeful_workflow/working-copy.xml +++ b/plone/app/iterate/profiles/test/portal_placeful_workflow/working-copy.xml @@ -5,6 +5,6 @@ - + diff --git a/plone/app/iterate/testing.py b/plone/app/iterate/testing.py index 0cefdbf..95b9136 100644 --- a/plone/app/iterate/testing.py +++ b/plone/app/iterate/testing.py @@ -12,7 +12,7 @@ try: - pkg_resources.get_distribution('Products.Archtypes') + pkg_resources.get_distribution('Products.Archetypes') except pkg_resources.DistributionNotFound: HAS_AT = False else: @@ -73,7 +73,6 @@ def setUpPloneSite(self, portal): if HAS_AT: # add default content applyProfile(portal, 'Products.ATContentTypes:content') - applyProfile(portal, 'plone.app.iterate:default') applyProfile(portal, 'plone.app.iterate:test') diff --git a/plone/app/iterate/tests/test_interfaces.py b/plone/app/iterate/tests/test_interfaces.py index 1b7378c..12b99ca 100644 --- a/plone/app/iterate/tests/test_interfaces.py +++ b/plone/app/iterate/tests/test_interfaces.py @@ -10,7 +10,7 @@ from plone.app.testing import TEST_USER_ID from plone.app.testing import TEST_USER_NAME from plone.dexterity.utils import createContentInContainer -from unittest2 import TestCase +from unittest import TestCase class TestObjectsProvideCorrectInterfaces(TestCase): diff --git a/plone/app/iterate/tests/test_iterate.py b/plone/app/iterate/tests/test_iterate.py index f31539c..0b9dde3 100644 --- a/plone/app/iterate/tests/test_iterate.py +++ b/plone/app/iterate/tests/test_iterate.py @@ -34,7 +34,7 @@ from plone.app.testing import TEST_USER_NAME from Products.CMFCore.utils import getToolByName -import unittest2 as unittest +import unittest class TestIterations(unittest.TestCase):