Skip to content

Commit

Permalink
Merge pull request #15 from plone/python3
Browse files Browse the repository at this point in the history
fix templateViewRegistrationGroups and tests in py3
  • Loading branch information
pbauer committed Oct 1, 2018
2 parents 3fb2abf + 4da27fe commit 2999e0c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -15,7 +15,8 @@ New features:

Bug fixes:

- *add item here*
- Fix templateViewRegistrationGroups and tests in py3.
[pbauer]


1.3.7 (2017-02-05)
Expand Down
6 changes: 3 additions & 3 deletions plone/app/customerize/registration.py
Expand Up @@ -13,6 +13,7 @@
from zope.component import getUtility
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.viewlet.interfaces import IViewlet
from operator import itemgetter


def getViews(type):
Expand Down Expand Up @@ -106,18 +107,17 @@ def templateViewRegistrationInfos(regs, mangle=True):

def templateViewRegistrationGroups(regs, mangle=True):
ifaces = {}
comp = lambda a, b: cmp(a['viewname'], b['viewname'])
registrations = sorted(
templateViewRegistrationInfos(regs, mangle=mangle),
cmp=comp
key=itemgetter('viewname')
)
for reg in registrations:
key = reg['for']
if key in ifaces:
ifaces[key]['views'].append(reg)
else:
ifaces[key] = {'name': key, 'views': [reg]}
return sorted(ifaces.values(), cmp=lambda a, b: cmp(a['name'], b['name']))
return sorted(ifaces.values(), key=itemgetter('name'))


def findTemplateViewRegistration(required, viewname):
Expand Down
13 changes: 7 additions & 6 deletions plone/app/customerize/tests/testBrowserLayers.txt
Expand Up @@ -23,12 +23,12 @@ product is installed, we cannot view the view, though:
>>> browser.open('http://nohost/plone/@@layer-test-view')
Traceback (most recent call last):
...
NotFound: ...
zExceptions.NotFound: ...

We can view a view registered for the default layer, though:

>>> browser.open('http://nohost/plone/@@standard-test-view')
>>> print browser.contents
>>> print(browser.contents)
a standard view

At this time only the latter should be customerizable:
Expand All @@ -51,11 +51,11 @@ should also show up as being customizable:
>>> transaction.commit()

>>> browser.open('http://nohost/plone/@@layer-test-view')
>>> print browser.contents
>>> print(browser.contents)
a local view

>>> browser.open('http://nohost/plone/@@standard-test-view')
>>> print browser.contents
>>> print(browser.contents)
a standard view

>>> browser.open('http://nohost/plone/portal_view_customizations/registrations.html')
Expand Down Expand Up @@ -154,7 +154,7 @@ We click the "customize" button, enter some new content, and save the changes:
Now we look at the view we just customized:

>>> browser.open('http://nohost/plone/@@layer-test-view')
>>> print browser.contents
>>> print(browser.contents)
customized view

And now let's do the same with a viewlet:
Expand All @@ -180,6 +180,7 @@ And now let's do the same with a viewlet:
'http://nohost/plone/portal_view_customizations/zope.interface.interface-layer-test-viewlet'
>>> browser.contents
'...Saved changes...'
>>> browser.handleErrors = False
>>> browser.open('http://nohost/plone/@@layer-test-view')
>>> browser.open('http://nohost/plone/')
>>> browser.contents
Expand Down Expand Up @@ -231,7 +232,7 @@ only the locally registered view and viewlet:
>>> without_layer.issubset(with_layer)
True
>>> sorted(list(with_layer.difference(without_layer)))
['layer-test-view', u'layer-test-viewlet']
['layer-test-view', 'layer-test-viewlet']

.. _extension: http://dev.plone.org/plone/changeset/20088

Expand Down
4 changes: 2 additions & 2 deletions plone/app/customerize/tests/testCustomizeView.txt
Expand Up @@ -62,8 +62,8 @@ This is mainly useful for code which wants the view_name anyhow.
Now we look at the view we just customized. To do so we browse the view
registrations overview again and select another template for customization:

>>> browser.getLink('portal_view_customizations').click()
>>> browser.getLink('registrations.html').click()
>>> browser.open('http://nohost/plone/portal_view_customizations/registrations.html')
>>> browser.getLink('registrations.html', index=0).click()
>>> browser.contents
'...you lose!...'

Expand Down
11 changes: 11 additions & 0 deletions plone/app/customerize/tests/testDocTests.py
Expand Up @@ -4,6 +4,16 @@
from unittest import TestSuite

import doctest
import re
import six


class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub('zExceptions.NotFound', 'NotFound', got)
got = re.sub("u'(.*?)'", "'\\1'", want)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
Expand All @@ -16,6 +26,7 @@ def test_suite():
testfile,
optionflags=OPTIONFLAGS,
package='plone.app.customerize.tests',
checker=Py23DocChecker(),
),
layer=PLONE_APP_CUSTOMERIZE_FUNCTIONAL_TESTING
)
Expand Down
2 changes: 1 addition & 1 deletion plone/app/customerize/tool.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from AccessControl import ClassSecurityInfo
from App.class_init import InitializeClass
from AccessControl.class_init import InitializeClass
from five.customerize.interfaces import IViewTemplateContainer
from OFS.Folder import Folder
from Products.CMFCore.permissions import ManagePortal
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Expand Up @@ -17,13 +17,16 @@
'Framework :: Plone',
'Framework :: Plone :: 5.0',
'Framework :: Plone :: 5.1',
'Framework :: Plone :: 5.2',
'Framework :: Zope2',
'Intended Audience :: Other Audience',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Internet :: WWW/HTTP :: Site Management',
],
keywords='customerize plone views page templates zmi',
Expand All @@ -38,6 +41,7 @@
test=[
'plone.app.layout',
'plone.app.testing',
'six',
'zope.testing',
]
),
Expand Down

1 comment on commit 2999e0c

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pbauer Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.app.customerize/24/violations

plone/app/customerize/tool.py:31:1: E305 expected 2 blank lines after class or function definition, found 1
plone/app/customerize/registration.py:16:1: I001 isort found an import in the wrong position
plone/app/customerize/registration.py:49:15: P002 found "hasattr", consider replacing it
plone/app/customerize/registration.py:51:11: T000 Todo note found.
plone/app/customerize/registration.py:74:15: T000 Todo note found.
plone/app/customerize/registration.py:112:35: C812 missing trailing comma
plone/app/customerize/registration.py:135:31: C812 missing trailing comma
plone/app/customerize/registration.py:155:7: T000 Todo note found.
plone/app/customerize/testing.py:13:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/customerize/testing.py:16:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/customerize/testing.py:19:9: D001 found xmlconfig.file( replace it with self.loadZCML(
plone/app/customerize/tests/testDocTests.py:31:63: C812 missing trailing comma
plone/app/customerize/tests/testDocTests.py:32:14: C812 missing trailing comma

Follow these instructions to reproduce it locally.

Please sign in to comment.