"""Test cases for assets validators.""" from unittest.mock import MagicMock, patch import pytest from assets.constants import error from assets.exceptions import ( BitsPerSampleNotFound, DesiredBitsPerSampleNotFound, ProductNotFound, ) from assets.logic import validate_bit_depth_by_upc as validators from assets.models import asset_final, ows_product def test_is_desired_bit_depth_found(monkeypatch: pytest.MonkeyPatch) -> None: """Test with valid Product having desired bit depth.""" product_id = 123456 desired_bit_depth = 64 mock_response = [64] monkeypatch.setattr( asset_final, "get_bit_depths_for_products", MagicMock(return_value=mock_response), ) validators._is_desired_bit_depth_found(product_id, desired_bit_depth) def test_no_desired_bit_depth_found(monkeypatch: pytest.MonkeyPatch) -> None: """Test with valid UPC not having desired bit depth.""" product_id = 123456 desired_bit_depth = 64 mock_response = [16] monkeypatch.setattr( asset_final, "get_bit_depths_for_products", MagicMock(return_value=mock_response), ) with pytest.raises(DesiredBitsPerSampleNotFound) as exc: validators._is_desired_bit_depth_found(product_id, desired_bit_depth) assert exc.value.description == error.DESIRED_BIT_DEPTH_NOT_FOUND @patch("assets.logic.validate_bit_depth_by_upc.asset_final.get_bit_depths_for_products") def test_is_bit_depth_uniform_with_error(mock_asset_final: MagicMock) -> None: """Test _is_bit_depth_uniform with an error.""" product_id = 123456 desired_bit_depth = 64 mock_asset_final.side_effect = BitsPerSampleNotFound(error.NO_BITS_PER_SAMPLE_FOUND) with pytest.raises(BitsPerSampleNotFound) as exc: validators._is_desired_bit_depth_found(product_id, desired_bit_depth) assert exc.value.description == error.NO_BITS_PER_SAMPLE_FOUND def test_check_for_desired_bit_depth_with_invalid_upc( monkeypatch: pytest.MonkeyPatch, ) -> None: """Test check_for_desired_bit_depth by providing invalid UPC.""" product_id = 123 desired_bit_depth = 64 monkeypatch.setattr( ows_product, "get_product_by_id", MagicMock(side_effect=ProductNotFound(error.ERROR_RELEASE_NOT_FOUND)), True, ) with pytest.raises(ProductNotFound) as exc: validators.check_for_desired_bit_depth(product_id, desired_bit_depth) assert exc.value.description == error.ERROR_RELEASE_NOT_FOUND def test_check_for_desired_bit_depth(monkeypatch: pytest.MonkeyPatch) -> None: """Test check_for_desired_bit_depth having desired bit depth.""" product_id = 123456 desired_bit_depth = 64 monkeypatch.setattr( ows_product, "get_product_by_id", MagicMock(return_value={"upc": 191018729677}), ) monkeypatch.setattr( validators, "_is_desired_bit_depth_found", MagicMock(return_value=None), ) validators.check_for_desired_bit_depth(product_id, desired_bit_depth) def test_check_for_desired_bit_depth_not_found(monkeypatch: pytest.MonkeyPatch) -> None: """Test check_for_desired_bit_depth with no desired bit depth.""" product_id = 123456 desired_bit_depth = 64 monkeypatch.setattr( ows_product, "get_product_by_id", MagicMock(return_value={"upc": 191018729677}), ) monkeypatch.setattr( validators, "_is_desired_bit_depth_found", MagicMock( side_effect=DesiredBitsPerSampleNotFound(error.DESIRED_BIT_DEPTH_NOT_FOUND) ), True, ) with pytest.raises(DesiredBitsPerSampleNotFound) as exc: validators.check_for_desired_bit_depth(product_id, desired_bit_depth) assert exc.value.description == error.DESIRED_BIT_DEPTH_NOT_FOUND def test_check_for_desired_bit_depth_with_null_bit_depths( monkeypatch: pytest.MonkeyPatch, ) -> None: """Test check_for_desired_bit_depth with null bit depth.""" product_id = 123456 desired_bit_depth = 24 monkeypatch.setattr( asset_final, "get_bit_depths_for_products", MagicMock(side_effect=BitsPerSampleNotFound(error.NO_BITS_PER_SAMPLE_FOUND)), True, ) with pytest.raises(BitsPerSampleNotFound) as exc: validators._is_desired_bit_depth_found(product_id, desired_bit_depth) assert exc.value.description == error.NO_BITS_PER_SAMPLE_FOUND