test_urllib2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """unit tests module for ndg.httpsclient.urllib2_build_opener module
  2. PyOpenSSL utility to make a httplib-like interface suitable for use with
  3. urllib2
  4. """
  5. __author__ = "P J Kershaw (STFC)"
  6. __date__ = "06/01/12"
  7. __copyright__ = "(C) 2012 Science and Technology Facilities Council"
  8. __license__ = "BSD - see LICENSE file in top-level directory"
  9. __contact__ = "Philip.Kershaw@stfc.ac.uk"
  10. __revision__ = '$Id$'
  11. from urllib2 import URLError
  12. import unittest
  13. from ndg.httpsclient.test import Constants
  14. from ndg.httpsclient.urllib2_build_opener import build_opener
  15. class Urllib2TestCase(unittest.TestCase):
  16. """Unit tests for urllib2 functionality"""
  17. def test01_urllib2_build_opener(self):
  18. opener = build_opener()
  19. self.assert_(opener)
  20. def test02_open(self):
  21. opener = build_opener()
  22. res = opener.open(Constants.TEST_URI)
  23. self.assert_(res)
  24. print("res = %s" % res.read())
  25. def test03_open_fails(self):
  26. opener = build_opener()
  27. self.failUnlessRaises(URLError, opener.open, Constants.TEST_URI2)
  28. if __name__ == "__main__":
  29. unittest.main()