Skip to content

Commit

Permalink
Allow for a callable title on objects in ZODB. (#108)
Browse files Browse the repository at this point in the history
* Allow for a callable title on objects in ZODB.

* Omit title attributes if they are callable.

---------

Co-authored-by: Michael Howitz <[email protected]>
Co-authored-by: Michael Howitz <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 0580263 commit 3bae333
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .toxfiles/reqs-py2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zope.mkzeoinstance==3.9.6
Products.ZSQLMethods==2.13.6
mock
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
unreleased
* Omit title attributes if they are callable.

22.2.4
* Refactor scripts into entry points to be usable with zc.buildout >= 3.

Expand Down
24 changes: 24 additions & 0 deletions perfact/zodbsync/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
except ImportError: # pragma: no cover
ZOPE2 = False

try:
from unittest import mock
except ImportError:
import mock

from ..main import Runner
from .. import zodbsync
from .. import helpers
Expand Down Expand Up @@ -243,6 +248,25 @@ def test_record_unsupported(self):
with pytest.raises(AssertionError):
zodbsync.mod_read(obj, onerrorstop=True)

def test_omit_callable_title(self):
"""It omits title attributes which are callable."""
app = self.app
obj = app.manage_addProduct['PageTemplates'].manage_addPageTemplate(
id='test_pt', title='Not-visible', text='test text')

def patch_title():
"""Callable to test callable titles."""
return 'Show-me'

# Normal case
result = zodbsync.mod_read(obj)
assert 'Not-visible' in result['title']

# with callable title
with mock.patch.object(obj, 'title', patch_title):
result = zodbsync.mod_read(obj)
assert 'title' not in result

def test_playback(self):
'''
Record everything, change /index_html, play it back and check if the
Expand Down
3 changes: 2 additions & 1 deletion perfact/zodbsync/zodbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def mod_read(obj=None, onerrorstop=False, default_owner=None,
# The title should always be readable
title = getattr(obj, 'title', None)
# see comment in helpers.py:str_repr for why we convert to string
meta['title'] = to_string(title)
if isinstance(title, (six.binary_type, six.text_type)):
meta['title'] = to_string(title)

# Generic and meta type dependent handlers

Expand Down

0 comments on commit 3bae333

Please sign in to comment.