ó
ŒGUc           @   sÞ   d  Z  d Z d Z d Z d Z d Z d Z d d l Z e j d	 d
 k r\ d d l	 m
 Z n d d l m
 Z d d l Z d d l m Z d d l m Z d d l m Z d e j f d „  ƒ  YZ e d k rÚ e j ƒ  n  d S(   s•   unit tests module for ndg.httpsclient.urllib2_build_opener module

PyOpenSSL utility to make a httplib-like interface suitable for use with 
urllib2
s   P J Kershaw (STFC)s   06/01/12s2   (C) 2012 Science and Technology Facilities Councils-   BSD - see LICENSE file in top-level directorys   Philip.Kershaw@stfc.ac.uks   $Id$iÿÿÿÿNi    i   (   t   URLError(   t   SSL(   t	   Constants(   t   build_openert   Urllib2TestCasec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s$   Unit tests for urllib2 functionalityc         C   s   t  ƒ  } |  j | ƒ d  S(   N(   R   t
   assertTrue(   t   selft   opener(    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt   test01_urllib2_build_opener   s    	c         C   s;   t  ƒ  } | j t j ƒ } |  j | ƒ d | j ƒ  GHd  S(   Ns   res = %s(   R   t   openR   t   TEST_URIR   t   read(   R   R   t   res(    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt   test02_open!   s    	c         C   s&   t  ƒ  } |  j t | j t j ƒ d  S(   N(   R   t   assertRaisest	   URLError_R	   R   t	   TEST_URI2(   R   R   (    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt   test03_open_fails_unknown_loc'   s    	c         C   sm   t  j t  j ƒ } d „  } | j t  j | ƒ | j d  d ƒ t d | ƒ } |  j t  j	 | j
 t j ƒ d  S(   Nc         S   s   | S(   N(    (   t   connt   x509t   errnumt   errdeptht   preverify_ok(    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt   <lambda>.   s    s   ./t   ssl_context(   R   t   Contextt   TLSv1_METHODt
   set_verifyt   VERIFY_PEERt   load_verify_locationst   NoneR   R   t   ErrorR	   R   R
   (   R   t   ctxt   verify_callbackR   (    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt(   test04_open_peer_cert_verification_fails+   s    	(   t   __name__t
   __module__t   __doc__R   R   R   R"   (    (    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyR      s
   			t   __main__(   R%   t
   __author__t   __date__t   __copyright__t   __license__t   __contact__t   __revision__t   syst   version_infot   urllib.errorR    R   t   urllib2t   unittestt   OpenSSLR   t   ndg.httpsclient.testR   t$   ndg.httpsclient.urllib2_build_openerR   t   TestCaseR   R#   t   main(    (    (    sE   /usr/lib/python2.7/dist-packages/ndg/httpsclient/test/test_urllib2.pyt   <module>   s"   