def test_multiple_clients(self): client_1 = exfoliate.Client() client_2 = exfoliate.Client() future_1 = client_1.get('https://httpbin.org/anything') future_2 = client_2.get('https://httpbin.org/anything') assert future_1.response().json() == future_2.response().json() assert client_1.connector != client_2.connector
def test_nonblocking(self): client = exfoliate.Client() blocking_future = client.get('https://httpbin.org/delay/1') nonblocking_future = client.get('https://httpbin.org/delay/0') target_futures = (nonblocking_future, blocking_future, ) for future, target_future in zip(client.futures, target_futures): assert future == target_future
def test_repeat_request(self): client = exfoliate.Client() future_initial = client.get('https://httpbin.org/anything') response_initial = future_initial.response().json() future_repeated = future_initial.repeat() response_repeated = future_repeated.response().json() assert response_repeated == response_initial
def test_default_cookie_isolation(self): client = exfoliate.Client() future_1 = client.get('https://httpbin.org/cookies/set?a=1&c=3') future_2 = client.get('https://httpbin.org/cookies/set?b=2&c=3') response_1 = future_1.response().json() response_2 = future_2.response().json() assert response_1 == {'cookies': {'a': '1', 'c': '3'}} assert response_2 == {'cookies': {'b': '2', 'c': '3'}}
def test_methods(self): client = exfoliate.Client() for method_name in ('GET', 'PUT', 'POST', 'DELETE', ): method = getattr(client, method_name.lower()) future = method('https://httpbin.org/anything') response = future.response() assert response.status_code == 200 assert response.json()['method'] == method_name
def test_shared_cookies(self): cookie_jar = exfoliate.CookieJar() client = exfoliate.Client(cookie_jar=cookie_jar) future_1 = client.get('https://httpbin.org/cookies/set?a=1&c=3') response_1 = future_1.response().json() future_2 = client.get('https://httpbin.org/cookies/set?b=2&c=3') response_2 = future_2.response().json() assert response_1 == {'cookies': {'a': '1', 'c': '3'}} assert response_2 == {'cookies': {'a': '1', 'b': '2', 'c': '3'}}
def test_headers(self): client = exfoliate.Client() headers = {'X-Test-Exfoliate': 'awesome'} future = client.get('https://httpbin.org/headers', headers=headers) response = future.response().json() assert response['headers']['X-Test-Exfoliate'] == 'awesome'
def test_text(self): client = exfoliate.Client() future = client.get('https://httpbin.org/encoding/utf8') response = future.response() assert len(response.text()) == 7808 assert len(response.content) == 14239