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

@@ -15,15 +15,15 @@ class Product(Base, TimestampMixin):
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
marketplace_product_id = Column(Integer, ForeignKey("marketplace_products.id"), nullable=False)
# Shop-specific overrides (can override the main product data)
product_id = Column(String) # Shop's internal product ID
# Vendor-specific overrides (can override the main product data)
product_id = Column(String) # Vendor's internal product ID
price = Column(Float) # Override main product price
sale_price = Column(Float)
currency = Column(String)
availability = Column(String) # Override availability
condition = Column(String)
# Shop-specific metadata
# Vendor-specific metadata
is_featured = Column(Boolean, default=False)
is_active = Column(Boolean, default=True)
display_order = Column(Integer, default=0)

View File

@@ -21,7 +21,7 @@ class Stock(Base, TimestampMixin):
vendor_id = Column(Integer, ForeignKey("vendors.id")) # Optional: vendor -specific stock
# Relationships
vendor = relationship("Shop")
vendor = relationship("Vendor")
# Composite unique constraint to prevent duplicate GTIN-location combinations
__table_args__ = (

View File

@@ -9,7 +9,7 @@ def test_marketplace_import_job(db, test_vendor, test_user):
"""Create a test marketplace import job"""
job = MarketplaceImportJob(
marketplace="amazon",
vendor_name="Test Import Shop",
vendor_name="Test Import Vendor",
status="completed",
source_url="https://test-marketplace.example.com/import",
vendor_id=test_vendor.id,
@@ -30,7 +30,7 @@ def create_test_marketplace_import_job(db, vendor_id, user_id, **kwargs):
"""Helper function to create MarketplaceImportJob with defaults"""
defaults = {
"marketplace": "test",
"vendor_name": "Test Shop",
"vendor_name": "Test Vendor",
"status": "pending",
"source_url": "https://test.example.com/import",
"vendor_id": vendor_id,

View File

@@ -41,7 +41,7 @@ def unique_product(db):
gtin=f"123456789{unique_id[:4]}",
availability="in stock",
marketplace="Letzshop",
vendor_name=f"UniqueShop_{unique_id}",
vendor_name=f"UniqueVendor_{unique_id}",
google_product_category=f"UniqueCategory_{unique_id}",
)
db.add(marketplace_product)
@@ -65,7 +65,7 @@ def multiple_products(db):
currency="EUR",
brand=f"MultiBrand_{i % 3}", # Create 3 different brands
marketplace=f"MultiMarket_{i % 2}", # Create 2 different marketplaces
vendor_name=f"MultiShop_{i}",
vendor_name=f"MultiVendor_{i}",
google_product_category=f"MultiCategory_{i % 2}", # Create 2 different categories
gtin=f"1234567890{i}{unique_id[:2]}",
)

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,

View File

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

View File

@@ -64,8 +64,8 @@ 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",
}
@@ -75,10 +75,10 @@ class TestIntegrationFlows:
# 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(

View File

@@ -33,7 +33,7 @@ class TestErrorHandling:
response = client.post(
"/api/v1/vendor",
headers=auth_headers,
json={"vendor_code": "TESTSHOP"}
json={"vendor_code": "TESTVENDOR"}
)
assert response.status_code == 422
@@ -49,8 +49,8 @@ class TestErrorHandling:
"/api/v1/vendor",
headers=auth_headers,
json={
"vendor_code": "INVALID@SHOP!",
"vendor_name": "Test Shop"
"vendor_code": "INVALID@VENDOR!",
"vendor_name": "Test Vendor"
}
)
@@ -99,7 +99,7 @@ class TestErrorHandling:
data = response.json()
assert data["error_code"] == "VENDOR_NOT_FOUND"
assert data["status_code"] == 404
assert data["details"]["resource_type"] == "Shop"
assert data["details"]["resource_type"] == "Vendor"
assert data["details"]["identifier"] == "NONEXISTENT"
def test_product_not_found(self, client, auth_headers):
@@ -117,7 +117,7 @@ class TestErrorHandling:
"""Test creating vendor with duplicate vendor code"""
vendor_data = {
"vendor_code": test_vendor.vendor_code,
"vendor_name": "Duplicate Shop"
"vendor_name": "Duplicate Vendor"
}
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
@@ -171,7 +171,7 @@ class TestErrorHandling:
vendors_created = []
for i in range(6): # Assume limit is 5
vendor_data = {
"vendor_code": f"SHOP{i:03d}",
"vendor_code": f"VENDOR{i:03d}",
"vendor_name": f"Test Vendor {i}"
}
response = client.post("/api/v1/vendor", headers=auth_headers, json=vendor_data)
@@ -266,8 +266,8 @@ class TestErrorHandling:
"""Test handling of unusually large payloads"""
large_description = "x" * 100000 # Very long description
vendor_data = {
"vendor_code": "LARGESHOP",
"vendor_name": "Large Shop",
"vendor_code": "LARGEVENDOR",
"vendor_name": "Large Vendor",
"description": large_description
}

View File

