"""Tests for features utilities.""" from collections import namedtuple from unittest.mock import patch import pytest from src.utils import features Response = namedtuple('Response', 'status message') @patch('src.utils.features.pythonfeatures') @pytest.mark.parametrize( 'feature, account_id, response, expected', [ ('yesplease', 24601, Response(200, 'enabled'), True), ('ihavethis', 12345, Response(200, 'enabled'), True), ('nothanks', 24601, Response(200, 'control'), False), ('thiswillfail', 24601, Response(400, 'FAIL!'), False), ], ) def test_is_feature_enabled(pythonfeatures_mock, feature, account_id, response, expected): """Test checking if a feature is enabled.""" pythonfeatures_mock.get_single_feature_by_attributes.return_value = response result = features.is_feature_enabled(feature, account_id) assert result == expected pythonfeatures_mock.get_single_feature_by_attributes.assert_called_once_with( feature, {'vendor_id': account_id} ) @patch('src.utils.features.pythonfeatures') @pytest.mark.parametrize( 'feature, response, expected', [ ('yesplease', Response(200, 'enabled'), True), ('nothanks', Response(200, 'control'), False), ('thiswillfail', Response(400, 'FAIL!'), False), ], ) def test_is_feature_enabled_without_account_id(pythonfeatures_mock, feature, response, expected): """Test checking if a feature is enabled without account_id.""" pythonfeatures_mock.get_single_feature_by_attributes.return_value = response result = features.is_feature_enabled(feature) assert result == expected pythonfeatures_mock.get_single_feature_by_attributes.assert_called_once_with(feature, {})