workflows testing
This commit is contained in:
130
tests/integration/workflows/test_integration.py
Normal file
130
tests/integration/workflows/test_integration.py
Normal file
@@ -0,0 +1,130 @@
|
||||
# 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 = {
|
||||
"product_id": "FLOW001",
|
||||
"title": "Integration Test Product",
|
||||
"description": "Testing full workflow",
|
||||
"price": "29.99",
|
||||
"brand": "FlowBrand",
|
||||
"gtin": "1111222233334",
|
||||
"availability": "in stock",
|
||||
"marketplace": "TestFlow",
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
"/api/v1/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/product/{product['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 Product"}
|
||||
response = client.put(
|
||||
f"/api/v1/product/{product['product_id']}",
|
||||
headers=auth_headers,
|
||||
json=update_data,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# 5. Search for product
|
||||
response = client.get(
|
||||
"/api/v1/product?search=Updated Integration", headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["total"] == 1
|
||||
|
||||
def test_shop_product_workflow(self, client, auth_headers):
|
||||
"""Test shop creation and product management workflow"""
|
||||
# 1. Create a shop
|
||||
shop_data = {
|
||||
"shop_code": "FLOWSHOP",
|
||||
"shop_name": "Integration Flow Shop",
|
||||
"description": "Test shop for integration",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/shop", headers=auth_headers, json=shop_data)
|
||||
assert response.status_code == 200
|
||||
shop = response.json()
|
||||
|
||||
# 2. Create a product
|
||||
product_data = {
|
||||
"product_id": "SHOPFLOW001",
|
||||
"title": "Shop Flow Product",
|
||||
"price": "15.99",
|
||||
"marketplace": "ShopFlow",
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
"/api/v1/product", headers=auth_headers, json=product_data
|
||||
)
|
||||
assert response.status_code == 200
|
||||
product = response.json()
|
||||
|
||||
# 3. Add product to shop (if endpoint exists)
|
||||
# This would test the shop-product association
|
||||
|
||||
# 4. Get shop details
|
||||
response = client.get(f"/api/v1/shop/{shop['shop_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
|
||||
Reference in New Issue
Block a user