marketplace refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# tests/integration/api/v1/test_pagination.py
|
||||
import pytest
|
||||
|
||||
from models.database.product import Product
|
||||
from models.database.marketplace_product import MarketplaceProduct
|
||||
from models.database.shop import Shop
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -18,9 +18,9 @@ class TestPagination:
|
||||
# Create multiple products
|
||||
products = []
|
||||
for i in range(25):
|
||||
product = Product(
|
||||
product_id=f"PAGE{i:03d}_{unique_suffix}",
|
||||
title=f"Pagination Test Product {i}",
|
||||
product = MarketplaceProduct(
|
||||
marketplace_product_id=f"PAGE{i:03d}_{unique_suffix}",
|
||||
title=f"Pagination Test MarketplaceProduct {i}",
|
||||
marketplace="PaginationTest",
|
||||
)
|
||||
products.append(product)
|
||||
@@ -29,7 +29,7 @@ class TestPagination:
|
||||
db.commit()
|
||||
|
||||
# Test first page
|
||||
response = client.get("/api/v1/product?limit=10&skip=0", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=10&skip=0", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data["products"]) == 10
|
||||
@@ -38,21 +38,21 @@ class TestPagination:
|
||||
assert data["limit"] == 10
|
||||
|
||||
# Test second page
|
||||
response = client.get("/api/v1/product?limit=10&skip=10", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=10&skip=10", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data["products"]) == 10
|
||||
assert data["skip"] == 10
|
||||
|
||||
# Test last page (should have remaining products)
|
||||
response = client.get("/api/v1/product?limit=10&skip=20", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=10&skip=20", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data["products"]) >= 5 # At least 5 remaining from our test set
|
||||
|
||||
def test_pagination_boundary_negative_skip_validation_error(self, client, auth_headers):
|
||||
"""Test negative skip parameter returns ValidationException"""
|
||||
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
|
||||
data = response.json()
|
||||
@@ -63,7 +63,7 @@ class TestPagination:
|
||||
|
||||
def test_pagination_boundary_zero_limit_validation_error(self, client, auth_headers):
|
||||
"""Test zero limit parameter returns ValidationException"""
|
||||
response = client.get("/api/v1/product?limit=0", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=0", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
@@ -73,7 +73,7 @@ class TestPagination:
|
||||
|
||||
def test_pagination_boundary_excessive_limit_validation_error(self, client, auth_headers):
|
||||
"""Test excessive limit parameter returns ValidationException"""
|
||||
response = client.get("/api/v1/product?limit=10000", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=10000", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
@@ -84,7 +84,7 @@ class TestPagination:
|
||||
def test_pagination_beyond_available_records(self, client, auth_headers, db):
|
||||
"""Test pagination beyond available records returns empty results"""
|
||||
# Test skip beyond available records
|
||||
response = client.get("/api/v1/product?skip=10000&limit=10", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?skip=10000&limit=10", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -101,9 +101,9 @@ class TestPagination:
|
||||
# Create products with same brand for filtering
|
||||
products = []
|
||||
for i in range(15):
|
||||
product = Product(
|
||||
product_id=f"FILTPAGE{i:03d}_{unique_suffix}",
|
||||
title=f"Filter Page Product {i}",
|
||||
product = MarketplaceProduct(
|
||||
marketplace_product_id=f"FILTPAGE{i:03d}_{unique_suffix}",
|
||||
title=f"Filter Page MarketplaceProduct {i}",
|
||||
brand="FilterBrand",
|
||||
marketplace="FilterMarket",
|
||||
)
|
||||
@@ -114,7 +114,7 @@ class TestPagination:
|
||||
|
||||
# Test first page with filter
|
||||
response = client.get(
|
||||
"/api/v1/product?brand=FilterBrand&limit=5&skip=0",
|
||||
"/api/v1/marketplace/product?brand=FilterBrand&limit=5&skip=0",
|
||||
headers=auth_headers
|
||||
)
|
||||
|
||||
@@ -124,13 +124,13 @@ class TestPagination:
|
||||
assert data["total"] >= 15 # At least our test products
|
||||
|
||||
# Verify all products have the filtered brand
|
||||
test_products = [p for p in data["products"] if p["product_id"].endswith(unique_suffix)]
|
||||
test_products = [p for p in data["products"] if p["marketplace_product_id"].endswith(unique_suffix)]
|
||||
for product in test_products:
|
||||
assert product["brand"] == "FilterBrand"
|
||||
|
||||
# Test second page with same filter
|
||||
response = client.get(
|
||||
"/api/v1/product?brand=FilterBrand&limit=5&skip=5",
|
||||
"/api/v1/marketplace/product?brand=FilterBrand&limit=5&skip=5",
|
||||
headers=auth_headers
|
||||
)
|
||||
|
||||
@@ -141,7 +141,7 @@ class TestPagination:
|
||||
|
||||
def test_pagination_default_values(self, client, auth_headers):
|
||||
"""Test pagination with default values"""
|
||||
response = client.get("/api/v1/product", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -157,9 +157,9 @@ class TestPagination:
|
||||
# Create products with predictable ordering
|
||||
products = []
|
||||
for i in range(10):
|
||||
product = Product(
|
||||
product_id=f"CONSIST{i:03d}_{unique_suffix}",
|
||||
title=f"Consistent Product {i:03d}",
|
||||
product = MarketplaceProduct(
|
||||
marketplace_product_id=f"CONSIST{i:03d}_{unique_suffix}",
|
||||
title=f"Consistent MarketplaceProduct {i:03d}",
|
||||
marketplace="ConsistentMarket",
|
||||
)
|
||||
products.append(product)
|
||||
@@ -168,14 +168,14 @@ class TestPagination:
|
||||
db.commit()
|
||||
|
||||
# Get first page
|
||||
response1 = client.get("/api/v1/product?limit=5&skip=0", headers=auth_headers)
|
||||
response1 = client.get("/api/v1/marketplace/product?limit=5&skip=0", headers=auth_headers)
|
||||
assert response1.status_code == 200
|
||||
first_page_ids = [p["product_id"] for p in response1.json()["products"]]
|
||||
first_page_ids = [p["marketplace_product_id"] for p in response1.json()["products"]]
|
||||
|
||||
# Get second page
|
||||
response2 = client.get("/api/v1/product?limit=5&skip=5", headers=auth_headers)
|
||||
response2 = client.get("/api/v1/marketplace/product?limit=5&skip=5", headers=auth_headers)
|
||||
assert response2.status_code == 200
|
||||
second_page_ids = [p["product_id"] for p in response2.json()["products"]]
|
||||
second_page_ids = [p["marketplace_product_id"] for p in response2.json()["products"]]
|
||||
|
||||
# Verify no overlap between pages
|
||||
overlap = set(first_page_ids) & set(second_page_ids)
|
||||
@@ -249,7 +249,7 @@ class TestPagination:
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
response = client.get("/api/v1/product?skip=1000&limit=10", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?skip=1000&limit=10", headers=auth_headers)
|
||||
end_time = time.time()
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -262,26 +262,26 @@ class TestPagination:
|
||||
def test_pagination_with_invalid_parameters_types(self, client, auth_headers):
|
||||
"""Test pagination with invalid parameter types returns ValidationException"""
|
||||
# Test non-numeric skip
|
||||
response = client.get("/api/v1/product?skip=invalid", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?skip=invalid", headers=auth_headers)
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
assert data["error_code"] == "VALIDATION_ERROR"
|
||||
|
||||
# Test non-numeric limit
|
||||
response = client.get("/api/v1/product?limit=invalid", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?limit=invalid", headers=auth_headers)
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
assert data["error_code"] == "VALIDATION_ERROR"
|
||||
|
||||
# Test float values (should be converted or rejected)
|
||||
response = client.get("/api/v1/product?skip=10.5&limit=5.5", headers=auth_headers)
|
||||
response = client.get("/api/v1/marketplace/product?skip=10.5&limit=5.5", headers=auth_headers)
|
||||
assert response.status_code in [200, 422] # Depends on implementation
|
||||
|
||||
def test_empty_dataset_pagination(self, client, auth_headers):
|
||||
"""Test pagination behavior with empty dataset"""
|
||||
# Use a filter that should return no results
|
||||
response = client.get(
|
||||
"/api/v1/product?brand=NonexistentBrand999&limit=10&skip=0",
|
||||
"/api/v1/marketplace/product?brand=NonexistentBrand999&limit=10&skip=0",
|
||||
headers=auth_headers
|
||||
)
|
||||
|
||||
@@ -294,7 +294,7 @@ class TestPagination:
|
||||
|
||||
def test_exception_structure_in_pagination_errors(self, client, auth_headers):
|
||||
"""Test that pagination validation errors follow consistent exception structure"""
|
||||
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
|
||||
data = response.json()
|
||||
|
||||
Reference in New Issue
Block a user