"""Test for ows-product.""" from owsrequest import request from owsrequest import test_utils from product_workflow.constants import error from product_workflow.constants import services from product_workflow.models import ows_product def test_get_product_details_by_id(monkeypatch): """Test for get_product_by_id.""" mock_json_response = 'ok' product_id = 2011621 path = '/product/2011621' call_specs = [{ 'service': services.OWS_PRODUCT, 'path': path, 'status': 200, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_product.get_product_by_id(product_id) assert response.message == mock_json_response def test_get_product_details_with_invalid_product_id(monkeypatch): """Test for get_product_by_id with invalid product id.""" mock_json_response = error.ERROR_RELEASE_NOT_FOUND product_id = 123 path = '/product/123' call_specs = [{ 'service': services.OWS_PRODUCT, 'path': path, 'status': 404, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_product.get_product_by_id(product_id) assert response.errors.get('message') == mock_json_response def test_get_product_details_by_id_with_error(monkeypatch): """Test for get_product_by_id with error.""" mock_json_response = {} product_id = 2011621 path = '/product/2011621' call_specs = [{ 'service': services.OWS_PRODUCT, 'path': path, 'status': 500, 'json': mock_json_response}] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(call_specs)) response = ows_product.get_product_by_id(product_id) assert response.status == 500 def test_get_product_details_by_id_with_exception(monkeypatch): """Test for get_product_by_id with exception.""" mock_json_response = {} product_id = 2011621 path = '/product/2011621' call_specs = [{ 'service': services.OWS_PRODUCT, 'path': path, 'status': 500, 'json': mock_json_response}] monkeypatch.setattr( request, 'head', test_utils.mock_ows_requests(call_specs)) response = ows_product.get_product_by_id(product_id) assert response.errors.get('message')