test_https.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """unit tests module for ndg.httpsclient.https.HTTPSconnection class
  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. import logging
  12. logging.basicConfig(level=logging.DEBUG)
  13. import unittest
  14. import socket
  15. from ndg.httpsclient.test import Constants
  16. from ndg.httpsclient.https import HTTPSConnection
  17. class TestHTTPSConnection(unittest.TestCase):
  18. '''Test ndg HTTPS client HTTPSConnection class'''
  19. def test01_open(self):
  20. conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT)
  21. conn.connect()
  22. conn.request('GET', '/')
  23. resp = conn.getresponse()
  24. print('Response = %s' % resp.read())
  25. conn.close()
  26. def test02_open_fails(self):
  27. conn = HTTPSConnection(Constants.HOSTNAME, port=Constants.PORT2)
  28. self.failUnlessRaises(socket.error, conn.connect)
  29. if __name__ == "__main__":
  30. unittest.main()