diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 15:57:41 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-04-21 15:57:41 +0200 |
commit | b4187e5d61acb98ffb86767c82a60280db7833f3 (patch) | |
tree | 6ee1e8ba1d6834f343d960aaa3b3868b594d1d29 /tests/test_auth | |
parent | f3fd444b0bc18e95d08c88567d9d8ed17346027d (diff) | |
download | paste-b4187e5d61acb98ffb86767c82a60280db7833f3.tar.gz |
Port paste.auth to Python 3
* md5() and hmac expects bytes: on Python 3, encode text to utf-8
* Don't compare None with int
* HTTP body must be bytes
Diffstat (limited to 'tests/test_auth')
-rw-r--r-- | tests/test_auth/test_auth_cookie.py | 6 | ||||
-rw-r--r-- | tests/test_auth/test_auth_digest.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/tests/test_auth/test_auth_cookie.py b/tests/test_auth/test_auth_cookie.py index 3bff2d8..67465f4 100644 --- a/tests/test_auth/test_auth_cookie.py +++ b/tests/test_auth/test_auth_cookie.py @@ -10,6 +10,7 @@ try: except ImportError: # Python 2 from Cookie import SimpleCookie +import six from paste.auth import cookie from paste.wsgilib import raw_interactive, dump_environ @@ -41,7 +42,10 @@ def test_basic(key='key', val='bingles'): cookie = value.split(";")[0] (status,headers,content,errors) = \ raw_interactive(app,{'HTTP_COOKIE': cookie}) - assert ("%s: %s" % (key,val.replace("\n","\n "))) in content + expected = ("%s: %s" % (key,val.replace("\n","\n "))) + if six.PY3: + expected = expected.encode('utf8') + assert expected in content def test_roundtrip(): roundtrip = str('').join(map(chr, xrange(256))) diff --git a/tests/test_auth/test_auth_digest.py b/tests/test_auth/test_auth_digest.py index a821720..5657782 100644 --- a/tests/test_auth/test_auth_digest.py +++ b/tests/test_auth/test_auth_digest.py @@ -8,12 +8,16 @@ from paste.response import header_value from paste.httpexceptions import * from paste.httpheaders import AUTHORIZATION, WWW_AUTHENTICATE, REMOTE_USER import os +import six def application(environ, start_response): content = REMOTE_USER(environ) start_response("200 OK",(('Content-Type', 'text/plain'), ('Content-Length', len(content)))) - return content + + if six.PY3: + content = content.encode('utf8') + return [content] realm = "tag:clarkevans.com,2005:testing" @@ -46,7 +50,7 @@ def check(username, password, path="/"): assert False, "Unexpected Status: %s" % status def test_digest(): - assert 'bing' == check("bing","gnib") + assert b'bing' == check("bing","gnib") assert check("bing","bad") is None # |