This commit is contained in:
@@ -18,7 +18,7 @@ class TestUserService:
|
||||
"""Test registration with duplicate email"""
|
||||
# First registration
|
||||
await client.post("/api/v1/register", json=user_data)
|
||||
|
||||
|
||||
# Second registration with same email
|
||||
response = await client.post("/api/v1/register", json=user_data)
|
||||
assert response.status_code == 400
|
||||
@@ -28,12 +28,9 @@ class TestUserService:
|
||||
"""Test user login"""
|
||||
# Register user first
|
||||
await client.post("/api/v1/register", json=user_data)
|
||||
|
||||
|
||||
# Login
|
||||
login_data = {
|
||||
"email": user_data["email"],
|
||||
"password": user_data["password"]
|
||||
}
|
||||
login_data = {"email": user_data["email"], "password": user_data["password"]}
|
||||
response = await client.post("/api/v1/login", json=login_data)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -42,10 +39,7 @@ class TestUserService:
|
||||
|
||||
async def test_login_invalid_credentials(self, client: AsyncClient):
|
||||
"""Test login with invalid credentials"""
|
||||
login_data = {
|
||||
"email": "wrong@example.com",
|
||||
"password": "wrongpassword"
|
||||
}
|
||||
login_data = {"email": "wrong@example.com", "password": "wrongpassword"}
|
||||
response = await client.post("/api/v1/login", json=login_data)
|
||||
assert response.status_code == 401
|
||||
|
||||
@@ -53,12 +47,12 @@ class TestUserService:
|
||||
"""Test getting user profile"""
|
||||
# Register and login
|
||||
await client.post("/api/v1/register", json=user_data)
|
||||
login_response = await client.post("/api/v1/login", json={
|
||||
"email": user_data["email"],
|
||||
"password": user_data["password"]
|
||||
})
|
||||
login_response = await client.post(
|
||||
"/api/v1/login",
|
||||
json={"email": user_data["email"], "password": user_data["password"]},
|
||||
)
|
||||
token = login_response.json()["access_token"]
|
||||
|
||||
|
||||
# Get profile
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = await client.get("/api/v1/profile", headers=headers)
|
||||
@@ -70,16 +64,18 @@ class TestUserService:
|
||||
"""Test updating user profile"""
|
||||
# Register and login
|
||||
await client.post("/api/v1/register", json=user_data)
|
||||
login_response = await client.post("/api/v1/login", json={
|
||||
"email": user_data["email"],
|
||||
"password": user_data["password"]
|
||||
})
|
||||
login_response = await client.post(
|
||||
"/api/v1/login",
|
||||
json={"email": user_data["email"], "password": user_data["password"]},
|
||||
)
|
||||
token = login_response.json()["access_token"]
|
||||
|
||||
|
||||
# Update profile
|
||||
update_data = {"bio": "Updated bio text"}
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = await client.put("/api/v1/profile", json=update_data, headers=headers)
|
||||
response = await client.put(
|
||||
"/api/v1/profile", json=update_data, headers=headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["bio"] == "Updated bio text"
|
||||
assert data["bio"] == "Updated bio text"
|
||||
|
||||
Reference in New Issue
Block a user