admin frontend elkezdése, járművek tisztázása, frontend fejleszts
This commit is contained in:
82
backend/backend/scripts/test_delete_me.py
Normal file
82
backend/backend/scripts/test_delete_me.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script: DELETE /api/v1/users/me
|
||||
Direct call to FastAPI inside the container (bypasses proxy).
|
||||
Uses tester_pro2@profibot.hu credentials.
|
||||
"""
|
||||
import asyncio
|
||||
import httpx
|
||||
import sys
|
||||
|
||||
BASE_URL = "http://localhost:8000/api/v1"
|
||||
|
||||
async def login_and_get_token():
|
||||
"""Login as tester_pro2 and get JWT token using OAuth2 form."""
|
||||
async with httpx.AsyncClient() as client:
|
||||
# OAuth2PasswordRequestForm expects form data with username and password fields
|
||||
resp = await client.post(
|
||||
f"{BASE_URL}/auth/login",
|
||||
data={
|
||||
"username": "tester_pro2@profibot.hu",
|
||||
"password": "TesztElek99!",
|
||||
"remember_me": "false"
|
||||
}
|
||||
)
|
||||
if resp.status_code != 200:
|
||||
print(f"❌ LOGIN FAILED: {resp.status_code}")
|
||||
print(f" Response: {resp.text}")
|
||||
return None
|
||||
data = resp.json()
|
||||
token = data.get("access_token")
|
||||
print(f"✅ LOGIN OK - Token obtained (first 50 chars): {token[:50]}...")
|
||||
return token
|
||||
|
||||
async def test_delete_me(token):
|
||||
"""Send DELETE /me request directly to FastAPI."""
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
async with httpx.AsyncClient() as client:
|
||||
print(f"\n🔍 Sending DELETE {BASE_URL}/users/me ...")
|
||||
resp = await client.delete(
|
||||
f"{BASE_URL}/users/me",
|
||||
headers=headers
|
||||
)
|
||||
print(f" Status: {resp.status_code}")
|
||||
print(f" Response: {resp.text[:500]}")
|
||||
|
||||
if resp.status_code == 200:
|
||||
print("✅ DELETE /me SUCCESS!")
|
||||
return True
|
||||
elif resp.status_code == 405:
|
||||
print("❌ 405 Method Not Allowed - The endpoint is not registered for DELETE")
|
||||
return False
|
||||
elif resp.status_code == 404:
|
||||
print("❌ 404 Not Found - The endpoint path is wrong")
|
||||
return False
|
||||
else:
|
||||
print(f"⚠️ Unexpected status code")
|
||||
return False
|
||||
|
||||
async def main():
|
||||
print("=" * 60)
|
||||
print("🧪 TEST: DELETE /api/v1/users/me")
|
||||
print("=" * 60)
|
||||
|
||||
# Step 1: Login
|
||||
token = await login_and_get_token()
|
||||
if not token:
|
||||
sys.exit(1)
|
||||
|
||||
# Step 2: Test DELETE
|
||||
success = await test_delete_me(token)
|
||||
|
||||
if success:
|
||||
print("\n✅ TEST PASSED: DELETE /me works correctly!")
|
||||
else:
|
||||
print("\n❌ TEST FAILED: DELETE /me returned an error!")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user