workflows testing
This commit is contained in:
73
tests/integration/api/v1/test_export.py
Normal file
73
tests/integration/api/v1/test_export.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# tests/test_export.py
|
||||
import csv
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
from models.database.product import Product
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.api
|
||||
@pytest.mark.performance # for the performance test
|
||||
class TestExportFunctionality:
|
||||
def test_csv_export_basic(self, client, auth_headers, test_product):
|
||||
"""Test basic CSV export functionality"""
|
||||
response = client.get("/api/v1/export-csv", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"] == "text/csv; charset=utf-8"
|
||||
|
||||
# Parse CSV content
|
||||
csv_content = response.content.decode("utf-8")
|
||||
csv_reader = csv.reader(StringIO(csv_content))
|
||||
|
||||
# Check header row
|
||||
header = next(csv_reader)
|
||||
expected_fields = ["product_id", "title", "description", "price", "marketplace"]
|
||||
for field in expected_fields:
|
||||
assert field in header
|
||||
|
||||
def test_csv_export_with_marketplace_filter(self, client, auth_headers, db):
|
||||
"""Test CSV export with marketplace filtering"""
|
||||
# Create products in different marketplaces
|
||||
products = [
|
||||
Product(product_id="EXP1", title="Product 1", marketplace="Amazon"),
|
||||
Product(product_id="EXP2", title="Product 2", marketplace="eBay"),
|
||||
]
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
response = client.get(
|
||||
"/api/v1/export-csv?marketplace=Amazon", headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
csv_content = response.content.decode("utf-8")
|
||||
assert "EXP1" in csv_content
|
||||
assert "EXP2" not in csv_content # Should be filtered out
|
||||
|
||||
def test_csv_export_performance(self, client, auth_headers, db):
|
||||
"""Test CSV export performance with many products"""
|
||||
# Create many products
|
||||
products = []
|
||||
for i in range(1000):
|
||||
product = Product(
|
||||
product_id=f"PERF{i:04d}",
|
||||
title=f"Performance Product {i}",
|
||||
marketplace="Performance",
|
||||
)
|
||||
products.append(product)
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
response = client.get("/api/v1/export-csv", headers=auth_headers)
|
||||
end_time = time.time()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert end_time - start_time < 10.0 # Should complete within 10 seconds
|
||||
116
tests/integration/api/v1/test_filtering.py
Normal file
116
tests/integration/api/v1/test_filtering.py
Normal file
@@ -0,0 +1,116 @@
|
||||
# tests/test_filtering.py
|
||||
import pytest
|
||||
|
||||
from models.database.product import Product
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.api
|
||||
@pytest.mark.products
|
||||
class TestFiltering:
|
||||
def test_product_brand_filter(self, client, auth_headers, db):
|
||||
"""Test filtering products by brand"""
|
||||
# Create products with different brands
|
||||
products = [
|
||||
Product(product_id="BRAND1", title="Product 1", brand="BrandA"),
|
||||
Product(product_id="BRAND2", title="Product 2", brand="BrandB"),
|
||||
Product(product_id="BRAND3", title="Product 3", brand="BrandA"),
|
||||
]
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
# Filter by BrandA
|
||||
response = client.get("/api/v1/product?brand=BrandA", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 2
|
||||
|
||||
# Filter by BrandB
|
||||
response = client.get("/api/v1/product?brand=BrandB", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 1
|
||||
|
||||
def test_product_marketplace_filter(self, client, auth_headers, db):
|
||||
"""Test filtering products by marketplace"""
|
||||
products = [
|
||||
Product(product_id="MKT1", title="Product 1", marketplace="Amazon"),
|
||||
Product(product_id="MKT2", title="Product 2", marketplace="eBay"),
|
||||
Product(product_id="MKT3", title="Product 3", marketplace="Amazon"),
|
||||
]
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
response = client.get(
|
||||
"/api/v1/product?marketplace=Amazon", headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 2
|
||||
|
||||
def test_product_search_filter(self, client, auth_headers, db):
|
||||
"""Test searching products by text"""
|
||||
products = [
|
||||
Product(
|
||||
product_id="SEARCH1", title="Apple iPhone", description="Smartphone"
|
||||
),
|
||||
Product(
|
||||
product_id="SEARCH2",
|
||||
title="Samsung Galaxy",
|
||||
description="Android phone",
|
||||
),
|
||||
Product(
|
||||
product_id="SEARCH3", title="iPad Tablet", description="Apple tablet"
|
||||
),
|
||||
]
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
# Search for "Apple"
|
||||
response = client.get("/api/v1/product?search=Apple", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 2 # iPhone and iPad
|
||||
|
||||
# Search for "phone"
|
||||
response = client.get("/api/v1/product?search=phone", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 2 # iPhone and Galaxy
|
||||
|
||||
def test_combined_filters(self, client, auth_headers, db):
|
||||
"""Test combining multiple filters"""
|
||||
products = [
|
||||
Product(
|
||||
product_id="COMBO1",
|
||||
title="Apple iPhone",
|
||||
brand="Apple",
|
||||
marketplace="Amazon",
|
||||
),
|
||||
Product(
|
||||
product_id="COMBO2",
|
||||
title="Apple iPad",
|
||||
brand="Apple",
|
||||
marketplace="eBay",
|
||||
),
|
||||
Product(
|
||||
product_id="COMBO3",
|
||||
title="Samsung Phone",
|
||||
brand="Samsung",
|
||||
marketplace="Amazon",
|
||||
),
|
||||
]
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
|
||||
# Filter by brand AND marketplace
|
||||
response = client.get(
|
||||
"/api/v1/product?brand=Apple&marketplace=Amazon", headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["total"] == 1 # Only iPhone matches both
|
||||
Reference in New Issue
Block a user