marketplace refactoring
This commit is contained in:
@@ -12,7 +12,7 @@ class TestAuthentication:
|
||||
"/api/v1/admin/users",
|
||||
"/api/v1/admin/shops",
|
||||
"/api/v1/marketplace/import-jobs",
|
||||
"/api/v1/product",
|
||||
"/api/v1/marketplace/product",
|
||||
"/api/v1/shop",
|
||||
"/api/v1/stats",
|
||||
"/api/v1/stock",
|
||||
@@ -26,7 +26,7 @@ class TestAuthentication:
|
||||
"""Test protected endpoints with invalid token"""
|
||||
headers = {"Authorization": "Bearer invalid_token_here"}
|
||||
|
||||
response = client.get("/api/v1/product", headers=headers)
|
||||
response = client.get("/api/v1/marketplace/product", headers=headers)
|
||||
assert response.status_code == 401 # Token is not valid
|
||||
|
||||
def test_debug_direct_bearer(self, client):
|
||||
@@ -49,7 +49,7 @@ class TestAuthentication:
|
||||
|
||||
# Test 2: Try a regular endpoint that uses get_current_user
|
||||
response2 = client.get(
|
||||
"/api/v1/product"
|
||||
"/api/v1/marketplace/product"
|
||||
) # or any endpoint with get_current_user
|
||||
print(f"Regular endpoint - Status: {response2.status_code}")
|
||||
try:
|
||||
@@ -64,12 +64,12 @@ class TestAuthentication:
|
||||
if hasattr(route, "path") and hasattr(route, "methods"):
|
||||
print(f"{list(route.methods)} {route.path}")
|
||||
|
||||
print("\n=== Testing Product Endpoint Variations ===")
|
||||
print("\n=== Testing MarketplaceProduct Endpoint Variations ===")
|
||||
variations = [
|
||||
"/api/v1/product", # Your current attempt
|
||||
"/api/v1/product/", # With trailing slash
|
||||
"/api/v1/product/list", # With list endpoint
|
||||
"/api/v1/product/all", # With all endpoint
|
||||
"/api/v1/marketplace/product", # Your current attempt
|
||||
"/api/v1/marketplace/product/", # With trailing slash
|
||||
"/api/v1/marketplace/product/list", # With list endpoint
|
||||
"/api/v1/marketplace/product/all", # With all endpoint
|
||||
]
|
||||
|
||||
for path in variations:
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestAuthorization:
|
||||
def test_regular_endpoints_with_user_access(self, client, auth_headers):
|
||||
"""Test that regular users can access non-admin endpoints"""
|
||||
user_endpoints = [
|
||||
"/api/v1/product",
|
||||
"/api/v1/marketplace/product",
|
||||
"/api/v1/stats",
|
||||
"/api/v1/stock",
|
||||
]
|
||||
|
||||
@@ -11,7 +11,7 @@ class TestInputValidation:
|
||||
malicious_search = "'; DROP TABLE products; --"
|
||||
|
||||
response = client.get(
|
||||
f"/api/v1/product?search={malicious_search}", headers=auth_headers
|
||||
f"/api/v1/marketplace/product?search={malicious_search}", headers=auth_headers
|
||||
)
|
||||
|
||||
# Should not crash and should return normal response
|
||||
@@ -25,12 +25,12 @@ class TestInputValidation:
|
||||
# xss_payload = "<script>alert('xss')</script>"
|
||||
#
|
||||
# product_data = {
|
||||
# "product_id": "XSS_TEST",
|
||||
# "marketplace_product_id": "XSS_TEST",
|
||||
# "title": xss_payload,
|
||||
# "description": xss_payload,
|
||||
# }
|
||||
#
|
||||
# response = client.post("/api/v1/product", headers=auth_headers, json=product_data)
|
||||
# response = client.post("/api/v1/marketplace/product", headers=auth_headers, json=product_data)
|
||||
#
|
||||
# assert response.status_code == 200
|
||||
# data = response.json()
|
||||
@@ -40,24 +40,24 @@ class TestInputValidation:
|
||||
def test_parameter_validation(self, client, auth_headers):
|
||||
"""Test parameter validation for API endpoints"""
|
||||
# Test invalid pagination parameters
|
||||
response = client.get("/api/v1/product?limit=-1", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=-1", headers=auth_headers)
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
response = client.get("/api/v1/product?skip=-1", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?skip=-1", headers=auth_headers)
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
def test_json_validation(self, client, auth_headers):
|
||||
"""Test JSON validation for POST requests"""
|
||||
# Test invalid JSON structure
|
||||
response = client.post(
|
||||
"/api/v1/product", headers=auth_headers, content="invalid json content"
|
||||
"/api/v1/marketplace/product", headers=auth_headers, content="invalid json content"
|
||||
)
|
||||
assert response.status_code == 422 # JSON decode error
|
||||
|
||||
# Test missing required fields
|
||||
response = client.post(
|
||||
"/api/v1/product",
|
||||
"/api/v1/marketplace/product",
|
||||
headers=auth_headers,
|
||||
json={"title": "Test Product"}, # Missing required product_id
|
||||
json={"title": "Test MarketplaceProduct"}, # Missing required marketplace_product_id
|
||||
)
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
Reference in New Issue
Block a user