fixing DQ issues

This commit is contained in:
2025-09-14 15:47:38 +02:00
parent 3eb18ef91e
commit 0ce708cf09
27 changed files with 430 additions and 214 deletions

View File

@@ -13,7 +13,7 @@ class TestStockService:
self.service = StockService()
def test_normalize_gtin_invalid(self):
"""Test GTIN normalization with invalid GTINs"""
"""Test GTIN normalization with invalid GTINs."""
# Completely invalid values that should return None
assert self.service.normalize_gtin("invalid") is None
assert self.service.normalize_gtin("abcdef") is None
@@ -36,7 +36,7 @@ class TestStockService:
assert self.service.normalize_gtin("12345") == "0000000012345"
def test_normalize_gtin_valid(self):
"""Test GTIN normalization with valid GTINs"""
"""Test GTIN normalization with valid GTINs."""
# Test various valid GTIN formats - these should remain unchanged
assert self.service.normalize_gtin("1234567890123") == "1234567890123" # EAN-13
assert self.service.normalize_gtin("123456789012") == "123456789012" # UPC-A
@@ -63,7 +63,7 @@ class TestStockService:
) # Truncated to 13
def test_normalize_gtin_edge_cases(self):
"""Test GTIN normalization edge cases"""
"""Test GTIN normalization edge cases."""
# Test numeric inputs
assert self.service.normalize_gtin(1234567890123) == "1234567890123"
assert self.service.normalize_gtin(123) == "0000000000123"
@@ -80,7 +80,7 @@ class TestStockService:
) # Letters removed
def test_set_stock_new_entry(self, db):
"""Test setting stock for a new GTIN/location combination"""
"""Test setting stock for a new GTIN/location combination."""
unique_id = str(uuid.uuid4())[:8]
stock_data = StockCreate(
gtin="1234567890123", location=f"WAREHOUSE_A_{unique_id}", quantity=100
@@ -93,7 +93,7 @@ class TestStockService:
assert result.quantity == 100
def test_set_stock_existing_entry(self, db, test_stock):
"""Test setting stock for an existing GTIN/location combination"""
"""Test setting stock for an existing GTIN/location combination."""
stock_data = StockCreate(
gtin=test_stock.gtin,
location=test_stock.location, # Use exact same location as test_stock
@@ -108,7 +108,7 @@ class TestStockService:
assert result.quantity == 200 # Should replace the original quantity
def test_set_stock_invalid_gtin(self, db):
"""Test setting stock with invalid GTIN"""
"""Test setting stock with invalid GTIN."""
stock_data = StockCreate(
gtin="invalid_gtin", location="WAREHOUSE_A", quantity=100
)
@@ -117,7 +117,7 @@ class TestStockService:
self.service.set_stock(db, stock_data)
def test_add_stock_new_entry(self, db):
"""Test adding stock for a new GTIN/location combination"""
"""Test adding stock for a new GTIN/location combination."""
unique_id = str(uuid.uuid4())[:8]
stock_data = StockAdd(
gtin="1234567890123", location=f"WAREHOUSE_B_{unique_id}", quantity=50
@@ -130,7 +130,7 @@ class TestStockService:
assert result.quantity == 50
def test_add_stock_existing_entry(self, db, test_stock):
"""Test adding stock to an existing GTIN/location combination"""
"""Test adding stock to an existing GTIN/location combination."""
original_quantity = test_stock.quantity
stock_data = StockAdd(
gtin=test_stock.gtin,
@@ -145,14 +145,14 @@ class TestStockService:
assert result.quantity == original_quantity + 25
def test_add_stock_invalid_gtin(self, db):
"""Test adding stock with invalid GTIN"""
"""Test adding stock with invalid GTIN."""
stock_data = StockAdd(gtin="invalid_gtin", location="WAREHOUSE_A", quantity=50)
with pytest.raises(ValueError, match="Invalid GTIN format"):
self.service.add_stock(db, stock_data)
def test_remove_stock_success(self, db, test_stock):
"""Test removing stock successfully"""
"""Test removing stock successfully."""
original_quantity = test_stock.quantity
remove_quantity = min(
10, original_quantity
@@ -171,7 +171,7 @@ class TestStockService:
assert result.quantity == original_quantity - remove_quantity
def test_remove_stock_insufficient_stock(self, db, test_stock):
"""Test removing more stock than available"""
"""Test removing more stock than available."""
stock_data = StockAdd(
gtin=test_stock.gtin,
location=test_stock.location, # Use exact same location as test_stock
@@ -185,7 +185,7 @@ class TestStockService:
self.service.remove_stock(db, stock_data)
def test_remove_stock_nonexistent_entry(self, db):
"""Test removing stock from non-existent GTIN/location"""
"""Test removing stock from non-existent GTIN/location."""
unique_id = str(uuid.uuid4())[:8]
stock_data = StockAdd(
gtin="9999999999999", location=f"NONEXISTENT_{unique_id}", quantity=10
@@ -195,14 +195,14 @@ class TestStockService:
self.service.remove_stock(db, stock_data)
def test_remove_stock_invalid_gtin(self, db):
"""Test removing stock with invalid GTIN"""
"""Test removing stock with invalid GTIN."""
stock_data = StockAdd(gtin="invalid_gtin", location="WAREHOUSE_A", quantity=10)
with pytest.raises(ValueError, match="Invalid GTIN format"):
self.service.remove_stock(db, stock_data)
def test_get_stock_by_gtin_success(self, db, test_stock, test_product):
"""Test getting stock summary by GTIN"""
"""Test getting stock summary by GTIN."""
result = self.service.get_stock_by_gtin(db, test_stock.gtin)
assert result.gtin == test_stock.gtin
@@ -213,7 +213,7 @@ class TestStockService:
assert result.product_title == test_product.title
def test_get_stock_by_gtin_multiple_locations(self, db, test_product):
"""Test getting stock summary with multiple locations"""
"""Test getting stock summary with multiple locations."""
unique_gtin = test_product.gtin
unique_id = str(uuid.uuid4())[:8]
@@ -237,17 +237,17 @@ class TestStockService:
assert len(result.locations) == 2
def test_get_stock_by_gtin_not_found(self, db):
"""Test getting stock for non-existent GTIN"""
"""Test getting stock for non-existent GTIN."""
with pytest.raises(ValueError, match="No stock found"):
self.service.get_stock_by_gtin(db, "9999999999999")
def test_get_stock_by_gtin_invalid_gtin(self, db):
"""Test getting stock with invalid GTIN"""
"""Test getting stock with invalid GTIN."""
with pytest.raises(ValueError, match="Invalid GTIN format"):
self.service.get_stock_by_gtin(db, "invalid_gtin")
def test_get_total_stock_success(self, db, test_stock, test_product):
"""Test getting total stock for a GTIN"""
"""Test getting total stock for a GTIN."""
result = self.service.get_total_stock(db, test_stock.gtin)
assert result["gtin"] == test_stock.gtin
@@ -256,19 +256,19 @@ class TestStockService:
assert result["locations_count"] == 1
def test_get_total_stock_invalid_gtin(self, db):
"""Test getting total stock with invalid GTIN"""
"""Test getting total stock with invalid GTIN."""
with pytest.raises(ValueError, match="Invalid GTIN format"):
self.service.get_total_stock(db, "invalid_gtin")
def test_get_all_stock_no_filters(self, db, test_stock):
"""Test getting all stock without filters"""
"""Test getting all stock without filters."""
result = self.service.get_all_stock(db)
assert len(result) >= 1
assert any(stock.gtin == test_stock.gtin for stock in result)
def test_get_all_stock_with_location_filter(self, db, test_stock):
"""Test getting all stock with location filter"""
"""Test getting all stock with location filter."""
result = self.service.get_all_stock(db, location=test_stock.location)
assert len(result) >= 1
@@ -278,14 +278,14 @@ class TestStockService:
)
def test_get_all_stock_with_gtin_filter(self, db, test_stock):
"""Test getting all stock with GTIN filter"""
"""Test getting all stock with GTIN filter."""
result = self.service.get_all_stock(db, gtin=test_stock.gtin)
assert len(result) >= 1
assert all(stock.gtin == test_stock.gtin for stock in result)
def test_get_all_stock_with_pagination(self, db):
"""Test getting all stock with pagination"""
"""Test getting all stock with pagination."""
unique_prefix = str(uuid.uuid4())[:8]
# Create multiple stock entries with unique GTINs and locations
@@ -305,7 +305,7 @@ class TestStockService:
) # Should be at most 2, might be less if other records exist
def test_update_stock_success(self, db, test_stock):
"""Test updating stock quantity"""
"""Test updating stock quantity."""
stock_update = StockUpdate(quantity=150)
result = self.service.update_stock(db, test_stock.id, stock_update)
@@ -314,14 +314,14 @@ class TestStockService:
assert result.quantity == 150
def test_update_stock_not_found(self, db):
"""Test updating non-existent stock entry"""
"""Test updating non-existent stock entry."""
stock_update = StockUpdate(quantity=150)
with pytest.raises(ValueError, match="Stock entry not found"):
self.service.update_stock(db, 99999, stock_update)
def test_delete_stock_success(self, db, test_stock):
"""Test deleting stock entry"""
"""Test deleting stock entry."""
stock_id = test_stock.id
result = self.service.delete_stock(db, stock_id)
@@ -333,12 +333,12 @@ class TestStockService:
assert deleted_stock is None
def test_delete_stock_not_found(self, db):
"""Test deleting non-existent stock entry"""
"""Test deleting non-existent stock entry."""
with pytest.raises(ValueError, match="Stock entry not found"):
self.service.delete_stock(db, 99999)
def test_get_stock_by_id_success(self, db, test_stock):
"""Test getting stock entry by ID"""
"""Test getting stock entry by ID."""
result = self.service.get_stock_by_id(db, test_stock.id)
assert result is not None
@@ -346,7 +346,7 @@ class TestStockService:
assert result.gtin == test_stock.gtin
def test_get_stock_by_id_not_found(self, db):
"""Test getting non-existent stock entry by ID"""
"""Test getting non-existent stock entry by ID."""
result = self.service.get_stock_by_id(db, 99999)
assert result is None
@@ -354,7 +354,7 @@ class TestStockService:
@pytest.fixture
def test_product_with_stock(db, test_stock):
"""Create a test product that corresponds to the test stock"""
"""Create a test product that corresponds to the test stock."""
product = Product(
product_id="STOCK_TEST_001",
title="Stock Test Product",