"""Features tests.""" from flexmock import flexmock from owsrequest import request as requests from label_copy_export import config from label_copy_export import features from label_copy_export.constants import ows_services def test_get_user_features_success(): """Test retrieving all the user's features for successful result.""" test_user_id = 'alw:25824' expected_result = {'feature_1': 'enabled'} mock_response = flexmock( status_code=200, json=lambda: {'feature_1': 'enabled'}) (flexmock(requests) .should_receive('process') .with_args( 'daemon-label-copy-export', config.ENVIRONMENT, 'GET', ows_services.OWS_FEATURES, '/features/user/{user_id}'.format(user_id=test_user_id)) .and_return(mock_response)) result = features.get_user_features(test_user_id) assert result.message == expected_result def test_get_user_features_ows_features_returned_error(): """Test retrieving all the user's features errors handling.""" test_user_id = 'alw:25824' error_msg = 'Something went wrong' mock_response = flexmock( status_code=400, content=error_msg) (flexmock(requests) .should_receive('process') .with_args( 'daemon-label-copy-export', config.ENVIRONMENT, 'GET', ows_services.OWS_FEATURES, '/features/user/{user_id}'.format(user_id=test_user_id)) .and_return(mock_response)) result = features.get_user_features(test_user_id) assert result.errors['message'] == error_msg