"""Test for the ows_prodcut module.""" import json from flexmock import flexmock from owsrequest import request import pytest import requests from salessheets import config from salessheets.constants import ows_services from salessheets.models import ows_product @pytest.mark.no_owsrequest_patch @pytest.mark.parametrize('account_type, account_id, product_id, resp_status', [ ('vendor', '1', '123', 200), ('subaccount', '2', '512', 404), ('vendor', '3', '25123', 403) ]) def test_get_product_ownership_by_account( account_type, account_id, product_id, resp_status): """Test if get_product_ownership_by_account returns successful result.""" test_content = flexmock( decode=lambda *args: {} ) response = flexmock(requests.models.Response()) response.status_code = resp_status (flexmock(response) .should_receive('content') .and_return(test_content)) flexmock(json).should_receive('loads').and_return(test_content) 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) .and_return(response)) result = ows_product.get_product_ownership_by_account( account_type, account_id, product_id) assert result.status == resp_status