"""Test Harness.io features model.""" import json from unittest.mock import call import pytest from owsresponse import response from pythonfeatures import pythonfeatures from blacklist_manager.models import features @pytest.mark.parametrize( ( "test_description", "get_single_feature_by_attributes_result", "expected_result", ), [ ( "success enabled", response.Response("enabled"), True ), ( "success disabled", response.Response("control"), False ), ( "error splitio", response.Response(status=500, message="Splitio error message"), False ), ], ) def test__is_enabled( mocker, test_description, get_single_feature_by_attributes_result, expected_result, ): """Test _is_enabled.""" mocker.patch.object( pythonfeatures, "get_single_feature_by_attributes", return_value=get_single_feature_by_attributes_result, ) feature_name = "some_feature" feature_attributes = {"some_key": test_description} feature_attributes_param = json.dumps(feature_attributes) result = features.verify_feature_eligibility(feature_name, feature_attributes_param) assert pythonfeatures.get_single_feature_by_attributes.mock_calls == [ call(feature_name, feature_attributes) ] assert result == expected_result @pytest.mark.parametrize("enabled", [True, False]) def test_is_enabled_store_blocked_artist_validation(mock_app, mocker, enabled): """It checks the content_store_blocked_artist_validation flag by identity.""" mock_app.g.request_context.identity_id = "identity-123" verify = mocker.patch.object( features, "verify_feature_eligibility", return_value=enabled) result = features.is_enabled_store_blocked_artist_validation() assert result is enabled verify.assert_called_once_with( "content_store_blocked_artist_validation", json.dumps({"identity_id": "identity-123"}), )