lots of stuff

This commit is contained in:
counterweight 2025-12-23 17:03:51 +01:00
parent f946fbf7b8
commit 4be45f8f7c
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
9 changed files with 513 additions and 236 deletions

View file

@ -670,14 +670,14 @@ class TestGetMyTrade:
},
)
assert create_response.status_code == 200
trade_id = create_response.json()["id"]
public_id = create_response.json()["public_id"]
# Get the trade
get_response = await client.get(f"/api/trades/{trade_id}")
get_response = await client.get(f"/api/trades/{public_id}")
assert get_response.status_code == 200
data = get_response.json()
assert data["id"] == trade_id
assert data["public_id"] == public_id
assert data["direction"] == "buy"
assert data["bitcoin_transfer_method"] == "onchain"
@ -701,13 +701,13 @@ class TestGetMyTrade:
},
)
assert create_response.status_code == 200
trade_id = create_response.json()["id"]
public_id = create_response.json()["public_id"]
# Second user tries to get it
async with client_factory.create(
cookies=alt_regular_user["cookies"]
) as client:
get_response = await client.get(f"/api/trades/{trade_id}")
get_response = await client.get(f"/api/trades/{public_id}")
assert get_response.status_code == 404
@ -717,7 +717,10 @@ class TestGetMyTrade:
):
"""Getting a nonexistent trade returns 404."""
async with client_factory.create(cookies=regular_user["cookies"]) as client:
response = await client.get("/api/trades/99999")
# Use a valid UUID format but non-existent
response = await client.get(
"/api/trades/00000000-0000-0000-0000-000000000000"
)
assert response.status_code == 404
@ -742,10 +745,10 @@ class TestCancelTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# Cancel
response = await client.post(f"/api/trades/{trade_id}/cancel")
response = await client.post(f"/api/trades/{public_id}/cancel")
assert response.status_code == 200
data = response.json()
@ -772,7 +775,7 @@ class TestCancelTrade:
},
)
assert book_response.status_code == 200
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# Verify the slot is NOT available
slots_response = await client.get(
@ -784,7 +787,7 @@ class TestCancelTrade:
assert f"{target_date}T09:00:00Z" not in slot_starts
# Cancel the trade
cancel_response = await client.post(f"/api/trades/{trade_id}/cancel")
cancel_response = await client.post(f"/api/trades/{public_id}/cancel")
assert cancel_response.status_code == 200
# Verify the slot IS available again
@ -815,11 +818,11 @@ class TestCancelTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# Second user tries to cancel (no mock needed for this)
async with client_factory.create(cookies=alt_regular_user["cookies"]) as client:
response = await client.post(f"/api/trades/{trade_id}/cancel")
response = await client.post(f"/api/trades/{public_id}/cancel")
assert response.status_code == 403
@ -827,7 +830,9 @@ class TestCancelTrade:
async def test_cannot_cancel_nonexistent_trade(self, client_factory, regular_user):
"""Returns 404 for non-existent trade."""
async with client_factory.create(cookies=regular_user["cookies"]) as client:
response = await client.post("/api/trades/99999/cancel")
response = await client.post(
"/api/trades/00000000-0000-0000-0000-000000000000/cancel"
)
assert response.status_code == 404
@ -850,11 +855,11 @@ class TestCancelTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
await client.post(f"/api/trades/{trade_id}/cancel")
public_id = book_response.json()["public_id"]
await client.post(f"/api/trades/{public_id}/cancel")
# Try to cancel again
response = await client.post(f"/api/trades/{trade_id}/cancel")
response = await client.post(f"/api/trades/{public_id}/cancel")
assert response.status_code == 400
assert "cancelled_by_user" in response.json()["detail"]
@ -884,11 +889,11 @@ class TestCancelTrade:
db.add(exchange)
await db.commit()
await db.refresh(exchange)
trade_id = exchange.id
public_id = exchange.public_id
# User tries to cancel
async with client_factory.create(cookies=regular_user["cookies"]) as client:
response = await client.post(f"/api/trades/{trade_id}/cancel")
response = await client.post(f"/api/trades/{public_id}/cancel")
assert response.status_code == 400
assert "already passed" in response.json()["detail"]
@ -1008,11 +1013,11 @@ class TestAdminCompleteTrade:
db.add(exchange)
await db.commit()
await db.refresh(exchange)
trade_id = exchange.id
public_id = exchange.public_id
# Admin completes
async with client_factory.create(cookies=admin_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/complete")
response = await client.post(f"/api/admin/trades/{public_id}/complete")
assert response.status_code == 200
data = response.json()
@ -1038,11 +1043,11 @@ class TestAdminCompleteTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# Admin tries to complete
async with client_factory.create(cookies=admin_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/complete")
response = await client.post(f"/api/admin/trades/{public_id}/complete")
assert response.status_code == 400
assert "not yet started" in response.json()["detail"]
@ -1071,11 +1076,11 @@ class TestAdminCompleteTrade:
db.add(exchange)
await db.commit()
await db.refresh(exchange)
trade_id = exchange.id
public_id = exchange.public_id
# Regular user tries to complete
async with client_factory.create(cookies=regular_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/complete")
response = await client.post(f"/api/admin/trades/{public_id}/complete")
assert response.status_code == 403
@ -1103,11 +1108,11 @@ class TestAdminCompleteTrade:
db.add(exchange)
await db.commit()
await db.refresh(exchange)
trade_id = exchange.id
public_id = exchange.public_id
# Regular user tries to mark as no-show
async with client_factory.create(cookies=regular_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/no-show")
response = await client.post(f"/api/admin/trades/{public_id}/no-show")
assert response.status_code == 403
@ -1139,11 +1144,11 @@ class TestAdminNoShowTrade:
db.add(exchange)
await db.commit()
await db.refresh(exchange)
trade_id = exchange.id
public_id = exchange.public_id
# Admin marks no-show
async with client_factory.create(cookies=admin_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/no-show")
response = await client.post(f"/api/admin/trades/{public_id}/no-show")
assert response.status_code == 200
data = response.json()
@ -1172,11 +1177,11 @@ class TestAdminCancelTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# Admin cancels
async with client_factory.create(cookies=admin_user["cookies"]) as client:
response = await client.post(f"/api/admin/trades/{trade_id}/cancel")
response = await client.post(f"/api/admin/trades/{public_id}/cancel")
assert response.status_code == 200
data = response.json()
@ -1201,10 +1206,10 @@ class TestAdminCancelTrade:
"eur_amount": 10000,
},
)
trade_id = book_response.json()["id"]
public_id = book_response.json()["public_id"]
# User tries admin cancel
response = await client.post(f"/api/admin/trades/{trade_id}/cancel")
response = await client.post(f"/api/admin/trades/{public_id}/cancel")
assert response.status_code == 403