@@ -97,7 +97,7 @@ class TestMarketplaceService:
request = MarketplaceImportJobRequest(
url="https://example.com/products.csv",
marketplace="Amazon",
vendor_code="INVALID_SHOP",
vendor_code="INVALID_VENDOR",
batch_size=1000,
)
@@ -106,7 +106,7 @@ class TestMarketplaceService:
exception = exc_info.value
assert exception.error_code == "VENDOR_NOT_FOUND"
assert "INVALID_SHOP" in exception.message
assert "INVALID_VENDOR" in exception.message
def test_create_import_job_unauthorized_access(self, db, test_vendor, test_user, other_user):
"""Test import job creation with unauthorized vendor access"""
@@ -452,7 +452,7 @@ class TestMarketplaceService:
request = MarketplaceImportJobRequest(
url="https://example.com/products.csv",
marketplace="Amazon",
vendor_code="TEST_SHOP",
vendor_code="TEST_VENDOR",
batch_size=1000,
)

View File

@@ -41,7 +41,7 @@ class TestStatsService:
brand="DifferentBrand",
google_product_category="Different Category",
marketplace="Amazon",
vendor_name="AmazonShop",
vendor_name="AmazonVendor",
price="15.99",
currency="EUR",
),
@@ -51,7 +51,7 @@ class TestStatsService:
brand="ThirdBrand",
google_product_category="Third Category",
marketplace="eBay",
vendor_name="eBayShop",
vendor_name="eBayVendor",
price="25.99",
currency="USD",
),
@@ -61,7 +61,7 @@ class TestStatsService:
brand="TestBrand", # Same as test_marketplace_product
google_product_category="Different Category",
marketplace="Letzshop", # Same as test_marketplace_product
vendor_name="DifferentShop",
vendor_name="DifferentVendor",
price="35.99",
currency="EUR",
),
@@ -143,7 +143,7 @@ class TestStatsService:
title="Amazon MarketplaceProduct 1",
brand="AmazonBrand1",
marketplace="Amazon",
vendor_name="AmazonShop1",
vendor_name="AmazonVendor1",
price="20.00",
currency="EUR",
),
@@ -152,7 +152,7 @@ class TestStatsService:
title="Amazon MarketplaceProduct 2",
brand="AmazonBrand2",
marketplace="Amazon",
vendor_name="AmazonShop2",
vendor_name="AmazonVendor2",
price="25.00",
currency="EUR",
),
@@ -161,7 +161,7 @@ class TestStatsService:
title="eBay MarketplaceProduct",
brand="eBayBrand",
marketplace="eBay",
vendor_name="eBayShop",
vendor_name="eBayVendor",
price="30.00",
currency="USD",
),
@@ -196,7 +196,7 @@ class TestStatsService:
marketplace_product_id="NULLMARKET001",
title="MarketplaceProduct without marketplace",
marketplace=None,
vendor_name="SomeShop",
vendor_name="SomeVendor",
brand="SomeBrand",
price="10.00",
currency="EUR",
@@ -291,7 +291,7 @@ class TestStatsService:
marketplace_product_id="MARKET001",
title="Marketplace MarketplaceProduct 1",
marketplace="Amazon",
vendor_name="AmazonShop",
vendor_name="AmazonVendor",
price="10.00",
currency="EUR",
),
@@ -299,7 +299,7 @@ class TestStatsService:
marketplace_product_id="MARKET002",
title="Marketplace MarketplaceProduct 2",
marketplace="eBay",
vendor_name="eBayShop",
vendor_name="eBayVendor",
price="15.00",
currency="EUR",
),
@@ -317,18 +317,18 @@ class TestStatsService:
# Add products with different vendor names
products = [
MarketplaceProduct(
marketplace_product_id="SHOP001",
marketplace_product_id="PRODUCT001",
title="Vendor MarketplaceProduct 1",
marketplace="Test",
vendor_name="ShopA",
vendor_name="VendorA",
price="10.00",
currency="EUR",
),
MarketplaceProduct(
marketplace_product_id="SHOP002",
marketplace_product_id="PRODUCT002",
title="Vendor MarketplaceProduct 2",
marketplace="Test",
vendor_name="ShopB",
vendor_name="VendorB",
price="15.00",
currency="EUR",
),
@@ -338,7 +338,7 @@ class TestStatsService:
count = self.service._get_unique_vendors_count(db)
assert count >= 2 # At least ShopA and ShopB, plus test_marketplace_product vendor
assert count >= 2 # At least VendorA and VendorB, plus test_marketplace_product vendor
assert isinstance(count, int)
def test_get_stock_statistics(self, db, test_stock):
@@ -379,7 +379,7 @@ class TestStatsService:
title="Specific MarketplaceProduct 1",
brand="SpecificBrand1",
marketplace="SpecificMarket",
vendor_name="SpecificShop1",
vendor_name="SpecificVendor1",
price="10.00",
currency="EUR",
),
@@ -388,7 +388,7 @@ class TestStatsService:
title="Specific MarketplaceProduct 2",
brand="SpecificBrand2",
marketplace="SpecificMarket",
vendor_name="SpecificShop2",
vendor_name="SpecificVendor2",
price="15.00",
currency="EUR",
),
@@ -397,7 +397,7 @@ class TestStatsService:
title="Other MarketplaceProduct",
brand="OtherBrand",
marketplace="OtherMarket",
vendor_name="OtherShop",
vendor_name="OtherVendor",
price="20.00",
currency="EUR",
),
@@ -417,7 +417,7 @@ class TestStatsService:
# Create products for specific marketplace
marketplace_products = [
MarketplaceProduct(
marketplace_product_id="SHOPTEST001",
marketplace_product_id="MARKETTEST001",
title="Vendor Test MarketplaceProduct 1",
brand="TestBrand",
marketplace="TestMarketplace",
@@ -426,7 +426,7 @@ class TestStatsService:
currency="EUR",
),
MarketplaceProduct(
marketplace_product_id="SHOPTEST002",
marketplace_product_id="MARKETTEST002",
title="Vendor Test MarketplaceProduct 2",
brand="TestBrand",
marketplace="TestMarketplace",
@@ -452,7 +452,7 @@ class TestStatsService:
marketplace_product_id="COUNT001",
title="Count MarketplaceProduct 1",
marketplace="CountMarketplace",
vendor_name="CountShop",
vendor_name="CountVendor",
price="10.00",
currency="EUR",
),
@@ -460,7 +460,7 @@ class TestStatsService:
marketplace_product_id="COUNT002",
title="Count MarketplaceProduct 2",
marketplace="CountMarketplace",
vendor_name="CountShop",
vendor_name="CountVendor",
price="15.00",
currency="EUR",
),
@@ -468,7 +468,7 @@ class TestStatsService:
marketplace_product_id="COUNT003",
title="Count MarketplaceProduct 3",
marketplace="CountMarketplace",
vendor_name="CountShop",
vendor_name="CountVendor",
price="20.00",
currency="EUR",
),

