"""Unit tests for feature_flag logic.""" from unittest.mock import Mock from unittest.mock import patch import pytest from src.logic import feature_flag @pytest.mark.parametrize( 'complete_product,test_description', [ ({}, 'no label key'), ({'label': None}, 'label is None'), ({'label': {}}, 'label is empty dict'), ({'label': {'vendor_id': None}}, 'vendor_id is None'), ({'label': {'vendor_id': 0}}, 'vendor_id is 0'), ({'label': {'subaccount_id': '67890'}}, 'no vendor_id, only subaccount_id'), ] ) @patch('src.logic.feature_flag.get_single_feature_by_attributes') def test_is_eligible_for_auto_approval_returns_false( mock_get_feature, complete_product, test_description ): """Test is_eligible_for_auto_approval returns False without calling feature flag.""" result = feature_flag.is_eligible_for_auto_approval(complete_product) assert result is False mock_get_feature.assert_not_called() @pytest.mark.parametrize( 'complete_product,expected_attributes,feature_flag_value,expected_result', [ ( {'label': {'vendor_id': '12345'}}, {'vendor_id': '12345'}, 'enabled', True, ), ( {'label': {'vendor_id': '12345'}}, {'vendor_id': '12345'}, 'disabled', False, ), ( {'label': {'vendor_id': '12345', 'subaccount_id': None}}, {'vendor_id': '12345'}, 'enabled', True, ), ( {'label': {'vendor_id': '12345', 'subaccount_id': 0}}, {'vendor_id': '12345'}, 'enabled', True, ), ( {'label': {'vendor_id': '12345', 'subaccount_id': '67890'}}, {'vendor_id': '12345', 'subaccount_id': '67890'}, 'enabled', True, ), ( {'label': {'vendor_id': '12345', 'subaccount_id': '67890'}}, {'vendor_id': '12345', 'subaccount_id': '67890'}, 'disabled', False, ), ] ) @patch('src.logic.feature_flag.get_single_feature_by_attributes') def test_is_eligible_for_auto_approval( mock_get_feature, complete_product, expected_attributes, feature_flag_value, expected_result ): """Test is_eligible_for_auto_approval calls feature flag and returns correct result.""" mock_result = Mock() mock_result.message = feature_flag_value mock_get_feature.return_value = mock_result result = feature_flag.is_eligible_for_auto_approval(complete_product) assert result is expected_result mock_get_feature.assert_called_once_with( feature_flag.config.AUTO_APPROVAL_FF_NAME, expected_attributes )