Skip to content

Commit

Permalink
Fix test fixture for Plone 5
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Feb 18, 2016
1 parent b2cbb7a commit 34a32e6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -9,8 +9,6 @@ env:
- PLONE_VERSION=4.3
- PLONE_VERSION=5.0
matrix:
allow_failures:
- env: PLONE_VERSION=5.0
fast_finish: true
install:
- sed -ie "s#test-4.3.x.cfg#test-$PLONE_VERSION.x.cfg#" buildout.cfg
Expand Down
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<layers>
<layer name="collective.fingerpointing" remove="true" />
</layers>
14 changes: 14 additions & 0 deletions src/collective/fingerpointing/testing.py
@@ -1,21 +1,35 @@
# -*- coding: utf-8 -*-
"""Setup testing infrastructure.
For Plone 5 we need to manually install plone.app.contenttypes.
"""
from plone import api
from plone.app.robotframework.testing import AUTOLOGIN_LIBRARY_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.testing import z2

PLONE_VERSION = api.env.plone_version()


class Fixture(PloneSandboxLayer):

defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
if PLONE_VERSION >= '5.0':
import plone.app.contenttypes
self.loadZCML(package=plone.app.contenttypes)

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

def setUpPloneSite(self, portal):
if PLONE_VERSION >= '5.0':
self.applyProfile(portal, 'plone.app.contenttypes:default')

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


Expand Down
36 changes: 29 additions & 7 deletions src/collective/fingerpointing/tests/test_lifecycle_subscriber.py
@@ -1,6 +1,12 @@
# -*- coding: utf-8 -*-
"""Tests for lifecycle subscriber.
Events are slightly different among Plone 4 and Plone 5. Also, Plone 5
content types have different names.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import PLONE_VERSION
from logging import INFO
from plone import api
from testfixtures import LogCapture
Expand All @@ -20,23 +26,39 @@ def setUp(self):
self.folder = api.content.create(self.portal, 'Folder', 'folder')

def test_object_created(self):
with LogCapture(level=INFO) as log:
api.content.create(self.folder, 'Folder', 'foo')
log.check(
if PLONE_VERSION >= '5.0':
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object created object=<Folder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object modified object=<Folder at folder>'),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object created object=<ATFolder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object modified object=<ATFolder at folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object modified object=<ATFolder at foo>'),
)

def test_object_removed(self):
api.content.create(self.folder, 'Folder', 'foo')
with LogCapture(level=INFO) as log:
api.content.delete(self.folder['foo'])
log.check(
api.content.create(self.folder, 'Folder', 'foo')
log.check(*expected)

def test_object_removed(self):
if PLONE_VERSION >= '5.0':
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object removed object=<Folder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object modified object=<Folder at folder>'),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object removed object=<ATFolder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=object modified object=<ATFolder at folder>'),
)

api.content.create(self.folder, 'Folder', 'foo')
with LogCapture(level=INFO) as log:
api.content.delete(self.folder['foo'])
log.check(*expected)

def test_susbcriber_ignored_when_package_not_installed(self):
# content type life cycle events should not raise errors
# if package is not installed
Expand Down
24 changes: 21 additions & 3 deletions src/collective/fingerpointing/tests/test_pas_subscriber.py
@@ -1,6 +1,11 @@
# -*- coding: utf-8 -*-
"""Tests for lifecycle subscriber.
Log output is slightly different among Plone 4 and Plone 5.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
from collective.fingerpointing.testing import PLONE_VERSION
from logging import INFO
from plone import api
from Products.PlonePAS.events import UserLoggedInEvent
Expand All @@ -23,12 +28,25 @@ def setUp(self):
self.request = self.layer['request']

def test_user_login(self):
if PLONE_VERSION >= '5.0':
expected = (
('plone.protect', 'INFO', 'auto rotating keyring _system'),
('plone.protect', 'INFO', 'auto rotating keyring _forms'),
('plone.protect', 'INFO', 'auto rotating keyring _anon'),
('plone.protect', 'INFO', 'auto rotating keyring _system'),
('plone.protect', 'INFO', 'auto rotating keyring _forms'),
('plone.protect', 'INFO', 'auto rotating keyring _anon'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=logged in '),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=logged in '),
)

event = UserLoggedInEvent(self.request)
with LogCapture(level=INFO) as log:
notify(event)
log.check(
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=logged in '),
)
log.check(*expected)

def test_user_logout(self):
event = UserLoggedOutEvent(self.request)
Expand Down
7 changes: 3 additions & 4 deletions src/collective/fingerpointing/tests/test_setup.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.interfaces import IBrowserLayer
from collective.fingerpointing.testing import INTEGRATION_TESTING
from plone.browserlayer.utils import registered_layers

Expand All @@ -20,8 +21,7 @@ def test_installed(self):
self.assertTrue(qi.isProductInstalled(PROJECTNAME))

def test_addon_layer(self):
layers = [l.getName() for l in registered_layers()]
self.assertIn('IBrowserLayer', layers)
self.assertIn(IBrowserLayer, registered_layers())


class UninstallTestCase(unittest.TestCase):
Expand All @@ -39,5 +39,4 @@ def test_uninstalled(self):
self.assertFalse(self.qi.isProductInstalled(PROJECTNAME))

def test_addon_layer_removed(self):
layers = [l.getName() for l in registered_layers()]
self.assertNotIn('IBrowserLayer', layers)
self.assertNotIn(IBrowserLayer, registered_layers())

0 comments on commit 34a32e6

Please sign in to comment.