"""Tests for ows-product Model.""" from unittest.mock import patch from owsrequest import request from owsrequest import test_utils import pytest from blacklist_manager.constants import service_name from blacklist_manager.models import ows_product @pytest.mark.parametrize( ('expected_status'), [ (200), (403) ]) def test_check_product_ownership(monkeypatch, expected_status): """Test getting a product.""" account_type = 'vendor' account_id = 123 product_id = 456 path = '/vendor/123/product/456' # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': service_name.OWS_PRODUCT, 'path': path, 'status': expected_status}] monkeypatch.setattr( request, 'head', test_utils.mock_ows_requests(call_specs)) response = ows_product.check_product_ownership( product_id, account_type, account_id) assert response.status == expected_status @patch('blacklist_manager.models.ows_product.capture_exception') def test_check_product_ownership_exception(mock_sentry): """Test exception raise for connection error.""" product_id = 123 account_type = 'vendor' account_id = '7123' response = ows_product.check_product_ownership( product_id, account_type, account_id) assert response.status == 500 assert response.errors.get('message') == 'connection error' assert mock_sentry.called