def post_response(self): try: the_url = prepare_url(self.url) http = HTTP(the_url) http.post() resp = http.response() # confirm that a response was returned, abort if not if resp == None and the_url.startswith('https://'): stderr( "Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL." ) sys.exit(1) elif resp == None: stderr( "Unable to connect to the requested URL. Please confirm your URL and try again." ) sys.exit(1) if len(resp.history) > 0: count = len(resp.history) for i in range(count): print( str(resp.history[i].status_code) + " : " + str(resp.history[i].url)) print(str(http.res.status_code) + " : " + the_url) exit_success() except ConnectionError as ce: error_string = "Unable to connect to the URL, " + self.url stderr(error_string, 1) except Exception as e: raise e
def post_response(self): try: the_url = prepare_url(self.url) http = HTTP(the_url) http.post() resp = http.response() # confirm that a response was returned, abort if not if resp == None and the_url.startswith('https://'): stderr("Unable to connect to the requested URL. This can happen if the secure HTTP protocol is not supported at the requested URL.") sys.exit(1) elif resp == None: stderr("Unable to connect to the requested URL. Please confirm your URL and try again.") sys.exit(1) if len(resp.history) > 0: count = len(resp.history) for i in range(count): print(str(resp.history[i].status_code) + " : " + str(resp.history[i].url)) print(str(http.res.status_code) + " : " + the_url) exit_success() except ConnectionError as ce: error_string = "Unable to connect to the URL, " + self.url stderr(error_string, 1) except Exception as e: raise e
def test_http_post_type(self): """Test the HTTP POST request return value type""" http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE") http_text = http.post() if state.py2: self.assertEqual(type(u"test string"), type(http_text)) else: self.assertEqual(type(str("test string")), type(http_text))
def test_http_post_type(self): """Test the HTTP POST request return value type""" http = HTTP( "https://raw.github.com/chrissimpkins/six-four/master/LICENSE") http_text = http.post() if state.py2: self.assertEqual(type(u"test string"), type(http_text)) else: self.assertEqual(type(str("test string")), type(http_text))
def test_http_post_response_status_200_ssl(self): """Test that the status code 200 is appropriately detected after a SSL POST request""" http = HTTP("https://httpbin.org/post") http.post() self.assertEqual(http.res.status_code, 200)
def test_http_get_response_method_return_value_missingsite(self): """Test the return type from response() method when non-existent site is requested""" http = HTTP('http://www.abogussitename.com') http.post() self.assertEqual(None, http.response())
def test_http_get_response_content_object_missingsite(self): """Test the contents of the response object returned by requests when site is non-existent""" http = HTTP('http://www.abogussitename.com') http.post() with self.assertRaises(AttributeError): http.res.content # confirm that attempt to access the content attribute of res raises Exception when no site
def test_http_POST_response_object_missingsite(self): """Test the POST response object returned by requests when site is non-existent""" http = HTTP('http://www.abogussitename.com') http.post() self.assertEqual(None, http.res)
def test_http_post_contents_response_missingsite(self): """Test the contents of the POST request response when the site is non-existent""" http = HTTP('http://www.abogussitename.com') self.assertEqual(False, http.post()) # returns False if requests ConnectionError
def test_http_post_ssl(self): """Test HTTP POST request content data""" http = HTTP("https://httpbin.org/post") http_text = http.post() response = http.response() self.assertEqual(response.url, 'https://httpbin.org/post')
def test_http_post_contents_response_missingsite(self): """Test the contents of the POST request response when the site is non-existent""" http = HTTP('http://www.abogussitename.com') self.assertEqual( False, http.post()) # returns False if requests ConnectionError