Exemple #1
0
 def test_http_get_response_obj_present(self):
     """Confirm that response object is set after GET request with site that exists"""
     http = HTTP('http://google.com')
     http.get()
     self.assertTrue(http.res)             # the response object
     self.assertTrue(http.res.content)     # the content of the response
     self.assertTrue(http.res.status_code) # the status code
Exemple #2
0
 def test_http_get_response_check_301(self):
     """Confirm that the reponse object contains 301 status code when do not follow redirects"""
     http = HTTP('http://httpbin.org/status/301')
     http.get(False) # do not follow redirects
     self.assertEqual(http.res.status_code, 301)
     response = http.response()
     self.assertEqual(response.status_code, 301)
Exemple #3
0
 def test_http_get_response_check_404(self):
     """Confirm that the response object contains a 404 status code when authentication required"""
     http = HTTP('http://httpbin.org/status/404')
     http.get()
     self.assertEqual(http.res.status_code, 404)
     response = http.response()
     self.assertEqual(response.status_code, 404)
Exemple #4
0
 def test_http_get_response_check_200(self):
     """Confirm that the response object contains 200 status code"""
     http = HTTP('http://httpbin.org/status/200')
     http.get()
     self.assertEqual(http.res.status_code, 200) # test the response object attribute
     response = http.response()
     self.assertEqual(response.status_code, 200) # test the returned object from the response() method
Exemple #5
0
 def test_http_get_response_obj_present(self):
     """Confirm that response object is set after GET request with site that exists"""
     http = HTTP('http://google.com')
     http.get()
     self.assertTrue(http.res)  # the response object
     self.assertTrue(http.res.content)  # the content of the response
     self.assertTrue(http.res.status_code)  # the status code
Exemple #6
0
        def test_http_get_ssl(self):
            """Test HTTP GET request content data with secure HTTP"""
            http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
            http_text = http.get()

            if state.py2:
                self.http_string = unicode(self.http_string)
            self.assertEqual(http_text.strip(), self.http_string.strip())
Exemple #7
0
 def test_http_get_response_obj_nonexistentsite(self):
     """Test the response object after GET request for a non-existent site"""
     http = HTTP('http://bigtimebogussite.io')
     self.assertEqual(False, http.get())
     self.assertEqual(None, http.res)
     with self.assertRaises(AttributeError):
         http.res.content
     with self.assertRaises(AttributeError):
         http.res.status_code
Exemple #8
0
        def test_http_get_type(self):
            """Test the HTTP GET request return value type"""
            http = HTTP("https://raw.github.com/chrissimpkins/six-four/master/LICENSE")
            http_text = http.get()

            if state.py2:
                self.assertEqual(type(u"test string"), type(http_text))
            else:
                self.assertEqual(type(str("test string")), type(http_text))
Exemple #9
0
 def test_http_get_response_obj_nonexistentsite(self):
     """Test the response object after GET request for a non-existent site"""
     http = HTTP('http://bigtimebogussite.io')
     self.assertEqual(False, http.get())
     self.assertEqual(None, http.res)
     with self.assertRaises(AttributeError):
         http.res.content
     with self.assertRaises(AttributeError):
         http.res.status_code
Exemple #10
0
 def test_http_get_response_object_missingsite(self):
     """Test the GET response object returned by requests when site is non-existent"""
     http = HTTP('http://www.abogussitename.com')
     http.get()
     self.assertEqual(None, http.res)
Exemple #11
0
 def test_http_get_follow_redirects(self):
     """Confirm that the GET request follows redirects and returns 200 status code by default"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get()
     self.assertEqual(200, http.res.status_code)
Exemple #12
0
 def test_http_get_status_ssl_redirect(self):
     """Confirm that GET request for a https domain returns appropriate 301 status code when redirects"""
     http = HTTP('https://httpbin.org/status/301')
     http.get(False) # do not allow redirects in order to capture this code
     self.assertEqual(http.res.status_code, 301)
Exemple #13
0
 def test_http_get_status_ssl(self):
     """Confirm that GET request for a https domain returns appropriate status code"""
     http = HTTP('https://httpbin.org/status/200')
     http.get()
     self.assertEqual(http.res.status_code, 200)
Exemple #14
0
 def test_http_get_follow_redirects_false_on_nofollow_arg(self):
     """Confirm that GET request does not follow redirect and returns non-200 status code when requested"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get(follow_redirects=False)
     self.assertEqual(301, http.res.status_code)
Exemple #15
0
 def test_http_get_follow_redirects(self):
     """Confirm that the GET request follows redirects and returns 200 status code by default"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get()
     self.assertEqual(200, http.res.status_code)
Exemple #16
0
 def test_http_get_follow_redirects_false_on_nofollow_arg(self):
     """Confirm that GET request does not follow redirect and returns non-200 status code when requested"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get(follow_redirects=False)
     self.assertEqual(301, http.res.status_code)
Exemple #17
0
 def test_http_get_response_method_return_value_missingsite(self):
     """Test the return type from response() method after GET request when non-existent site is requested"""
     http = HTTP('http://www.abogussitename.com')
     http.get()
     self.assertEqual(None, http.response())
Exemple #18
0
 def test_http_get_response_content_object_missingsite(self):
     """Test the contents of the GET response object returned by requests when site is non-existent"""
     http = HTTP('http://www.abogussitename.com')
     http.get()
     with self.assertRaises(AttributeError):
         http.res.content # confirm that attempt to access the content attribute of res raises Exception when no site
Exemple #19
0
 def test_http_get_contents_response_missingsite(self):
     """Test the contents of the GET request response when the site is non-existent"""
     http = HTTP('http://www.abogussitename.com')
     self.assertEqual(False, http.get()) # returns False if requests ConnectionError
Exemple #20
0
 def test_http_get_follow_redirects_false_content(self):
     """Test the contents of the returned data from the GET request when site returns non-200 status code"""
     http = HTTP("http://httpbin.org/status/301")
     http_text = http.get(follow_redirects=False)
     self.assertEqual("", http_text)