def wrapper(*args, **kwargs): # Make the actual call to urlopen so urllib3 will attempt a connect. # Since the proxy does not actually open a socket to the remote host we # expect cPython to raise a ProxyError and PyPy will raise an SSLError. # For testing these errors can be ignored, we just care that the # connect occured with the proper request line. try: fn(*args, **kwargs) except exceptions.ProxyError: pass except exceptions.SSLError: pass response = HTTPResponse(status=202) return response
def wrapper(*args, **kwargs): response = HTTPResponse(status=202) response.request = Request(*args, **kwargs) if status_code is not None: response.status = status_code return response
def test_response_ok(status, expected): response = HTTPResponse(status=status) assert response.ok is expected
def test_response_json(): response = HTTPResponse(status=200, body=b"{}") assert response.json() == {}
def disable_sending(*args, **kwargs): response = HTTPResponse(status=202) response.request = Request(*args, **kwargs) return response
def test_response_raise_for_status_ok(): response = HTTPResponse(status=200) response.raise_for_status()
def test_response_raise_for_status_error(): response = HTTPResponse(status=500) with pytest.raises(HTTPError): response.raise_for_status()
def send_batch(instance, items, common): _metrics.extend(items) return HTTPResponse(status=200)