import urllib.request
import urllib.error
import json

# Test login
data = json.dumps({"username": "e2etest", "password": "Test12345!"}).encode()
req = urllib.request.Request(
    "http://127.0.0.1:5000/api/v1/auth/login",
    data=data,
    headers={"Content-Type": "application/json"},
)

try:
    with urllib.request.urlopen(req) as resp:
        body = resp.read().decode()
        print("SUCCESS:", body[:200])
except urllib.error.HTTPError as e:
    body = e.read().decode()
    print(f"HTTP ERROR {e.code}:", body[:500])
except Exception as e:
    print("ERROR:", e)
