Skip to content

Commit

Permalink
Add tests for plone.app.iterate subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Feb 15, 2018
1 parent efb65b2 commit 61fd57b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/collective/fingerpointing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
else:
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE as PLONE_FIXTURE # noqa: E501

try:
pkg_resources.get_distribution('plone.app.iterate')
except pkg_resources.DistributionNotFound:
HAS_ITERATE = False
else:
HAS_ITERATE = True

IS_PLONE_5 = api.env.plone_version().startswith('5')

Expand Down Expand Up @@ -52,10 +58,17 @@ def _cleanup_audit_log(self):

def setUpZope(self, app, configurationContext):
self._setup_audit_log()
if HAS_ITERATE:
import plone.app.iterate
self.loadZCML(package=plone.app.iterate)

import collective.fingerpointing
self.loadZCML(package=collective.fingerpointing)

def setUpPloneSite(self, portal):
if HAS_ITERATE:
self.applyProfile(portal, 'plone.app.iterate:plone.app.iterate')

self.applyProfile(portal, 'collective.fingerpointing:default')
portal.portal_workflow.setDefaultChain('simple_publication_workflow')

Expand Down
76 changes: 76 additions & 0 deletions src/collective/fingerpointing/tests/test_iterate_subscriber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
"""Tests for iterate subscribers.
Dexterity content types have different names.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IFingerPointingSettings
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import IS_PLONE_5
from logging import INFO
from plone import api
from plone.app.iterate.interfaces import ICheckinCheckoutPolicy
from testfixtures import LogCapture

import unittest


class IterateSubscribersTestCase(unittest.TestCase):
"""Tests for plone.app.iterate subscribers."""

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self._disable_lifecycle_events()

with api.env.adopt_roles(['Manager']):
self.folder = api.content.create(self.portal, 'Folder', 'folder')
self.doc = api.content.create(self.folder, 'Document', 'doc')

def _disable_lifecycle_events(self):
name = IFingerPointingSettings.__identifier__ + '.audit_lifecycle'
api.portal.set_registry_record(name, value=False)

def test_checkout_checkin(self):
if IS_PLONE_5:
expected = (
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkout object=<Document at doc> working_copy=<Document at copy_of_doc>'), # noqa: E501
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkin object=<Document at copy_of_doc> baseline=<Document at doc>'), # noqa: E501
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkout object=<ATDocument at doc> working_copy=<ATDocument at copy_of_doc>'), # noqa: E501
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkin object=<ATDocument at copy_of_doc> baseline=<ATDocument at doc>'), # noqa: E501
)

with LogCapture('collective.fingerpointing', level=INFO) as log:
wc = ICheckinCheckoutPolicy(self.doc).checkout(self.folder)
self.doc = ICheckinCheckoutPolicy(wc).checkin('updated')
log.check(*expected)

def test_checkout_cancel(self):
if IS_PLONE_5:
expected = (
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkout object=<Document at doc> working_copy=<Document at copy_of_doc>'), # noqa: E501
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=cancel checkout object=<Document at copy_of_doc> baseline=<Document at doc>'), # noqa: E501
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=checkout object=<ATDocument at doc> working_copy=<ATDocument at copy_of_doc>'), # noqa: E501
('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=cancel checkout object=<ATDocument at copy_of_doc> baseline=<ATDocument at doc>'), # noqa: E501
)

with LogCapture('collective.fingerpointing', level=INFO) as log:
wc = ICheckinCheckoutPolicy(self.doc).checkout(self.folder)
ICheckinCheckoutPolicy(wc).cancelCheckout()
log.check(*expected)

def test_susbcriber_ignored_when_package_not_installed(self):
# iterate events should not raise errors if package not installed
qi = self.portal['portal_quickinstaller']
with api.env.adopt_roles(['Manager']):
qi.uninstallProducts(products=[PROJECTNAME])

wc = ICheckinCheckoutPolicy(self.doc).checkout(self.folder)
ICheckinCheckoutPolicy(wc).cancelCheckout()

0 comments on commit 61fd57b

Please sign in to comment.