vendor refactoring
This commit is contained in:
@@ -344,7 +344,7 @@ class TestMarketplaceImportJobAPI:
|
||||
import_data = {
|
||||
"url": "https://example.com/products.csv",
|
||||
"marketplace": "TestMarket",
|
||||
"vendor_code": "TEST_SHOP",
|
||||
"vendor_code": "TEST_VENDOR",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/marketplace/import-product", json=import_data)
|
||||
|
||||
@@ -70,13 +70,13 @@ class TestExportFunctionality:
|
||||
unique_suffix = str(uuid.uuid4())[:8]
|
||||
products = [
|
||||
MarketplaceProduct(
|
||||
marketplace_product_id=f"SHOP1_{unique_suffix}",
|
||||
title=f"Shop1 MarketplaceProduct {unique_suffix}",
|
||||
marketplace_product_id=f"VENDOR1_{unique_suffix}",
|
||||
title=f"Vendor1 MarketplaceProduct {unique_suffix}",
|
||||
vendor_name="TestVendor1"
|
||||
),
|
||||
MarketplaceProduct(
|
||||
marketplace_product_id=f"SHOP2_{unique_suffix}",
|
||||
title=f"Shop2 MarketplaceProduct {unique_suffix}",
|
||||
marketplace_product_id=f"VENDOR2_{unique_suffix}",
|
||||
title=f"Vendor2 MarketplaceProduct {unique_suffix}",
|
||||
vendor_name="TestVendor2"
|
||||
),
|
||||
]
|
||||
@@ -90,8 +90,8 @@ class TestExportFunctionality:
|
||||
assert response.status_code == 200
|
||||
|
||||
csv_content = response.content.decode("utf-8")
|
||||
assert f"SHOP1_{unique_suffix}" in csv_content
|
||||
assert f"SHOP2_{unique_suffix}" not in csv_content # Should be filtered out
|
||||
assert f"VENDOR1_{unique_suffix}" in csv_content
|
||||
assert f"VENDOR2_{unique_suffix}" not in csv_content # Should be filtered out
|
||||
|
||||
def test_csv_export_with_combined_filters_success(self, client, auth_headers, db):
|
||||
"""Test CSV export with combined marketplace and vendor filters successfully"""
|
||||
@@ -113,7 +113,7 @@ class TestExportFunctionality:
|
||||
marketplace_product_id=f"COMBO3_{unique_suffix}",
|
||||
title=f"Combo MarketplaceProduct 3 {unique_suffix}",
|
||||
marketplace="Amazon",
|
||||
vendor_name="OtherShop"
|
||||
vendor_name="OtherVendor"
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ class TestPagination:
|
||||
vendors =[]
|
||||
for i in range(15):
|
||||
vendor = Vendor(
|
||||
vendor_code=f"PAGESHOP{i:03d}_{unique_suffix}",
|
||||
vendor_code=f"PAGEVENDOR{i:03d}_{unique_suffix}",
|
||||
vendor_name=f"Pagination Vendor {i}",
|
||||
owner_id=test_user.id,
|
||||
is_active=True,
|
||||
@@ -203,7 +203,7 @@ class TestPagination:
|
||||
|
||||
# Test first page (assuming admin endpoint exists)
|
||||
response = client.get(
|
||||
"/api/v1/vendor ?limit=5&skip=0", headers=admin_headers
|
||||
"/api/v1/vendor?limit=5&skip=0", headers=admin_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
@@ -15,7 +15,7 @@ class TestVendorsAPI:
|
||||
"description": "A new test vendor ",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
||||
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -31,7 +31,7 @@ class TestVendorsAPI:
|
||||
"description": "Different description",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
||||
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
||||
|
||||
assert response.status_code == 409
|
||||
data = response.json()
|
||||
@@ -47,7 +47,7 @@ class TestVendorsAPI:
|
||||
"description": "Missing vendor code",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
||||
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
||||
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
@@ -64,7 +64,7 @@ class TestVendorsAPI:
|
||||
"description": "Vendor with empty name",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
||||
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
|
||||
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
@@ -87,7 +87,7 @@ class TestVendorsAPI:
|
||||
|
||||
def test_get_vendors_success(self, client, auth_headers, test_vendor):
|
||||
"""Test getting vendors list successfully"""
|
||||
response = client.get("/api/v1/vendor ", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -101,21 +101,21 @@ class TestVendorsAPI:
|
||||
def test_get_vendors_with_filters(self, client, auth_headers, test_vendor):
|
||||
"""Test getting vendors with filtering options"""
|
||||
# Test active_only filter
|
||||
response = client.get("/api/v1/vendor ?active_only=true", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor?active_only=true", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
for vendor in data["vendors"]:
|
||||
assert vendor ["is_active"] is True
|
||||
|
||||
# Test verified_only filter
|
||||
response = client.get("/api/v1/vendor ?verified_only=true", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor?verified_only=true", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
# Response should only contain verified vendors
|
||||
|
||||
def test_get_vendor_by_code_success(self, client, auth_headers, test_vendor):
|
||||
"""Test getting specific vendor successfully"""
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -125,7 +125,7 @@ class TestVendorsAPI:
|
||||
|
||||
def test_get_vendor_by_code_not_found(self, client, auth_headers):
|
||||
"""Test getting nonexistent vendor returns VendorNotFoundException"""
|
||||
response = client.get("/api/v1/vendor /NONEXISTENT", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor/NONEXISTENT", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 404
|
||||
data = response.json()
|
||||
@@ -144,7 +144,7 @@ class TestVendorsAPI:
|
||||
db.commit()
|
||||
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
|
||||
assert response.status_code == 403
|
||||
@@ -158,7 +158,7 @@ class TestVendorsAPI:
|
||||
"""Test accessing inactive vendor owned by another user returns UnauthorizedVendorAccessException"""
|
||||
# inactive_vendor fixture already creates an unverified, inactive vendor owned by other_user
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{inactive_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{inactive_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
|
||||
assert response.status_code == 403
|
||||
@@ -173,7 +173,7 @@ class TestVendorsAPI:
|
||||
# verified_vendor fixture creates a verified, active vendor owned by other_user
|
||||
# This should allow public access per your business logic
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{verified_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{verified_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -191,7 +191,7 @@ class TestVendorsAPI:
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
||||
headers=auth_headers,
|
||||
json=product_data
|
||||
)
|
||||
@@ -221,7 +221,7 @@ class TestVendorsAPI:
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
||||
headers=auth_headers,
|
||||
json=product_data
|
||||
)
|
||||
@@ -241,7 +241,7 @@ class TestVendorsAPI:
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
||||
headers=auth_headers,
|
||||
json=product_data
|
||||
)
|
||||
@@ -255,7 +255,7 @@ class TestVendorsAPI:
|
||||
def test_get_products_success(self, client, auth_headers, test_vendor, test_product):
|
||||
"""Test getting vendor products successfully"""
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
||||
headers=auth_headers
|
||||
)
|
||||
|
||||
@@ -263,21 +263,21 @@ class TestVendorsAPI:
|
||||
data = response.json()
|
||||
assert data["total"] >= 1
|
||||
assert len(data["products"]) >= 1
|
||||
assert "vendor " in data
|
||||
assert data["vendor "]["vendor_code"] == test_vendor.vendor_code
|
||||
assert "vendor" in data
|
||||
assert data["vendor"]["vendor_code"] == test_vendor.vendor_code
|
||||
|
||||
def test_get_products_with_filters(self, client, auth_headers, test_vendor):
|
||||
"""Test getting vendor products with filtering"""
|
||||
# Test active_only filter
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products?active_only=true",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products?active_only=true",
|
||||
headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Test featured_only filter
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products?featured_only=true",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products?featured_only=true",
|
||||
headers=auth_headers
|
||||
)
|
||||
assert response.status_code == 200
|
||||
@@ -285,7 +285,7 @@ class TestVendorsAPI:
|
||||
def test_get_products_from_nonexistent_vendor_not_found(self, client, auth_headers):
|
||||
"""Test getting products from nonexistent vendor returns VendorNotFoundException"""
|
||||
response = client.get(
|
||||
"/api/v1/vendor /NONEXISTENT/products",
|
||||
"/api/v1/vendor/NONEXISTENT/products",
|
||||
headers=auth_headers
|
||||
)
|
||||
|
||||
@@ -303,7 +303,7 @@ class TestVendorsAPI:
|
||||
|
||||
# Depending on your business logic, this might return an error
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
|
||||
# If your service enforces active vendor requirement
|
||||
@@ -326,7 +326,7 @@ class TestVendorsAPI:
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}/products",
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}/products",
|
||||
headers=auth_headers,
|
||||
json=product_data
|
||||
)
|
||||
@@ -340,7 +340,7 @@ class TestVendorsAPI:
|
||||
|
||||
def test_get_vendor_without_auth_returns_invalid_token(self, client):
|
||||
"""Test that vendor endpoints require authentication returns InvalidTokenException"""
|
||||
response = client.get("/api/v1/vendor ")
|
||||
response = client.get("/api/v1/vendor")
|
||||
|
||||
assert response.status_code == 401
|
||||
data = response.json()
|
||||
@@ -350,19 +350,19 @@ class TestVendorsAPI:
|
||||
def test_pagination_validation_errors(self, client, auth_headers):
|
||||
"""Test pagination parameter validation"""
|
||||
# Test negative skip
|
||||
response = client.get("/api/v1/vendor ?skip=-1", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor?skip=-1", headers=auth_headers)
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
assert data["error_code"] == "VALIDATION_ERROR"
|
||||
|
||||
# Test zero limit
|
||||
response = client.get("/api/v1/vendor ?limit=0", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor?limit=0", headers=auth_headers)
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
assert data["error_code"] == "VALIDATION_ERROR"
|
||||
|
||||
# Test excessive limit
|
||||
response = client.get("/api/v1/vendor ?limit=10000", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor?limit=10000", headers=auth_headers)
|
||||
assert response.status_code == 422
|
||||
data = response.json()
|
||||
assert data["error_code"] == "VALIDATION_ERROR"
|
||||
@@ -370,7 +370,7 @@ class TestVendorsAPI:
|
||||
def test_exception_structure_consistency(self, client, auth_headers):
|
||||
"""Test that all vendor exceptions follow the consistent LetzShopException structure"""
|
||||
# Test with a known error case
|
||||
response = client.get("/api/v1/vendor /NONEXISTENT", headers=auth_headers)
|
||||
response = client.get("/api/v1/vendor/NONEXISTENT", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 404
|
||||
data = response.json()
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestAuthentication:
|
||||
"/api/v1/admin/vendors",
|
||||
"/api/v1/marketplace/import-jobs",
|
||||
"/api/v1/marketplace/product",
|
||||
"/api/v1/vendor ",
|
||||
"/api/v1/vendor",
|
||||
"/api/v1/stats",
|
||||
"/api/v1/stock",
|
||||
]
|
||||
|
||||
@@ -42,7 +42,7 @@ class TestAuthorization:
|
||||
"""Test that users can only access their own vendors"""
|
||||
# Test accessing own vendor (should work)
|
||||
response = client.get(
|
||||
f"/api/v1/vendor /{test_vendor.vendor_code}", headers=auth_headers
|
||||
f"/api/v1/vendor/{test_vendor.vendor_code}", headers=auth_headers
|
||||
)
|
||||
# Response depends on your implementation - could be 200 or 404 if vendor doesn't belong to user
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestBackgroundTasks:
|
||||
job = MarketplaceImportJob(
|
||||
status="pending",
|
||||
source_url="http://example.com/test.csv",
|
||||
vendor_name="TESTSHOP",
|
||||
vendor_name="TESTVENDOR",
|
||||
marketplace="TestMarket",
|
||||
vendor_id=test_vendor.id,
|
||||
user_id=test_user.id,
|
||||
@@ -47,7 +47,7 @@ class TestBackgroundTasks:
|
||||
|
||||
# Run background task
|
||||
await process_marketplace_import(
|
||||
job_id, "http://example.com/test.csv", "TestMarket", "TESTSHOP", 1000
|
||||
job_id, "http://example.com/test.csv", "TestMarket", "TESTVENDOR", 1000
|
||||
)
|
||||
|
||||
# Re-query the job using the stored ID
|
||||
@@ -73,7 +73,7 @@ class TestBackgroundTasks:
|
||||
job = MarketplaceImportJob(
|
||||
status="pending",
|
||||
source_url="http://example.com/test.csv",
|
||||
vendor_name="TESTSHOP",
|
||||
vendor_name="TESTVENDOR",
|
||||
marketplace="TestMarket",
|
||||
vendor_id=test_vendor.id,
|
||||
user_id=test_user.id,
|
||||
@@ -102,7 +102,7 @@ class TestBackgroundTasks:
|
||||
job_id,
|
||||
"http://example.com/test.csv",
|
||||
"TestMarket",
|
||||
"TESTSHOP",
|
||||
"TESTVENDOR",
|
||||
1000,
|
||||
)
|
||||
except Exception:
|
||||
@@ -142,7 +142,7 @@ class TestBackgroundTasks:
|
||||
999, # Non-existent job ID
|
||||
"http://example.com/test.csv",
|
||||
"TestMarket",
|
||||
"TESTSHOP",
|
||||
"TESTVENDOR",
|
||||
1000,
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ class TestBackgroundTasks:
|
||||
job = MarketplaceImportJob(
|
||||
status="pending",
|
||||
source_url="http://example.com/test.csv",
|
||||
vendor_name="TESTSHOP",
|
||||
vendor_name="TESTVENDOR",
|
||||
marketplace="TestMarket",
|
||||
vendor_id=test_vendor.id,
|
||||
user_id=test_user.id,
|
||||
@@ -185,7 +185,7 @@ class TestBackgroundTasks:
|
||||
|
||||
# Run background task
|
||||
await process_marketplace_import(
|
||||
job_id, "http://example.com/test.csv", "TestMarket", "TESTSHOP", 1000
|
||||
job_id, "http://example.com/test.csv", "TestMarket", "TESTVENDOR", 1000
|
||||
)
|
||||
|
||||
# Re-query the job using the stored ID
|
||||
|
||||
@@ -64,21 +64,21 @@ class TestIntegrationFlows:
|
||||
"""Test vendor creation and product management workflow"""
|
||||
# 1. Create a vendor
|
||||
vendor_data = {
|
||||
"vendor_code": "FLOWSHOP",
|
||||
"vendor_name": "Integration Flow Shop",
|
||||
"vendor_code": "FLOWVENDOR",
|
||||
"vendor_name": "Integration Flow Vendor",
|
||||
"description": "Test vendor for integration",
|
||||
}
|
||||
|
||||
response = client.post("/api/v1/vendor ", headers=auth_headers, json=vendor_data)
|
||||
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",
|
||||
"marketplace_product_id": "VENDORFLOW001",
|
||||
"title": "Vendor Flow MarketplaceProduct",
|
||||
"price": "15.99",
|
||||
"marketplace": "ShopFlow",
|
||||
"marketplace": "VendorFlow",
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
@@ -91,7 +91,7 @@ class TestIntegrationFlows:
|
||||
# This would test the vendor -product association
|
||||
|
||||
# 4. Get vendor details
|
||||
response = client.get(f"/api/v1/vendor /{vendor ['vendor_code']}", headers=auth_headers)
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user