|
|
import requests |
|
|
|
|
|
BASE_URL = "http://127.0.0.1:8000" |
|
|
|
|
|
def safe_print_response(resp): |
|
|
print("Status code:", resp.status_code) |
|
|
try: |
|
|
print("Response JSON:", resp.json()) |
|
|
except Exception: |
|
|
print("Raw response text:", resp.text) |
|
|
|
|
|
|
|
|
register_data = { |
|
|
"email": "test@example.com", |
|
|
"password": "test", |
|
|
"security_question_1": "What is your favorite color?", |
|
|
"security_answer_1": "Blue", |
|
|
"security_question_2": "What is your mother's maiden name?", |
|
|
"security_answer_2": "Smith" |
|
|
} |
|
|
|
|
|
resp = requests.post(f"{BASE_URL}/auth/register", json=register_data) |
|
|
print("Register Response:") |
|
|
safe_print_response(resp) |
|
|
|
|
|
login_data = { |
|
|
"email": "test@example.com", |
|
|
"password": "test" |
|
|
} |
|
|
|
|
|
resp = requests.post(f"{BASE_URL}/auth/login", json=login_data) |
|
|
print("\nLogin Response:") |
|
|
safe_print_response(resp) |
|
|
|
|
|
if resp.status_code == 200: |
|
|
token = resp.json().get("access_token") |
|
|
print("\nJWT Access Token:", token) |
|
|
else: |
|
|
print("Login failed, cannot test protected route") |
|
|
|