Skip to content

Commit

Permalink
fix templateViewRegistrationGroups and tests in py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jun 12, 2018
1 parent 3fb2abf commit ff054dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
6 changes: 3 additions & 3 deletions plone/app/customerize/registration.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
12 changes: 12 additions & 0 deletions plone/app/customerize/tests/testDocTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
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)
else:
want = re.sub("u'(.*?)'", "'\\1'", want)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
Expand All @@ -16,6 +27,7 @@ def test_suite():
testfile,
optionflags=OPTIONFLAGS,
package='plone.app.customerize.tests',
checker=Py23DocChecker(),
),
layer=PLONE_APP_CUSTOMERIZE_FUNCTIONAL_TESTING
)
Expand Down

1 comment on commit ff054dd

@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/19/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:32:63: C812 missing trailing comma
plone/app/customerize/tests/testDocTests.py:33:14: C812 missing trailing comma

Follow these instructions to reproduce it locally.

Please sign in to comment.