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

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