Skip to content

Commit

Permalink
remove unittest2
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 22, 2016
1 parent 5b89c4c commit 79f0064
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 103 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ New features:

Bug fixes:

- Do not use unittest2 anymore.
[jensens]

- Cleanup: isort, zca decorators, etc.
[jensens]

Expand Down
99 changes: 99 additions & 0 deletions plone/app/iterate/base.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion plone/app/iterate/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
/>

<include package=".dexterity" zcml:condition="installed plone.app.relationfield" />
<include file="at.zcml" zcml:condition="installed Products.Archtypes" />
<include file="at.zcml" zcml:condition="installed Products.Archetypes" />

</configure>
62 changes: 28 additions & 34 deletions plone/app/iterate/dexterity/policy.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
84 changes: 21 additions & 63 deletions plone/app/iterate/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<default>
<bound-workflow workflow_id="workingcopy_workflow" />
</default>
<type default_chain="true" type_id="Document" />
<type default_chain="true" type_id="Document" />
</bindings>
</object>
3 changes: 1 addition & 2 deletions plone/app/iterate/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion plone/app/iterate/tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion plone/app/iterate/tests/test_iterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 79f0064

Please sign in to comment.