1 """unit tests module for ndg.httpsclient.utils module
2
3 PyOpenSSL utility to make a httplib-like interface suitable for use with
4 urllib2
5 """
6 __author__ = "P J Kershaw (STFC)"
7 __date__ = "06/01/12"
8 __copyright__ = "(C) 2012 Science and Technology Facilities Council"
9 __license__ = "BSD - see LICENSE file in top-level directory"
10 __contact__ = "Philip.Kershaw@stfc.ac.uk"
11 __revision__ = '$Id$'
12 import unittest
13 import os
14
15 from OpenSSL import SSL
16
17 from ndg.httpsclient.test import Constants
18 from ndg.httpsclient.utils import (Configuration, fetch_from_url, open_url,
19 _should_use_proxy)
20
21
23 '''Test ndg.httpsclient.utils module'''
24
26 config = Configuration(SSL.Context(SSL.SSLv3_METHOD), True)
27 self.assert_(config.ssl_context)
28 self.assertEquals(config.debug, True)
29
34
40
42 if 'no_proxy' in os.environ:
43 no_proxy = os.environ['no_proxy']
44 del os.environ['no_proxy']
45 else:
46 no_proxy = None
47
48 self.assertTrue(_should_use_proxy(Constants.TEST_URI),
49 'Expecting use proxy = True')
50
51 os.environ['no_proxy'] = 'localhost,localhost.localdomain'
52 self.assertFalse(_should_use_proxy(Constants.TEST_URI),
53 'Expecting use proxy = False')
54
55 if no_proxy is not None:
56 os.environ['no_proxy'] = no_proxy
57 else:
58 del os.environ['no_proxy']
59
60 if __name__ == "__main__":
61 unittest.main()
62