Files / tests /test_auth.py
lea97338's picture
Upload 100 files (#1)
680fa2b
Raw
History Blame Contribute Delete
3.08 kB
import pytest
def test_signup_customer(client):
response = client.post(
"/api/auth/signup",
json={
"name": "Jane Doe",
"phone": "9876543211",
"role": "customer",
"city": "Jaipur"
}
)
assert response.status_code == 201
data = response.json()
assert data["name"] == "Jane Doe"
assert data["phone"] == "9876543211"
assert data["role"] == "customer"
assert "customer_profile" in data
assert data["customer_profile"]["wallet_balance"] == 8200
def test_signup_worker_fails_without_skill_or_rate(client):
response = client.post(
"/api/auth/signup",
json={
"name": "Ramu",
"phone": "9876543212",
"role": "worker",
"city": "Jaipur"
}
)
assert response.status_code == 400
assert "detail" in response.json()
def test_signup_worker_success(client):
response = client.post(
"/api/auth/signup",
json={
"name": "Ramu Mason",
"phone": "9876543212",
"role": "worker",
"city": "Jaipur",
"skill": "Mason",
"rate": 500
}
)
assert response.status_code == 201
data = response.json()
assert data["role"] == "worker"
assert "worker_profile" in data
assert data["worker_profile"]["skill"] == "Mason"
assert data["worker_profile"]["rate"] == 500
def test_login_demo_bypass_otp(client):
# Log in as a customer with phone and demo OTP
response = client.post(
"/api/auth/login",
json={
"phone": "9876543213",
"role": "customer",
"otp": "123456"
}
)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert data["role"] == "customer"
def test_login_demo_bypass_otp_worker(client):
response = client.post(
"/api/auth/login",
json={
"phone": "9876543214",
"role": "worker",
"otp": "123456"
}
)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert data["role"] == "worker"
def test_login_invalid_otp_fails(client):
response = client.post(
"/api/auth/login",
json={
"phone": "9876543213",
"role": "customer",
"otp": "999999"
}
)
assert response.status_code == 401
def test_fetch_me_profile_success(client):
# 1. Login to get token
login_response = client.post(
"/api/auth/login",
json={
"phone": "9876543215",
"role": "customer",
"otp": "123456"
}
)
token = login_response.json()["access_token"]
# 2. Access me endpoint
response = client.get(
"/api/auth/me",
headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
data = response.json()
assert data["phone"] == "9876543215"
assert data["role"] == "customer"