From 8547303c6a1f411d30331aa97e88f1d2f70494bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dr=2E=20Kert=C3=A9sz=20Csaba-Zolt=C3=A1n?= Date: Fri, 30 Jan 2015 19:28:10 +0200 Subject: [PATCH 1/2] Added b prefix for string used in BaseHTTPRequestHandler wfile.write --- oauth2client/tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oauth2client/tools.py b/oauth2client/tools.py index 235793b9d..20faa4375 100644 --- a/oauth2client/tools.py +++ b/oauth2client/tools.py @@ -99,9 +99,9 @@ def do_GET(self): query = self.path.split('?', 1)[-1] query = dict(urllib.parse.parse_qsl(query)) self.server.query_params = query - self.wfile.write("Authentication Status") - self.wfile.write("

The authentication flow has completed.

") - self.wfile.write("") + self.wfile.write(b"Authentication Status") + self.wfile.write(b"

The authentication flow has completed.

") + self.wfile.write(b"") def log_message(self, format, *args): """Do not log messages to stdout while running as command line program.""" From 927589bf06a1ed140612babf92e8469f2f013859 Mon Sep 17 00:00:00 2001 From: KCs Date: Sun, 1 Feb 2015 13:12:21 +0200 Subject: [PATCH 2/2] added test file for tools module containing a test for the ClientRedirectServer and ClientRedirect classes --- tests/test_tools.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_tools.py diff --git a/tests/test_tools.py b/tests/test_tools.py new file mode 100644 index 000000000..23aca9025 --- /dev/null +++ b/tests/test_tools.py @@ -0,0 +1,30 @@ +"""Unit tests for oauth2client.tools.""" + +import unittest +from oauth2client import tools +from six.moves.urllib import request +import threading + +class TestClientRedirectServer(unittest.TestCase): + """Test the ClientRedirectServer and ClientRedirectHandler classes.""" + + def test_ClientRedirectServer(self): + # create a ClientRedirectServer and run it in a thread to listen + # for a mock GET request with the access token + # the server should return a 200 message and store the token + httpd = tools.ClientRedirectServer(('localhost', 0), tools.ClientRedirectHandler) + code = 'foo' + url = 'http://localhost:%i?code=%s' % (httpd.server_address[1], code) + t = threading.Thread(target = httpd.handle_request) + t.setDaemon(True) + t.start() + f = request.urlopen( url ) + self.assertTrue(f.read()) + t.join() + httpd.server_close() + self.assertEqual(httpd.query_params.get('code'),code) + + +if __name__ == '__main__': + unittest.main() +