"""Test for service_optout model.""" import pytest from sqlalchemy.exc import IntegrityError from carveouts.models.service_opt_out import ( add_product_opt_outs, get_product_opt_outs, get_vendor_opt_outs, ) def test_get_vendor_opt_outs(db_fixture: None) -> None: """Test get_vendor_opt_outs.""" actual_response = get_vendor_opt_outs(10) assert actual_response == {1} def test_get_product_opt_outs(db_fixture: None) -> None: """Test get_product_opt_outs.""" actual_response = get_product_opt_outs(123) assert actual_response == {1} @pytest.mark.parametrize( "distribution_types, expected_result", [ ([], 0), ( [1, 2, 3], 3, ), ], ) def test_add_product_carveouts( distribution_types: list[int], expected_result: int, db_fixture: None, ) -> None: add_product_opt_outs( product_id=123, upc=1234568768889, distribution_types=distribution_types, ) assert len(get_product_opt_outs(123)) == expected_result def test_add_product_carveouts_integrity_error(db_fixture: None) -> None: upc = 1234568768889 with pytest.raises(IntegrityError) as exc: add_product_opt_outs( product_id=123, upc=upc, distribution_types=[1, 1, 1, 2], ) assert f"Duplicate entry '{upc}-1'" in str(exc.value)