"""Tests for features.""" from collections import namedtuple from unittest.mock import MagicMock, patch import pytest from abacus_common_logic.utils import features Response = namedtuple('Response', 'message status') @patch('abacus_common_logic.utils.features.pythonfeatures') @pytest.mark.parametrize( 'feature, response, expected', [ ('yes_please', Response('enabled', 200), True), ('i_have_this', Response('enabled', 200), True), ('no_thanks', Response('control', 200), False), ], ) def test_is_feature_enabled_without_context(features_mock, feature, response, expected): """Test checking if a feature is enabled.""" features_mock.get_single_feature_by_attributes.return_value = response result = features.is_feature_enabled(feature) assert result == expected features_mock.get_single_feature_by_attributes.assert_called_with(feature, {}) @patch('abacus_common_logic.utils.features.pythonfeatures') @pytest.mark.parametrize( 'feature, response, expected', [ ('yes_please', Response('enabled', 200), True), ('i_have_this', Response('enabled', 200), True), ('no_thanks', Response('control', 200), False), ], ) def test_is_feature_enabled_with_context(features_mock, feature, response, expected): """Test checking if a feature is enabled.""" mocked_context = MagicMock() features_mock.get_single_feature.return_value = response result = features.is_feature_enabled(feature, mocked_context) assert result == expected features_mock.get_single_feature.assert_called_with(feature, mocked_context)