This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test file for tools module containing a test for the ClientRedi…
…rectServer and ClientRedirect classes
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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() | ||
|