Skip to content
Myr

test_sync.py

This file

Path

tests/test_sync.py

69 lines · 1.8 KiB · Python

Last changed by

Update test_sync.pyTom Christiebefore adoption5d552eb

History of this file

Take it

Merge pull request #13 from encode/syncTom Christiebefore adoption903a961

lines 1–30why, one step back
1import asyncio
2import functools34import pytest56import httpcore789def threadpool(func):10 """11 Our sync tests should run in seperate thread to the uvicorn server.12 """1314 @functools.wraps(func)15 async def wrapped(*args, **kwargs):16 nonlocal func1718 loop = asyncio.get_event_loop()19 if kwargs:20 func = functools.partial(func, **kwargs)21 await loop.run_in_executor(None, func, *args)2223 return pytest.mark.asyncio(wrapped)242526@threadpool27def test_get(server):28 with httpcore.SyncConnectionPool() as http:29 response = http.request("GET", "http://127.0.0.1:8000/")30 assert response.status_code == 200

Merge branch 'master' into wait-for-connection-closeTom Christiebefore adoption20bc1f3

line 31why, one step back
31 assert response.content == b"Hello, world!"

Merge pull request #13 from encode/syncTom Christiebefore adoption903a961

lines 32–45why, one step back
32
3334@threadpool35def test_post(server):36 with httpcore.SyncConnectionPool() as http:37 response = http.request("POST", "http://127.0.0.1:8000/", body=b"Hello, world!")38 assert response.status_code == 200394041@threadpool42def test_stream_response(server):43 with httpcore.SyncConnectionPool() as http:44 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)45 assert response.status_code == 200

Merge branch 'master' into wait-for-connection-closeTom Christiebefore adoption20bc1f3

lines 46–47why, one step back
46 content = response.read()
47 assert content == b"Hello, world!"

Merge pull request #13 from encode/syncTom Christiebefore adoption903a961

lines 48–54why, one step back
48
4950@threadpool51def test_stream_iterator(server):52 with httpcore.SyncConnectionPool() as http:53 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)54 assert response.status_code == 200

Update test_sync.pyTom Christiebefore adoption5d552eb

line 55why, one step back
55 body = b""

Merge pull request #13 from encode/syncTom Christiebefore adoption903a961

lines 56–58why, one step back
56 for chunk in response.stream():
57 body += chunk58 assert body == b"Hello, world!"

Add `raw` method to SyncResponseYeray Diaz Diazbefore adoption99dc1a9

lines 59–69why, one step back
59
6061@threadpool62def test_raw_iterator(server):63 with httpcore.SyncConnectionPool() as http:64 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)65 assert response.status_code == 20066 body = b""67 for chunk in response.raw():68 body += chunk69 assert body == b"Hello, world!"