def test_redirect(self): url = self.getURL("redirect") self.setupStep(http.GETNewStyle(url)) expected_log = ''' Redirected 1 times: URL: {0}/redirect ------ Content ------ <html> <head> <meta http-equiv="refresh" content="0;URL=/redirected-path"> </head> <body bgcolor="#FFFFFF" text="#000000"> <a href="/redirected-path">click here</a> </body> </html> ============================================================ URL: {0}/redirected-path Status: 200 ------ Content ------ OK'''.format(self.get_connection_string()) self.expectLogfile('log', expected_log) self.expectLogfile('content', "OK") self.expectOutcome(result=SUCCESS, state_string="Status code: 200") return self.runStep()
def test_header(self): url = self.getURL("header") self.setupStep(http.GETNewStyle(url, headers={"X-Test": "True"})) self.expectLogfile( 'log', "URL: {}\nStatus: 200\n ------ Content ------\nTrue".format(url)) self.expectOutcome(result=SUCCESS, state_string="Status code: 200") return self.runStep()
def test_get(self): url = self.getURL() self.setupStep(http.GETNewStyle(url)) self.expectLogfile( 'log', "URL: {}\nStatus: 200\n ------ Content ------\nOK".format(url)) self.expectLogfile('content', "OK") self.expectOutcome(result=SUCCESS, state_string="Status code: 200") return self.runStep()
def test_404(self): url = self.getURL("404") self.setupStep(http.GETNewStyle(url)) self.expectLogfile('log', "URL: {}\n ------ Content ------\n404".format(url)) self.expectLogfile('content', "404") self.expectOutcome(result=FAILURE, state_string="Status code: 404 (failure)") return self.runStep()
def test_connection_error(self): def throwing_request(*args, **kwargs): raise requests.exceptions.ConnectionError("failed to connect") with mock.patch.object(http.getSession(), 'request', throwing_request): url = self.getURL("path") self.setupStep(http.GETNewStyle(url)) self.expectOutcome(result=FAILURE, state_string="Requested (failure)") return self.runStep()
def test_params_renderable(self): url = self.getURL() self.setupStep(http.GETNewStyle(url, params=properties.Property("x"))) self.properties.setProperty('x', { 'param_1': 'param_1', 'param_2': 2 }, 'here') self.expectLogfile('log', ( "URL: {}?param_1=param_1¶m_2=2\nStatus: 200\n ------ Content ------\nOK" ).format(url)) self.expectLogfile('content', "OK") self.expectOutcome(result=SUCCESS, state_string="Status code: 200") return self.runStep()
def test_hidden_header(self): url = self.getURL("header") self.setupStep( http.GETNewStyle(url, headers={"X-Test": "True"}, hide_request_headers=["X-Test"], hide_response_headers=["Content-Length"])) self.expectLogfile( 'log', "URL: {}\nStatus: 200\n ------ Content ------\nTrue".format(url)) self.expectOutcome(result=SUCCESS, state_string="Status code: 200") yield self.runStep() self.assertIn("X-Test: <HIDDEN>", self.step.logs['log'].header) self.assertIn("Content-Length: <HIDDEN>", self.step.logs['log'].header)