vendor refactoring

This commit is contained in:
2025-10-05 19:49:03 +02:00
parent 0114b6c46e
commit f569995883
17 changed files with 121 additions and 121 deletions

View File

@@ -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)

View File

@@ -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"
),
]

View File

@@ -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()

View File

@@ -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()