Package ndg :: Package httpsclient :: Package test :: Module test_utils
[hide private]

Source Code for Module ndg.httpsclient.test.test_utils

 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   
22 -class TestUtilsModule(unittest.TestCase):
23 '''Test ndg.httpsclient.utils module''' 24
25 - def test01_configuration(self):
26 config = Configuration(SSL.Context(SSL.SSLv3_METHOD), True) 27 self.assert_(config.ssl_context) 28 self.assertEquals(config.debug, True)
29
30 - def test02_fetch_from_url(self):
31 config = Configuration(SSL.Context(SSL.SSLv3_METHOD), True) 32 res = fetch_from_url(Constants.TEST_URI, config) 33 self.assert_(res)
34
35 - def test03_open_url(self):
36 config = Configuration(SSL.Context(SSL.SSLv3_METHOD), True) 37 res = open_url(Constants.TEST_URI, config) 38 self.assertEqual(res[0], 200, 39 'open_url for %r failed' % Constants.TEST_URI)
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