-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Purge data when delete tile #768
Changes from 1 commit
36dfc3b
9040b0d
e61e831
09f43bd
f83f88c
318a8ef
ccefd8e
facb577
40ab3cd
e67c9d5
4495074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
from collective.cover.tiles.permissions import ITilesPermissions | ||
from cStringIO import StringIO | ||
from plone.tiles.interfaces import ITileDataManager | ||
from zope.annotation import IAnnotations | ||
from zope.component import eventtesting | ||
from zope.component import getMultiAdapter | ||
from zope.configuration.xmlconfig import xmlconfig | ||
|
||
|
@@ -49,7 +47,6 @@ def _register_tile(self): | |
|
||
def setUp(self): | ||
super(BaseTileTestCase, self).setUp() | ||
eventtesting.setUp() | ||
self._register_tile() | ||
self.tile = PersistentCoverTile(self.cover, self.request) | ||
self.tile.__name__ = u'collective.cover.base' | ||
|
@@ -71,9 +68,14 @@ def test_default_configuration(self): | |
def test_accepted_content_types(self): | ||
self.assertEqual(self.tile.accepted_ct(), ALL_CONTENT_TYPES) | ||
|
||
def test_delete_tile_persistent_data(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep this test to guarantee all persistent data, conffiguration an permissions are removed at low level and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test uses the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have to think on how to test the feature on low level. |
||
eventtesting.clearEvents() | ||
|
||
def test_delete_tile_removes_persistent_data(self): | ||
# https://github.com/collective/collective.cover/issues/765 | ||
from collective.cover.config import CONFIGURATION_PREFIX | ||
from collective.cover.config import PERMISSIONS_PREFIX | ||
from zope.annotation import IAnnotations | ||
from zope.component import eventtesting | ||
from zope.lifecycleevent import IObjectModifiedEvent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hvelarde why in tests do you import inside the methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because is easier to maintain later. |
||
eventtesting.setUp() | ||
annotations = IAnnotations(self.tile.context) | ||
|
||
data_mgr = ITileDataManager(self.tile) | ||
|
@@ -82,24 +84,25 @@ def test_delete_tile_persistent_data(self): | |
self.assertEqual(data_mgr.get()['test'], 'data') | ||
|
||
permissions = getMultiAdapter( | ||
(self.tile.context, self.request, self.tile), ITilesPermissions) | ||
(self.cover, self.request, self.tile), ITilesPermissions) | ||
permissions.set_allowed_edit('masters_of_the_universe') | ||
self.assertIn('plone.tiles.permission.test', annotations) | ||
self.assertIn(PERMISSIONS_PREFIX + '.test', annotations) | ||
|
||
configuration = getMultiAdapter( | ||
(self.tile.context, self.request, self.tile), ITilesConfigurationScreen) | ||
(self.cover, self.request, self.tile), ITilesConfigurationScreen) | ||
configuration.set_configuration({'uuid': 'c1d2e3f4g5jrw'}) | ||
self.assertIn('plone.tiles.configuration.test', annotations) | ||
self.assertIn(CONFIGURATION_PREFIX + '.test', annotations) | ||
|
||
# Call the delete method | ||
eventtesting.clearEvents() | ||
self.tile.delete() | ||
|
||
# Now we should not see the stored data anymore | ||
# Now we should not see the persistent data anymore | ||
self.assertNotIn('test', data_mgr.get()) | ||
self.assertNotIn('plone.tiles.permission.test', annotations) | ||
self.assertNotIn('plone.tiles.configuration.test', annotations) | ||
|
||
events = eventtesting.getEvents() | ||
self.assertNotIn(PERMISSIONS_PREFIX + '.test', annotations) | ||
self.assertNotIn(CONFIGURATION_PREFIX + '.test', annotations) | ||
|
||
# Finally, test that ObjectModifiedEvent was fired for the cover | ||
self.assertEqual(events[0].object, self.cover) | ||
events = eventtesting.getEvents() | ||
self.assertEqual(len(events), 1) | ||
self.assertTrue(IObjectModifiedEvent.providedBy(events[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to be divided in a two-step process: on
plone.tiles
persistent tiles data can be stored on a storage different of annotations, that means it's safer to use the data manager API to remove the data from the tile; our annotations (configuration and permission) can be removed directly, but we will need to test them at least on the base tile at low level to guarantee it's working.it's probably better to keep the API also on configuration and permission, so we could call a
delete()
method to do the work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean.. storage variable is an alias to annotation property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you have to delete the annotation using the tile manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't work, tile collection test breaks because I don't know the type of the deleted tile to instantiate the correct type..