Skip to content
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

Verify intids in tests #456

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/430.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add tests to verify that the intids utility is correct after moving content.
[ale-rt, maurits]
25 changes: 25 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ def setUp(self):
id='image',
)

def verify_intids(self):
"""Test that the intids are in order"""
from zope.component import getUtility
from zope.intid.interfaces import IIntIds

intids = getUtility(IIntIds)
broken_keys = [
key for key in intids.ids
if not self.portal.unrestrictedTraverse(key.path, None)
]
obsolete_paths = [key.path for key in broken_keys]
self.assertListEqual(obsolete_paths, [])

# Objects used as keys with a hash can behave strangely.
# I have seen this go wrong in a production site.
weird_keys = [
key for key in intids.ids
if key not in intids.ids
]
weird_paths = [key.path for key in weird_keys]
self.assertListEqual(weird_paths, [])

def test_create_constraints(self):
"""Test the constraints when creating content."""
from plone.api.exc import InvalidParameterError
Expand Down Expand Up @@ -242,6 +264,7 @@ def test_create_dexterity(self):
type='Dexterity Item',
id='test-item',
)
self.verify_intids()

def test_create_content(self):
"""Test create content"""
Expand Down Expand Up @@ -289,6 +312,7 @@ def test_create_content(self):
type='Document',
id='test-document',
)
self.verify_intids()

def test_create_with_safe_id(self):
"""Test the content creating with safe_id mode."""
Expand Down Expand Up @@ -552,6 +576,7 @@ def test_move(self):
container['events']['about']
and container['events']['about'] == about
)
self.verify_intids()

def test_move_no_move_if_target_is_source_parent(self):
"""Test that trying to move an object to its parent is a noop"""
Expand Down