Fix tests using the new api root
This commit is contained in:
@@ -11,7 +11,7 @@ def test_create_user(client, auth_headers):
|
||||
"password": "newpassword123"
|
||||
}
|
||||
|
||||
response = client.post("/users/", json=user_data, headers=auth_headers)
|
||||
response = client.post("/api/v1/users/", json=user_data, headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
@@ -30,13 +30,13 @@ def test_create_user_unauthorized(client):
|
||||
"password": "password123"
|
||||
}
|
||||
|
||||
response = client.post("/users/", json=user_data)
|
||||
response = client.post("/api/v1/users/", json=user_data)
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_get_users(client, auth_headers, admin_user, regular_user):
|
||||
"""Test retrieving all users."""
|
||||
response = client.get("/users/", headers=auth_headers)
|
||||
response = client.get("/api/v1/users/", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
users = response.json()
|
||||
@@ -49,7 +49,7 @@ def test_get_users(client, auth_headers, admin_user, regular_user):
|
||||
|
||||
def test_get_user_by_id(client, auth_headers, regular_user):
|
||||
"""Test retrieving a specific user by ID."""
|
||||
response = client.get(f"/users/{regular_user.id}", headers=auth_headers)
|
||||
response = client.get(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
@@ -59,7 +59,7 @@ def test_get_user_by_id(client, auth_headers, regular_user):
|
||||
|
||||
def test_get_nonexistent_user(client, auth_headers):
|
||||
"""Test retrieving a non-existent user."""
|
||||
response = client.get("/users/99999", headers=auth_headers)
|
||||
response = client.get("/api/v1/users/99999", headers=auth_headers)
|
||||
assert response.status_code == 404
|
||||
assert "not found" in response.json()["detail"].lower()
|
||||
|
||||
@@ -72,7 +72,7 @@ def test_update_user(client, auth_headers, regular_user):
|
||||
}
|
||||
|
||||
response = client.patch(
|
||||
f"/users/{regular_user.id}",
|
||||
f"/api/v1/users/{regular_user.id}",
|
||||
json=update_data,
|
||||
headers=auth_headers
|
||||
)
|
||||
@@ -92,7 +92,7 @@ def test_update_user_password(client, auth_headers, regular_user):
|
||||
}
|
||||
|
||||
response = client.patch(
|
||||
f"/users/{regular_user.id}",
|
||||
f"/api/v1/users/{regular_user.id}",
|
||||
json=update_data,
|
||||
headers=auth_headers
|
||||
)
|
||||
@@ -100,7 +100,7 @@ def test_update_user_password(client, auth_headers, regular_user):
|
||||
|
||||
# Verify password can be used for login
|
||||
login_response = client.post(
|
||||
"/token",
|
||||
"/api/v1/token",
|
||||
data={"username": regular_user.name, "password": "new_password_456"}
|
||||
)
|
||||
assert login_response.status_code == 200
|
||||
@@ -109,24 +109,24 @@ def test_update_user_password(client, auth_headers, regular_user):
|
||||
def test_update_nonexistent_user(client, auth_headers):
|
||||
"""Test updating a non-existent user."""
|
||||
update_data = {"name": "updated"}
|
||||
response = client.patch("/users/99999", json=update_data, headers=auth_headers)
|
||||
response = client.patch("/api/v1/users/99999", json=update_data, headers=auth_headers)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_delete_user(client, auth_headers, regular_user):
|
||||
"""Test deleting a user."""
|
||||
response = client.delete(f"/users/{regular_user.id}", headers=auth_headers)
|
||||
response = client.delete(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
assert "deleted successfully" in response.json()["message"].lower()
|
||||
|
||||
# Verify user is deleted
|
||||
response = client.get(f"/users/{regular_user.id}", headers=auth_headers)
|
||||
response = client.get(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_delete_nonexistent_user(client, auth_headers):
|
||||
"""Test deleting a non-existent user."""
|
||||
response = client.delete("/users/99999", headers=auth_headers)
|
||||
response = client.delete("/api/v1/users/99999", headers=auth_headers)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@@ -134,17 +134,17 @@ def test_user_operations_by_non_admin(client, user_auth_headers):
|
||||
"""Test that non-admin users cannot perform admin operations."""
|
||||
# Try to create a user
|
||||
response = client.post(
|
||||
"/users/",
|
||||
"/api/v1/users/",
|
||||
json={"name": "test", "password": "pass"},
|
||||
headers=user_auth_headers
|
||||
)
|
||||
assert response.status_code == 403
|
||||
|
||||
# Try to get users
|
||||
response = client.get("/users/", headers=user_auth_headers)
|
||||
response = client.get("/api/v1/users/", headers=user_auth_headers)
|
||||
assert response.status_code == 403
|
||||
|
||||
# Try to delete the admin user (if ID is known)
|
||||
# This would require knowing the admin user ID
|
||||
# response = client.delete(f"/users/{admin_id}", headers=user_auth_headers)
|
||||
# response = client.delete(f"/api/v1/users/{admin_id}", headers=user_auth_headers)
|
||||
# assert response.status_code == 403
|
||||
|
||||
Reference in New Issue
Block a user