# tests/test_performance.py import pytest import time from models.database_models import Product class TestPerformance: def test_product_list_performance(self, client, auth_headers, db): """Test performance of product listing with many products""" # Create multiple products products = [] for i in range(100): product = Product( product_id=f"PERF{i:03d}", title=f"Performance Test Product {i}", price=f"{i}.99", marketplace="Performance" ) products.append(product) db.add_all(products) db.commit() # Time the request start_time = time.time() response = client.get("/api/v1/product?limit=100", headers=auth_headers) end_time = time.time() assert response.status_code == 200 assert len(response.json()["products"]) == 100 assert end_time - start_time < 2.0 # Should complete within 2 seconds def test_search_performance(self, client, auth_headers, db): """Test search performance""" # Create products with searchable content products = [] for i in range(50): product = Product( product_id=f"SEARCH{i:03d}", title=f"Searchable Product {i}", description=f"This is a searchable product number {i}", brand="SearchBrand", marketplace="SearchMarket" ) products.append(product) db.add_all(products) db.commit() # Time search request start_time = time.time() response = client.get("/api/v1/product?search=Searchable", headers=auth_headers) end_time = time.time() assert response.status_code == 200 assert response.json()["total"] == 50 assert end_time - start_time < 1.0 # Search should be fast