code quality run
This commit is contained in:
@@ -5,24 +5,25 @@ import pytest
|
||||
class TestErrorHandling:
|
||||
def test_invalid_json(self, client, auth_headers):
|
||||
"""Test handling of invalid JSON"""
|
||||
response = client.post("/api/v1/product",
|
||||
headers=auth_headers,
|
||||
content="invalid json")
|
||||
response = client.post(
|
||||
"/api/v1/product", headers=auth_headers, content="invalid json"
|
||||
)
|
||||
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
def test_missing_required_fields(self, client, auth_headers):
|
||||
"""Test handling of missing required fields"""
|
||||
response = client.post("/api/v1/product",
|
||||
headers=auth_headers,
|
||||
json={"title": "Test"}) # Missing product_id
|
||||
response = client.post(
|
||||
"/api/v1/product", headers=auth_headers, json={"title": "Test"}
|
||||
) # Missing product_id
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_invalid_authentication(self, client):
|
||||
"""Test handling of invalid authentication"""
|
||||
response = client.get("/api/v1/product",
|
||||
headers={"Authorization": "Bearer invalid_token"})
|
||||
response = client.get(
|
||||
"/api/v1/product", headers={"Authorization": "Bearer invalid_token"}
|
||||
)
|
||||
|
||||
assert response.status_code == 401 # Token is not valid
|
||||
|
||||
@@ -38,8 +39,10 @@ class TestErrorHandling:
|
||||
"""Test handling of duplicate resource creation"""
|
||||
product_data = {
|
||||
"product_id": test_product.product_id, # Duplicate ID
|
||||
"title": "Another Product"
|
||||
"title": "Another Product",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/product", headers=auth_headers, json=product_data)
|
||||
response = client.post(
|
||||
"/api/v1/product", headers=auth_headers, json=product_data
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
Reference in New Issue
Block a user