def test_validate_duration_failure(self): try: requestests.get(self.test_url) \ .validate_code(requestests.codes.ok) \ .validate_duration_lt(0) assert False, "Expected validate duration < 0 to fail" except AssertionError: pass
def test_multiple_requestests(self): """multiple requestests can be served""" requests_to_handle = 5 server = Server.basic_response_server(requests_to_handle=requests_to_handle) with server as (host, port): server_url = 'http://{0}:{1}'.format(host, port) for _ in range(requests_to_handle): r = requestests.get(server_url) assert r.status_code == 200 # the (n+1)th request fails with pytest.raises(requestests.ConnectionError): r = requestests.get(server_url)
def test_ttlb_and_request_url_using_requestests(self): response = requestests.get(self.test_url) \ .validate_code(requestests.codes.ok) assert response.ttlb > 0, "There is a valid TTLB in Response - ttlb: {}".format( response.ttlb) assert response.request_url, "There is a valid request_url in Response - url: {}".format( response.request_url)
def test_basic_response(self): """the basic response server returns an empty http response""" with Server.basic_response_server() as (host, port): r = requestests.get('http://{0}:{1}'.format(host, port)) assert r.status_code == 200 assert r.text == u'' assert r.headers['Content-Length'] == '0'
def test_text_response(self): """the text_response_server sends the given text""" server = Server.text_response_server( "HTTP/1.1 200 OK\r\n" + "Content-Length: 6\r\n" + "\r\nroflol" ) with server as (host, port): r = requestests.get('http://{0}:{1}'.format(host, port)) assert r.status_code == 200 assert r.text == u'roflol' assert r.headers['Content-Length'] == '6'
def test_validate_duration(self): requestests.get(self.test_url) \ .validate_code(requestests.codes.ok) \ .validate_duration_lt(60)
def test_validate_ttlb(self): requestests.get(self.test_url) \ .validate_code(requestests.codes.ok) \ .validate_ttlb_lt(60)
def test_ttlb_and_request_url_using_requestests(self): response = requestests.get(self.test_url) \ .validate_code(requestests.codes.ok) assert response.ttlb > 0, "There is a valid TTLB in Response - ttlb: {}".format(response.ttlb) assert response.request_url, "There is a valid request_url in Response - url: {}".format(response.request_url)