"""Test OWS contracts functions.""" from unittest.mock import Mock from owsrequest import test_utils from pytest import raises from api.exceptions import OWSError from api.utils import ows_contracts def test_get_advances_success(monkeypatch): """Test get_advances.""" vendor_id = 123 mock_json_response = {'foo': 'bar'} # The call spec list used by mock_ows_requests to mock these requests call_specs = [{ 'service': ows_contracts.CONTRACTS_SERVICE, 'path': ows_contracts.CONTRACTS_ADVANCES_ENDPOINT.format( vendor_id=vendor_id), 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( ows_contracts.request, 'process', test_utils.mock_ows_requests(call_specs), raising=False) result = ows_contracts.get_advances(vendor_id) assert result == mock_json_response def test_get_advances_error(monkeypatch): """Test get_advances with error.""" vendor_id = 123 ows_response_mock = Mock() monkeypatch.setattr( ows_contracts.request, 'process', ows_response_mock, raising=False) with raises(OWSError): ows_contracts.get_advances(vendor_id) assert ows_response_mock.json.called