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
|
||||
Reference in New Issue
Block a user