Skip to content

Commit

Permalink
Use object representation to log life cycle events
Browse files Browse the repository at this point in the history
This fixes an issue with Archetypes-based objects being dumped to the log.
  • Loading branch information
hvelarde committed May 6, 2016
1 parent 1b3effa commit 44c7bd7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
1.0b4 (unreleased)
------------------

- Use object representation to log life cycle events;
this fixes an issue with Archetypes-based objects being dumped to the log (refs. `#8`_ and fixes `#38`_).
[hvelarde]

- Package is now compatible with Plone 5.0 and Plone 5.1.
[hvelarde]

Expand Down Expand Up @@ -84,7 +88,9 @@ Changelog
.. _`#1`: https://github.com/collective/collective.fingerpointing/issues/1
.. _`#2`: https://github.com/collective/collective.fingerpointing/issues/2
.. _`#4`: https://github.com/collective/collective.fingerpointing/issues/4
.. _`#8`: https://github.com/collective/collective.fingerpointing/issues/8
.. _`#15`: https://github.com/collective/collective.fingerpointing/issues/15
.. _`#18`: https://github.com/collective/collective.fingerpointing/issues/18
.. _`#25`: https://github.com/collective/collective.fingerpointing/issues/25
.. _`#30`: https://github.com/collective/collective.fingerpointing/issues/30
.. _`#38`: https://github.com/collective/collective.fingerpointing/issues/38
6 changes: 3 additions & 3 deletions src/collective/fingerpointing/subscribers/lifecycle_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def lifecycle_logger(obj, event):

if IObjectCreatedEvent.providedBy(event):
action = 'create'
extras = 'object={0}'.format(obj)
extras = 'object={0}'.format(repr(obj))
if IObjectModifiedEvent.providedBy(event):
action = 'modify'
extras = 'object={0}'.format(obj)
extras = 'object={0}'.format(repr(obj))
if IObjectRemovedEvent.providedBy(event):
action = 'remove'
extras = 'object={0}'.format(obj)
extras = 'object={0}'.format(repr(obj))

log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
69 changes: 52 additions & 17 deletions src/collective/fingerpointing/tests/test_lifecycle_subscriber.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- 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.
Events are slightly different among Archetypes and Dexterity.
Also, Dexterity content types have different names.
"""
from collective.fingerpointing.config import PROJECTNAME
from collective.fingerpointing.testing import INTEGRATION_TESTING
Expand All @@ -25,38 +25,72 @@ def setUp(self):
with api.env.adopt_roles(['Manager']):
self.folder = api.content.create(self.portal, 'Folder', 'folder')

def test_object_created(self):
def test_file_lifecicle(self):
if PLONE_VERSION >= '5.0':
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<File at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<File at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<ATFile at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFile at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<ATFile at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
)

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

def test_folder_lifecicle(self):
if PLONE_VERSION >= '5.0':
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<Folder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<Folder at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<ATFolder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<ATFolder at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<ATFolder at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
)

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

def test_object_removed(self):
def test_image_lifecicle(self):
if PLONE_VERSION >= '5.0':
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<Folder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<Image at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<Image at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<Folder at /plone/folder>'),
)
else:
expected = (
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<ATFolder at foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=create object=<ATImage at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATImage at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=remove object=<ATImage at /plone/folder/foo>'),
('collective.fingerpointing', 'INFO', 'user=test ip=127.0.0.1 action=modify object=<ATFolder at /plone/folder>'),
)

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

def test_susbcriber_ignored_when_package_not_installed(self):
Expand All @@ -67,5 +101,6 @@ def test_susbcriber_ignored_when_package_not_installed(self):
with api.env.adopt_roles(['Manager']):
qi.uninstallProducts(products=[PROJECTNAME])

api.content.create(self.folder, 'Folder', 'foo')
api.content.delete(self.folder['foo'])
obj = api.content.create(self.folder, 'Folder', 'foo')
obj.reindexObject()
api.content.delete(obj)

0 comments on commit 44c7bd7

Please sign in to comment.