File: test_tools.py

package info (click to toggle)
python-oauth2client 2.0.1-3~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,108 kB
  • sloc: python: 8,964; makefile: 188; sh: 55
file content (32 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""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."""

    @unittest.skip("Skipped in Debian: doing network access")
    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__':  # pragma: NO COVER
    unittest.main()