Skip to content

Commit

Permalink
Merge pull request #456 from plone/maurits/verify-intids-in-tests
Browse files Browse the repository at this point in the history
Verify intids in tests
  • Loading branch information
mauritsvanrees committed Mar 22, 2021
2 parents b9013bb + 44bb079 commit 403b152
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit 403b152

Please sign in to comment.