diff --git a/.toxfiles/reqs-py2.txt b/.toxfiles/reqs-py2.txt index dc72df4..fa448c1 100644 --- a/.toxfiles/reqs-py2.txt +++ b/.toxfiles/reqs-py2.txt @@ -1,2 +1,3 @@ zope.mkzeoinstance==3.9.6 Products.ZSQLMethods==2.13.6 +mock diff --git a/CHANGELOG b/CHANGELOG index d0d801b..31c8ea0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/perfact/zodbsync/tests/test_sync.py b/perfact/zodbsync/tests/test_sync.py index adefddc..a25a4ef 100644 --- a/perfact/zodbsync/tests/test_sync.py +++ b/perfact/zodbsync/tests/test_sync.py @@ -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 @@ -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 diff --git a/perfact/zodbsync/zodbsync.py b/perfact/zodbsync/zodbsync.py index 37d6e4a..f44c416 100644 --- a/perfact/zodbsync/zodbsync.py +++ b/perfact/zodbsync/zodbsync.py @@ -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