View File

@@ -19,7 +19,7 @@ from models.schemas.product import ProductCreate
@pytest.mark.unit
@pytest.mark.vendors
class TestVendorService:
"""Test suite for ShopService following the application's exception patterns"""
"""Test suite for VendorService following the application's exception patterns"""
def setup_method(self):
"""Setup method following the same pattern as admin service tests"""
@@ -29,7 +29,7 @@ class TestVendorService:
"""Test successful vendor creation"""
vendor_data = VendorCreate(
vendor_code="NEWVENDOR",
vendor_name="New Test Shop",
vendor_name="New Test Vendor",
description="A new test vendor ",
)
@@ -42,7 +42,7 @@ class TestVendorService:
def test_create_vendor_admin_auto_verify(self, db, test_admin, vendor_factory):
"""Test admin creates verified vendor automatically"""
vendor_data = VendorCreate(vendor_code="ADMINSHOP", vendor_name="Admin Test Shop")
vendor_data = VendorCreate(vendor_code="ADMINVENDOR", vendor_name="Admin Test Vendor")
vendor = self.service.create_vendor(db, vendor_data, test_admin)
@@ -65,7 +65,7 @@ class TestVendorService:
def test_create_vendor_invalid_data_empty_code(self, db, test_user):
"""Test vendor creation fails with empty vendor code"""
vendor_data = VendorCreate(vendor_code="", vendor_name="Test Shop")
vendor_data = VendorCreate(vendor_code="", vendor_name="Test Vendor")
with pytest.raises(InvalidVendorDataException) as exc_info:
self.service.create_vendor(db, vendor_data, test_user)
@@ -88,7 +88,7 @@ class TestVendorService:
def test_create_vendor_invalid_code_format(self, db, test_user):
"""Test vendor creation fails with invalid vendor code format"""
vendor_data = VendorCreate(vendor_code="INVALID@CODE!", vendor_name="Test Shop")
vendor_data = VendorCreate(vendor_code="INVALID@CODE!", vendor_name="Test Vendor")
with pytest.raises(InvalidVendorDataException) as exc_info:
self.service.create_vendor(db, vendor_data, test_user)
@@ -163,7 +163,7 @@ class TestVendorService:
exception = exc_info.value
assert exception.status_code == 404
assert exception.error_code == "VENDOR_NOT_FOUND"
assert exception.details["resource_type"] == "Shop"
assert exception.details["resource_type"] == "Vendor"
assert exception.details["identifier"] == "NONEXISTENT"
def test_get_vendor_by_code_access_denied(self, db, test_user, inactive_vendor):
@@ -266,7 +266,7 @@ class TestVendorService:
monkeypatch.setattr(db, "commit", mock_commit)
vendor_data = VendorCreate(vendor_code="NEWVENDOR", vendor_name="Test Shop")
vendor_data = VendorCreate(vendor_code="NEWVENDOR", vendor_name="Test Vendor")
with pytest.raises(ValidationException) as exc_info:
self.service.create_vendor(db, vendor_data, test_user)