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 from urllib2 import URLError
13 import unittest
14
15 from OpenSSL import SSL
16 from ndg.httpsclient.test import Constants
17 from ndg.httpsclient.urllib2_build_opener import build_opener
18
19
21 """Unit tests for urllib2 functionality"""
22
24 opener = build_opener()
25 self.assert_(opener)
26
32
36
38
39 ctx = SSL.Context(SSL.SSLv3_METHOD)
40 verify_callback = lambda conn, x509, errnum, errdepth, preverify_ok: \
41 preverify_ok
42
43 ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
44 ctx.load_verify_locations(None, './')
45 opener = build_opener(ssl_context=ctx)
46 self.failUnlessRaises(SSL.Error, opener.open, Constants.TEST_URI)
47
48
49 if __name__ == "__main__":
50 unittest.main()
51