Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Corrected py2/py3 compat. Fixed tests for cross-versio testing
Browse files Browse the repository at this point in the history
  • Loading branch information
trollfot committed Sep 20, 2018
1 parent ee1f81e commit 2d070c1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/grokui/admin/security.py
Expand Up @@ -12,10 +12,9 @@
from grokui.base import Messages, IGrokUIRealm

if sys.version_info >= (3, 3):
from html import escape
import urllib.request as urllib
import urllib.parse as urlparse
import urllib.urljoin as urljoin
from html import escape
from urllib.parse import urlparse, urljoin
else:
import urllib2 as urllib
from cgi import escape
Expand Down
1 change: 1 addition & 0 deletions src/grokui/admin/tests/apps.py
Expand Up @@ -57,6 +57,7 @@
>>> ctrl.getControl(value='my-mammoth-manager').selected = True
>>> browser.getControl('Rename').click()
We get a form were we can enter new names::
>>> print(browser.contents)
Expand Down
2 changes: 1 addition & 1 deletion src/grokui/admin/tests/infoviews.py
Expand Up @@ -37,7 +37,7 @@
>>> import re
>>> re.match(r'^grok \d+\.\d+(\.\d+)?.*$', browser.contents)
<_sre.SRE_Match object; ...>
<_sre.SRE_Match object...>
Getting the version of any other installed package
Expand Down
18 changes: 7 additions & 11 deletions src/grokui/admin/tests/security.py
Expand Up @@ -53,15 +53,13 @@
We can get a notification, of course. Asking for that will not trigger
a lookup, while the notifier is disabled::
>>> sn.getNotification()
'Security notifications are disabled.'
>>> assert sn.getNotification() == 'Security notifications are disabled.'
Even an explicit lookup request will not do lookups, while the
notifier is not enabled::
>>> sn.updateMessage()
>>> sn.getNotification()
'Security notifications are disabled.'
>>> assert sn.getNotification() == 'Security notifications are disabled.'
Where to look for notifications
Expand Down Expand Up @@ -95,8 +93,7 @@
>>> sn.enable()
>>> note = sn.getNotification()
>>> note
''
>>> assert note == u''
Ah, there is no security warning for our version. So let us create
one::
Expand All @@ -106,21 +103,20 @@
>>> import os.path
>>> fake_warning_file = 'grok-%s.security.txt' % version
>>> fake_warning_file = os.path.join(release_info_tmpdir, fake_warning_file)
>>> assert open(fake_warning_file, 'w').write('You better smash %s' % version)
>>> with open(fake_warning_file, 'w') as fd:
... _ = fd.write('You better smash %s' % version)
When we now ask the security notifier again::
>>> sn.getNotification()
''
>>> assert sn.getNotification() == ''
We got the same answer as before. Why? The lookups are done only in
certain intervals to reduce the amount of outgoing traffic. When we
fix the lookup timestamp, we get the real value::
>>> sn.last_lookup = None
>>> sn.getNotification()
'You better smash 3.1'
>>> assert sn.getNotification() == u'You better smash 3.1'
To decide, whether the delivered string is actually a warning, we can
call the `isWarning` method::
Expand Down
4 changes: 3 additions & 1 deletion src/grokui/admin/tests/tests.py
Expand Up @@ -18,7 +18,9 @@ def test_suite():
functional_layer = ZopeFanstaticBrowserLayer(grokui.admin.tests)
optionflags = (doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF)
doctest.REPORT_NDIFF +
doctest.IGNORE_EXCEPTION_DETAIL
)
globs = dict(getRootFolder=functional_layer.getRootFolder)

tests = [
Expand Down
5 changes: 3 additions & 2 deletions src/grokui/admin/utilities.py
@@ -1,12 +1,13 @@
import pkg_resources
import socket
import urllib
import sys

if sys.version_info >= (3, 3):
from http.client import HTTPConnection
from urllib.request import HTTPHandler
from urllib.parse import urlencode
else:
from urllib import urlencode
from urllib2 import HTTPHandler
from httplib import HTTPConnection

Expand All @@ -24,7 +25,7 @@ def getURLWithParams(url, data=None):
if isinstance(v, (list, set, tuple)):
data[k] = [isinstance(item, str) and item.encode('utf-8')
or item for item in v]
url += '?' + urllib.parse.urlencode(data, doseq=True)
url += '?' + urlencode(data, doseq=True)
return url


Expand Down
23 changes: 11 additions & 12 deletions src/grokui/admin/views.py
Expand Up @@ -115,20 +115,19 @@ def delete(self, items):
self.redirect(self.url(self.context, 'applications'))

def render(self, rename=None, delete=None, items=None):

if items is None:
return self.redirect(self.url(self.context, 'applications'))

if not isinstance(items, list):
items = [items]

if delete is not None:
return self.delete(items)
elif rename is not None:
return self.redirect(getURLWithParams(

if items is not None:
if not isinstance(items, list):
items = [items]

if delete is not None:
return self.delete(items)
elif rename is not None:
return self.redirect(getURLWithParams(
self.url(self.context, '@@rename'),
data=dict(items=items)))
self.redirect(self.url(self.context, 'applications'))

return self.redirect(self.url(self.context, 'applications'))


class Rename(grok.Page):
Expand Down

0 comments on commit 2d070c1

Please sign in to comment.