# tests/test_services.py import pytest from app.services.product_service import ProductService from models.api_models import ProductCreate from models.database_models import Product class TestProductService: def setup_method(self): self.service = ProductService() def test_create_product_with_gtin_validation(self, db): """Test product creation with GTIN validation""" product_data = ProductCreate( product_id="SVC001", title="Service Test Product", gtin="1234567890123", price="19.99", marketplace="TestMarket" ) product = self.service.create_product(db, product_data) assert product.product_id == "SVC001" assert product.gtin == "1234567890123" assert product.marketplace == "TestMarket" def test_create_product_invalid_gtin(self, db): """Test product creation with invalid GTIN""" product_data = ProductCreate( product_id="SVC002", title="Service Test Product", gtin="invalid_gtin", price="19.99" ) with pytest.raises(ValueError, match="Invalid GTIN format"): self.service.create_product(db, product_data) def test_get_products_with_filters(self, db, test_product): """Test getting products with various filters""" products, total = self.service.get_products_with_filters( db, brand="TestBrand" ) assert total == 1 assert len(products) == 1 assert products[0].brand == "TestBrand" def test_get_products_with_search(self, db, test_product): """Test getting products with search""" products, total = self.service.get_products_with_filters( db, search="Test Product" ) assert total == 1 assert len(products) == 1