Application fully migrated to modular approach

This commit is contained in:
2025-09-13 21:30:40 +02:00
parent c7d6b33cd5
commit b9fe91ab88
38 changed files with 509 additions and 265 deletions

View File

@@ -3,6 +3,7 @@ import pytest
class TestProductsAPI:
def test_get_products_empty(self, client, auth_headers):
"""Test getting products when none exist"""
response = client.get("/api/v1/product", headers=auth_headers)
@@ -14,7 +15,7 @@ class TestProductsAPI:
def test_get_products_with_data(self, client, auth_headers, test_product):
"""Test getting products with data"""
response = client.get("/api/v1/products", headers=auth_headers)
response = client.get("/api/v1/product", headers=auth_headers)
assert response.status_code == 200
data = response.json()
@@ -25,17 +26,17 @@ class TestProductsAPI:
def test_get_products_with_filters(self, client, auth_headers, test_product):
"""Test filtering products"""
# Test brand filter
response = client.get("/api/v1/products?brand=TestBrand", headers=auth_headers)
response = client.get("/api/v1/product?brand=TestBrand", headers=auth_headers)
assert response.status_code == 200
assert response.json()["total"] == 1
# Test marketplace filter
response = client.get("/api/v1/products?marketplace=Letzshop", headers=auth_headers)
response = client.get("/api/v1/product?marketplace=Letzshop", headers=auth_headers)
assert response.status_code == 200
assert response.json()["total"] == 1
# Test search
response = client.get("/api/v1/products?search=Test", headers=auth_headers)
response = client.get("/api/v1/product?search=Test", headers=auth_headers)
assert response.status_code == 200
assert response.json()["total"] == 1
@@ -52,7 +53,7 @@ class TestProductsAPI:
"marketplace": "Amazon"
}
response = client.post("/api/v1/products", headers=auth_headers, json=product_data)
response = client.post("/api/v1/product", headers=auth_headers, json=product_data)
assert response.status_code == 200
data = response.json()
@@ -63,19 +64,32 @@ class TestProductsAPI:
def test_create_product_duplicate_id(self, client, auth_headers, test_product):
"""Test creating product with duplicate ID"""
product_data = {
"product_id": "TEST001", # Same as test_product
"title": "Another Product",
"price": "20.00"
"product_id": test_product.product_id,
"title": test_product.title,
"description": "A new product",
"price": "15.99",
"brand": "NewBrand",
"gtin": "9876543210987",
"availability": "in stock",
"marketplace": "Amazon"
}
response = client.post("/api/v1/products", headers=auth_headers, json=product_data)
response = client.post("/api/v1/product", headers=auth_headers, json=product_data)
# Debug output
print(f"Status Code: {response.status_code}")
print(f"Response Content: {response.content}")
try:
print(f"Response JSON: {response.json()}")
except:
print("Could not parse response as JSON")
assert response.status_code == 400
assert "already exists" in response.json()["detail"]
def test_get_product_by_id(self, client, auth_headers, test_product):
"""Test getting specific product"""
response = client.get(f"/api/v1/products/{test_product.product_id}", headers=auth_headers)
response = client.get(f"/api/v1/product/{test_product.product_id}", headers=auth_headers)
assert response.status_code == 200
data = response.json()
@@ -84,7 +98,7 @@ class TestProductsAPI:
def test_get_nonexistent_product(self, client, auth_headers):
"""Test getting nonexistent product"""
response = client.get("/api/v1/products/NONEXISTENT", headers=auth_headers)
response = client.get("/api/v1/product/NONEXISTENT", headers=auth_headers)
assert response.status_code == 404
@@ -96,7 +110,7 @@ class TestProductsAPI:
}
response = client.put(
f"/api/v1/products/{test_product.product_id}",
f"/api/v1/product/{test_product.product_id}",
headers=auth_headers,
json=update_data
)
@@ -109,14 +123,14 @@ class TestProductsAPI:
def test_delete_product(self, client, auth_headers, test_product):
"""Test deleting product"""
response = client.delete(
f"/api/v1/products/{test_product.product_id}",
f"/api/v1/product/{test_product.product_id}",
headers=auth_headers
)
assert response.status_code == 200
assert "deleted successfully" in response.json()["message"]
def test_products_require_auth(self, client):
def test_get_product_without_auth(self, client):
"""Test that product endpoints require authentication"""
response = client.get("/api/v1/products")
assert response.status_code == 403
response = client.get("/api/v1/product")
assert response.status_code == 401 # No authorization header