"""Test feature helpers.""" from unittest.mock import MagicMock from unittest.mock import patch from moneyhub.constants.constants import JWTKeys from moneyhub.utils import features @patch('moneyhub.utils.features.g') @patch('moneyhub.utils.features.pythonfeatures') def test_is_feature_enabled(mock_pythonfeatures, mock_g): """Test checking if a feature is enabled.""" feature = 'my_awesome_feature' identity_id = '1234' mock_g.return_value = MagicMock(token={JWTKeys.ORCHARD_IDENTITY_ID: identity_id}) mock_pythonfeatures.get_single_feature_by_attributes.return_value = MagicMock( status=200, message='enabled') result = features.is_feature_enabled(feature) assert result is True mock_pythonfeatures.get_single_feature_by_attributes.assert_called_once_with( feature, {'identity_id': identity_id}) @patch('moneyhub.utils.features.g') @patch('moneyhub.utils.features.pythonfeatures') def test_is_feature_enabled_no_token(mock_pythonfeatures, mock_g): """Test checking if a feature is enabled when no token is specified.""" feature = 'my_awesome_feature' mock_g.return_value = MagicMock(token=None) mock_pythonfeatures.get_single_feature_by_attributes.return_value = MagicMock( status=200, message='enabled') result = features.is_feature_enabled(feature) assert result is True mock_pythonfeatures.get_single_feature_by_attributes.assert_called_once_with( feature, {'identity_id': None})