Files
orion/tests/integration/workflows/test_integration.py

132 lines
4.5 KiB
Python

# tests/test_integration.py
import pytest
@pytest.mark.integration
@pytest.mark.api
@pytest.mark.e2e
class TestIntegrationFlows:
def test_full_product_workflow(self, client, auth_headers):
"""Test complete product creation and management workflow"""
# 1. Create a product
product_data = {
"marketplace_product_id": "FLOW001",
"title": "Integration Test MarketplaceProduct",
"description": "Testing full workflow",
"price": "29.99",
"brand": "FlowBrand",
"gtin": "1111222233334",
"availability": "in stock",
"marketplace": "TestFlow",
}
response = client.post(
"/api/v1/marketplace/product", headers=auth_headers, json=product_data
)
assert response.status_code == 200
product = response.json()
# 2. Add stock for the product
stock_data = {
"gtin": product["gtin"],
"location": "MAIN_WAREHOUSE",
"quantity": 50,
}
response = client.post("/api/v1/stock", headers=auth_headers, json=stock_data)
assert response.status_code == 200
# 3. Get product with stock info
response = client.get(
f"/api/v1/marketplace/product/{product['marketplace_product_id']}", headers=auth_headers
)
assert response.status_code == 200
product_detail = response.json()
assert product_detail["stock_info"]["total_quantity"] == 50
# 4. Update product
update_data = {"title": "Updated Integration Test MarketplaceProduct"}
response = client.put(
f"/api/v1/marketplace/product/{product['marketplace_product_id']}",
headers=auth_headers,
json=update_data,
)
assert response.status_code == 200
# 5. Search for product
response = client.get(
"/api/v1/marketplace/product?search=Updated Integration", headers=auth_headers
)
assert response.status_code == 200
assert response.json()["total"] == 1
def test_product_workflow(self, client, auth_headers):
"""Test vendor creation and product management workflow"""
# 1. Create a vendor
vendor_data = {
"vendor_code": "FLOWSHOP",
"vendor_name": "Integration Flow Shop",
"description": "Test vendor for integration",
}
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
assert response.status_code == 200
vendor = response.json()
# 2. Create a product
product_data = {
"marketplace_product_id": "SHOPFLOW001",
"title": "Vendor Flow MarketplaceProduct",
"price": "15.99",
"marketplace": "ShopFlow",
}
response = client.post(
"/api/v1/marketplace/product", headers=auth_headers, json=product_data
)
assert response.status_code == 200
product = response.json()
# 3. Add product to vendor (if endpoint exists)
# This would test the vendor -product association
# 4. Get vendor details
response = client.get(f"/api/v1/vendor /{vendor ['vendor_code']}", headers=auth_headers)
assert response.status_code == 200
def test_stock_operations_workflow(self, client, auth_headers):
"""Test complete stock management workflow"""
gtin = "9999888877776"
location = "TEST_WAREHOUSE"
# 1. Set initial stock
response = client.post(
"/api/v1/stock",
headers=auth_headers,
json={"gtin": gtin, "location": location, "quantity": 100},
)
assert response.status_code == 200
# 2. Add more stock
response = client.post(
"/api/v1/stock/add",
headers=auth_headers,
json={"gtin": gtin, "location": location, "quantity": 25},
)
assert response.status_code == 200
assert response.json()["quantity"] == 125
# 3. Remove some stock
response = client.post(
"/api/v1/stock/remove",
headers=auth_headers,
json={"gtin": gtin, "location": location, "quantity": 30},
)
assert response.status_code == 200
assert response.json()["quantity"] == 95
# 4. Check total stock
response = client.get(f"/api/v1/stock/{gtin}/total", headers=auth_headers)
assert response.status_code == 200
assert response.json()["total_quantity"] == 95