"""Test OWS accounting functions.""" from unittest.mock import Mock from owsrequest import test_utils from pytest import raises from flows.sales_data import ows_accounting from flows.sales_data.exceptions import OWSError def test_get_accounting_period_success(monkeypatch): """Test get_accounting_period.""" accounting_period_id = '123' mock_json_response = {'accounting_period': accounting_period_id} call_specs = [{ 'service': ows_accounting.ACCOUNTING_SERVICE, 'path': ows_accounting.ACCOUNTING_PERIOD_ENDPOINT, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( ows_accounting.request, 'process', test_utils.mock_ows_requests(call_specs)) result = ows_accounting.get_accounting_period() assert result == accounting_period_id def test_get_accounting_period_error(monkeypatch): """Test get_accounting_period with error.""" ows_response_mock = Mock() ows_response_mock().status_code = 500 monkeypatch.setattr( ows_accounting.request, 'process', ows_response_mock) with raises(OWSError): ows_accounting.get_accounting_period()