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

Allow for a callable title on objects in ZODB. #108

Merged
merged 3 commits into from
Sep 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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