"""Test for Releases model.""" from unittest.mock import MagicMock, patch import pytest from sqlalchemy.exc import SQLAlchemyError from carveouts.exceptions import ProductInvalid from carveouts.models import releases from carveouts.models.schemas import Product def test_for_invalid_product(db_fixture: None) -> None: """Test to check invalid product id.""" with pytest.raises( ProductInvalid, match="^400 Bad Request: Product ID 1 is invalid$" ): releases.get_product(1) def test_for_valid_product(db_fixture: None) -> None: """Test to check valid product id.""" actual_response = releases.get_product(123) assert actual_response == Product(product_id=123, upc=1234567890) @patch( "carveouts.models.releases.db_connector.db_session", side_effect=SQLAlchemyError("some sql error"), ) def test_get_product_error(db_session_mock: MagicMock) -> None: """Test check_product_is_valid with exception.""" with pytest.raises(SQLAlchemyError) as exc: releases.get_product(123) assert str(exc.value) == "some sql error"