diff options
author | KCs <cskertesz@gmail.com> | 2015-02-01 13:12:21 +0200 |
---|---|---|
committer | KCs <cskertesz@gmail.com> | 2015-02-01 13:12:21 +0200 |
commit | 927589bf06a1ed140612babf92e8469f2f013859 (patch) | |
tree | 5e5d5952a200c4457c67da6666d149d34b401bb8 /tests/test_tools.py | |
parent | 8547303c6a1f411d30331aa97e88f1d2f70494bf (diff) | |
download | oauth2client-927589bf06a1ed140612babf92e8469f2f013859.tar.gz |
added test file for tools module containing a test for the ClientRedirectServer and ClientRedirect classes
Diffstat (limited to 'tests/test_tools.py')
-rw-r--r-- | tests/test_tools.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_tools.py b/tests/test_tools.py new file mode 100644 index 0000000..23aca90 --- /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() + |