Skip to content

Commit

Permalink
Deprecation warnings removed under py3
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Mar 19, 2013
1 parent 3114be0 commit 94ceded
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/zope/testbrowser/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
from urllib import quote as url_quote
import httplib as httpclient
import urllib2 as urllib_request
from cgi import escape as html_escape
from urllib import urlencode
from UserDict import DictMixin
from base64 import encodestring as base64_encodebytes
class MutableMapping(object, DictMixin):
pass
else:
Expand All @@ -39,3 +41,5 @@ class MutableMapping(object, DictMixin):
from urllib.parse import urlencode
import http.client as httpclient
from collections import MutableMapping
from html import escape as html_escape
from base64 import encodebytes as base64_encodebytes
7 changes: 5 additions & 2 deletions src/zope/testbrowser/ftests/wsgitestapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from webob import Request, Response

from zope.testbrowser._compat import html_escape

class NotFound(Exception):
pass

Expand Down Expand Up @@ -68,14 +70,15 @@ def __init__(self, params):

def __getitem__(self, key):
if key in self.params:
return cgi.escape(self.params[key])
return html_escape(self.params[key])
return ''

def handle_resource(req, extra=None):
filename = req.path_info.split('/')[-1]
type, _ = mimetypes.guess_type(filename)
path = os.path.join(_HERE, filename)
contents = open(path, 'rb').read()
with open(path, 'rb') as f:
contents = f.read()
if type == 'text/html':
params = {}
params.update(req.params)
Expand Down
26 changes: 13 additions & 13 deletions src/zope/testbrowser/tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_redirect(self):
# redirecting locally works
browser.open('http://localhost/redirect.html?%s'
% urlencode(dict(to='/set_status.html')))
self.assertEquals(browser.url, 'http://localhost/set_status.html')
self.assertEqual(browser.url, 'http://localhost/set_status.html')
browser.open('http://localhost/redirect.html?%s'
% urlencode(dict(to='/set_status.html', type='301')))
self.assertEquals(browser.url, 'http://localhost/set_status.html')
self.assertEqual(browser.url, 'http://localhost/set_status.html')
browser.open('http://localhost/redirect.html?%s'
% urlencode(dict(to='http://localhost/set_status.html')))
self.assertEquals(browser.url, 'http://localhost/set_status.html')
self.assertEqual(browser.url, 'http://localhost/set_status.html')
browser.open('http://localhost/redirect.html?%s'
% urlencode(dict(to='http://localhost/set_status.html', type='301')))
self.assertEquals(browser.url, 'http://localhost/set_status.html')
self.assertEqual(browser.url, 'http://localhost/set_status.html')
# non-local redirects raise HostNotAllowed error
self.assertRaises(zope.testbrowser.wsgi.HostNotAllowed,
browser.open,
Expand Down Expand Up @@ -82,18 +82,18 @@ def test_handle_errors(self):
app = WSGITestApplication()
browser = zope.testbrowser.wsgi.Browser(wsgi_app=app)
browser.open('http://localhost/echo_one.html?var=x-wsgiorg.throw_errors')
self.assertEquals(browser.contents, 'None')
self.assertEqual(browser.contents, 'None')
browser.open('http://localhost/echo_one.html?var=paste.throw_errors')
self.assertEquals(browser.contents, 'None')
self.assertEqual(browser.contents, 'None')
browser.open('http://localhost/echo_one.html?var=wsgi.handleErrors')
self.assertEquals(browser.contents, 'None')
self.assertEqual(browser.contents, 'None')
browser.handleErrors = False
browser.open('http://localhost/echo_one.html?var=x-wsgiorg.throw_errors')
self.assertEquals(browser.contents, 'True')
self.assertEqual(browser.contents, 'True')
browser.open('http://localhost/echo_one.html?var=paste.throw_errors')
self.assertEquals(browser.contents, 'True')
self.assertEqual(browser.contents, 'True')
browser.open('http://localhost/echo_one.html?var=wsgi.handleErrors')
self.assertEquals(browser.contents, 'False')
self.assertEqual(browser.contents, 'False')

class TestWSGILayer(unittest.TestCase):

Expand Down Expand Up @@ -132,7 +132,7 @@ def test_unwanted_headers(self):
#x-powered-by and x-content-type-warning are filtered
url = 'http://localhost/set_header.html?x-other=another&x-powered-by=zope&x-content-type-warning=bar'
self.browser.open(url)
self.assertEquals(self.browser.headers['x-other'], 'another')
self.assertEqual(self.browser.headers['x-other'], 'another')
self.assertTrue('x-other' in self.browser.headers)
self.assertFalse('x-powered-by' in self.browser.headers)
self.assertFalse('x-content-type-warning' in self.browser.headers)
Expand All @@ -145,10 +145,10 @@ def test_authorization(self):
# Basic authorization headers are encoded in base64
self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
self.browser.open('http://localhost/echo_one.html?var=HTTP_AUTHORIZATION')
self.assertEquals(self.browser.contents, repr('Basic bWdyOm1ncnB3'))
self.assertEqual(self.browser.contents, repr('Basic bWdyOm1ncnB3'))

def test_authorization_other(self):
# Non-Basic authorization headers are unmolested
self.browser.addHeader('Authorization', 'Digest foobar')
self.browser.open('http://localhost/echo_one.html?var=HTTP_AUTHORIZATION')
self.assertEquals(self.browser.contents, repr('Digest foobar'))
self.assertEqual(self.browser.contents, repr('Digest foobar'))
4 changes: 2 additions & 2 deletions src/zope/testbrowser/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"""WSGI-specific testing code
"""

import base64
import re

import zope.testbrowser.browser

from zope.testbrowser.browser import HostNotAllowed # BBB
from zope.testbrowser._compat import base64_encodebytes

class Browser(zope.testbrowser.browser.Browser):
def __init__(self, url=None, wsgi_app=None):
Expand All @@ -45,7 +45,7 @@ def auth_header(header):
if p is None:
p = ''
plain = '%s:%s' % (u, p)
auth = base64.encodestring(plain.encode('utf-8'))
auth = base64_encodebytes(plain.encode('utf-8'))
return 'Basic %s' % str(auth.rstrip().decode('latin1'))
return header

Expand Down

0 comments on commit 94ceded

Please sign in to comment.