Skip to content

Commit

Permalink
Tests; fix AttributeError: 'Dummy' object has no attribute 'contentIds'.
Browse files Browse the repository at this point in the history
In coredev, when you run `bin/test -u`, all is well.
When you run `bin/test -s plone.dexterity`, with or without `-u`, one test fails:

```
Error in test testAddContentToContainer_preserves_existing_id (plone.dexterity.tests.test_utils.TestUtils)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.10.4/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.10.4/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.10.4/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.dexterity/plone/dexterity/tests/test_utils.py", line 83, in testAddContentToContainer_preserves_existing_id
    item = addContentToContainer(container, item, checkConstraints=False)
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.dexterity/plone/dexterity/utils.py", line 175, in addContentToContainer
    name = INameChooser(container).chooseName(name, object)
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.app.content/plone/app/content/namechooser.py", line 55, in chooseName
    return self._findUniqueName(name, obj)
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.app.content/plone/app/content/namechooser.py", line 64, in _findUniqueName
    if not check_id(name, required=1):
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.app.content/plone/app/content/namechooser.py", line 104, in do_Plone_check
    return check_id(obj, newid, required=required, contained_by=parent)
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.base/src/plone/base/utils.py", line 412, in check_id
    result = _check_for_collision(contained_by, id, **kwargs)
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.base/src/plone/base/utils.py", line 476, in _check_for_collision
    if portal and cid in portal.contentIds():
AttributeError: 'Dummy' object has no attribute 'contentIds'
```

So the portal here is a Dummy from our tests.  No idea why there is a difference in how we run the tests, especially without layers.
Anyway, fixed by adding a `contentIds` method to our Dummy class, returning an empty list.
  • Loading branch information
mauritsvanrees committed Jul 1, 2022
1 parent f24fa8c commit ab90388
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plone/dexterity/tests/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class Dummy(object):
def __init__(self, **kw):
self.__dict__.update(kw)

def contentIds(self):
# testAddContentToContainer_preserves_existing_id fails without this.
return []


class ItemDummy(Dummy):
"""Dummy objects with title getter and setter"""
Expand Down

0 comments on commit ab90388

Please sign in to comment.