fix(ci): explicitly pass client=('127.0.0.1', 50000) to ASGITransport in tests
This commit is contained in:
+13
-13
@@ -16,7 +16,7 @@ NON_EXIST_CARD_ID = 1000
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_valid():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
payload = {
|
||||
"choice_A": "Option A",
|
||||
"choice_B": "Option B",
|
||||
@@ -34,7 +34,7 @@ async def test_add_card_valid():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_missing_field():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
payload = {
|
||||
#choice_A
|
||||
"choice_B": "Option B",
|
||||
@@ -46,7 +46,7 @@ async def test_add_card_missing_field():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_wrong_type():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
payload = {
|
||||
"choice_A": 123,
|
||||
"choice_B": "Option B",
|
||||
@@ -58,7 +58,7 @@ async def test_add_card_wrong_type():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_empty_strings():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
payload = {
|
||||
"choice_A": "",
|
||||
"choice_B": "",
|
||||
@@ -70,7 +70,7 @@ async def test_add_card_empty_strings():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_long_strings():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
long_str = "A" * 5000 # long string
|
||||
payload = {
|
||||
"choice_A": long_str,
|
||||
@@ -83,7 +83,7 @@ async def test_add_card_long_strings():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_negative_author_id():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
payload = {
|
||||
"choice_A": "Option A",
|
||||
"choice_B": "Option B",
|
||||
@@ -95,7 +95,7 @@ async def test_add_card_negative_author_id():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_add_card_malformed_json():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
malformed_json = '{"choice_A": "Option A", "choice_B": "Option B", "author_id": 123' # broken json
|
||||
response = await client.post(
|
||||
"/add_card",
|
||||
@@ -112,7 +112,7 @@ async def test_async_card_creation():
|
||||
Limit on /add_card — 3 requests/60s (decorator).
|
||||
Send only 2 parallel requests to avoid exceeding the limit.
|
||||
"""
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
tasks = []
|
||||
num_cards = 2 # at most 3 (decorator limit), leaving a margin
|
||||
for i in range(num_cards):
|
||||
@@ -143,7 +143,7 @@ async def test_async_card_creation():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_get_card_valid():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
# First create a card
|
||||
payload = {
|
||||
"choice_A": "GetTest A",
|
||||
@@ -169,28 +169,28 @@ async def test_get_card_valid():
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_get_card_nonexistent():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
response = await client.get("/get_card", params={"card_id": NON_EXIST_CARD_ID})
|
||||
print(f"\nINPUT: endpoint=/get_card | params={{'card_id': {NON_EXIST_CARD_ID}}}\nOUTPUT: status={response.status_code} | json={response.json()}")
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_get_card_missing_param():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
response = await client.get("/get_card")
|
||||
print(f"\nINPUT: endpoint=/get_card (missing card_id param)\nOUTPUT: status={response.status_code} | json={response.json() if response.content else 'No content'}")
|
||||
assert response.status_code == 422
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_get_card_wrong_type():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
response = await client.get("/get_card", params={"card_id": "abc"})
|
||||
print(f"\nINPUT: endpoint=/get_card | params={{'card_id': 'abc'}}\nOUTPUT: status={response.status_code} | json={response.json()}")
|
||||
assert response.status_code == 422
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_get_card_negative():
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with AsyncClient(transport=ASGITransport(app=app, client=("127.0.0.1", 50000)), base_url="http://test") as client:
|
||||
response = await client.get("/get_card", params={"card_id": -10})
|
||||
print(f"\nINPUT: endpoint=/get_card | params={{'card_id': -10}}\nOUTPUT: status={response.status_code} | json={response.json()}")
|
||||
assert response.status_code == 404
|
||||
Reference in New Issue
Block a user