"""Test for the ows_product module.""" from flexmock import flexmock from owsrequest import request import pytest import requests from sales_goals import config from sales_goals.constants import ows_services from sales_goals.models import ows_product @pytest.mark.parametrize( 'account_type, account_id, product_id, resp_status, error_msg', [ ('vendor', '1', '123', 200, None), ('subaccount', '2', '512', 404, 'Product 512 doesn\'t exist'), ('vendor', '3', '25123', 403, 'Product 25123 isn\'t owned by 3'), ('subaccount', '2', '512', 500, 'Something went wrong'), ]) def test_get_product_ownership_by_account( account_type, account_id, product_id, resp_status, error_msg): """Test if get_product_ownership_by_account returns successful result.""" response = flexmock(requests.models.Response()) response.status_code = resp_status (flexmock(response) .should_receive('text') .and_return(error_msg)) endpoint = '/{account_type}/{account_id}/product/{product_id}'.format( account_type=account_type, account_id=account_id, product_id=product_id) (flexmock(request) .should_receive('process') .with_args( ows_services.APPLICATION_NAME, config.ENVIRONMENT, ows_services.SERVICE_CALL_METHOD_HEAD, ows_services.OWS_PRODUCT_SERVICE_NAME, endpoint, None, 'https') .and_return(response)) result = ows_product.get_product_ownership_by_account( account_type, account_id, product_id) assert result.status == resp_status if not result: assert result.errors['message'] == error_msg