Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Added b prefix for string used in BaseHTTPRequestHandler wfile.write #122

Merged
merged 2 commits into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions oauth2client/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html><head><title>Authentication Status</title></head>")
self.wfile.write("<body><p>The authentication flow has completed.</p>")
self.wfile.write("</body></html>")
self.wfile.write(b"<html><head><title>Authentication Status</title></head>")
self.wfile.write(b"<body><p>The authentication flow has completed.</p>")
self.wfile.write(b"</body></html>")

def log_message(self, format, *args):
"""Do not log messages to stdout while running as command line program."""
Expand Down
30 changes: 30 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -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)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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()