1 """unit tests module for ndg.httpsclient.urllib2_build_opener 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 sys
13
14 if sys.version_info[0] > 2:
15 from urllib.error import URLError as URLError_
16 else:
17 from urllib2 import URLError as URLError_
18
19 import unittest
20
21 from OpenSSL import SSL
22 from ndg.httpsclient.test import Constants
23 from ndg.httpsclient.urllib2_build_opener import build_opener
24
25
27 """Unit tests for urllib2 functionality"""
28
30 opener = build_opener()
31 self.assertTrue(opener)
32
38
42
44
45 ctx = SSL.Context(SSL.TLSv1_METHOD)
46 verify_callback = lambda conn, x509, errnum, errdepth, preverify_ok: \
47 preverify_ok
48
49 ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
50 ctx.load_verify_locations(None, './')
51 opener = build_opener(ssl_context=ctx)
52 self.assertRaises(SSL.Error, opener.open, Constants.TEST_URI)
53
54
55 if __name__ == "__main__":
56 unittest.main()
57