def test_http_status_555(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/status/555' result = requestor.sync_request(task) response = rebuild_response(result) assert response.status_code == 555
def test_fake_request(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = 'first_task: test_project' result = requestor.sync_request(task) response = rebuild_response(result) assert response.json == None
def test_http_max_redirect(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/redirect/4' task['fetch']['max_redirects'] = 3 result = requestor.sync_request(task) response = rebuild_response(result) assert response.error == 'HTTP 599: Maximum (3) redirects followed' task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/redirect/4' task['fetch']['max_redirects'] = 5 result = requestor.sync_request(task) response = rebuild_response(result) assert response.status_code == 200
def test_http_no_redirect(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/redirect/4' task['fetch']['allow_redirects'] = False result = requestor.sync_request(task) response = rebuild_response(result) assert response.error == 'HTTP 302: FOUND'
def test_http_proxy_auth_failed(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/get' task['fetch']['proxy_host'] = self.proxy_host task['fetch']['proxy_port'] = self.proxy_port result = requestor.sync_request(task) response = rebuild_response(result) assert response.status_code == 403
def test__phantomjs_url(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/status/200' task['fetch']['fetch_type'] = 'js' result = requestor.sync_request(task) response = rebuild_response(result) assert response.status_code == 200 assert response.error == None assert response.isok() == True assert response.js_script_result == None
def test_http_post(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/post' task['fetch']['method'] = 'POST' task['fetch']['data'] = 'Hello World' task['fetch']['cookies'] = {'c': 'd'} result = requestor.sync_request(task) response = rebuild_response(result) assert response.status_code == 200 assert response.orig_url == task['url'] assert response.json['form']['Hello World'] == '' assert response.json['headers'].get('A') == 'b'
def test_http_timeout(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/delay/4' task['fetch']['timeout'] = 2 start_time = time.time() result = requestor.sync_request(task) end_time = time.time() response = rebuild_response(result) time_cost = end_time - start_time assert time_cost >= 2 assert time_cost < 3 assert response.content == '' assert response.status_code == 599 assert 'HTTP 599: Operation timed out' in response.error
def test_http_get(self, requestor): task = copy.deepcopy(self.default_task) task['url'] = task['url'] + '/get' result = requestor.sync_request(task) response = rebuild_response(result) assert response.ok == True assert response.status_code == 200 assert response.url == task['url'] assert hasattr(response, 'headers') assert len(response.content) > 0 assert isinstance(response.time_cost, (int, float)) assert response.cookies == {'c': 'd'} assert response.json['headers']['A'] == 'b' assert response.json['headers']['Cookie'] == 'a=b'