test updates to take into account exception management
This commit is contained in:
@@ -217,7 +217,8 @@ class StockService:
|
||||
)
|
||||
return existing_stock
|
||||
|
||||
except (StockNotFoundException, InsufficientStockException, InvalidQuantityException, NegativeStockException):
|
||||
except (StockValidationException, StockNotFoundException, InsufficientStockException, InvalidQuantityException,
|
||||
NegativeStockException):
|
||||
db.rollback()
|
||||
raise # Re-raise custom exceptions
|
||||
except Exception as e:
|
||||
@@ -564,21 +565,6 @@ class StockService:
|
||||
raise StockNotFoundException(str(stock_id))
|
||||
return stock_entry
|
||||
|
||||
# Legacy methods for backward compatibility (deprecated)
|
||||
def normalize_gtin(self, gtin_value) -> Optional[str]:
|
||||
"""Normalize GTIN format. DEPRECATED: Use _normalize_gtin."""
|
||||
logger.warning("normalize_gtin is deprecated, use _normalize_gtin")
|
||||
return self._normalize_gtin(gtin_value)
|
||||
|
||||
def get_stock_by_id(self, db: Session, stock_id: int) -> Optional[Stock]:
|
||||
"""Get stock by ID. DEPRECATED: Use proper exception handling."""
|
||||
logger.warning("get_stock_by_id is deprecated, use proper exception handling")
|
||||
try:
|
||||
return db.query(Stock).filter(Stock.id == stock_id).first()
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting stock by ID: {str(e)}")
|
||||
return None
|
||||
|
||||
|
||||
# Create service instance
|
||||
stock_service = StockService()
|
||||
|
||||
Reference in New Issue
Block a user