"""Test PATCH /order endpoint.""" from unittest.mock import patch from owsrequest.constants import headers import pytest from ows_product_physical.logic import orders @pytest.mark.parametrize('url,json', [ ['/orders', { 'items': [{ 'order_id': 123, 'status': 'cancelled' }] }], ['/orders', { 'items': [{ 'order_id': 123, 'output_file': 'cancelled.xml' }] }], ['/orders', { 'items': [{ 'order_id': 123, 'status': 'cancelled', 'output_file': 'cancelled.xml' }] }], ['/orders', { 'items': [{ 'order_id': 123, 'status': 'cancelled', 'output_file': 'cancelled.xml' }, { 'order_id': 456, 'output_file': 'cancelled.xml' }] }] ]) def test_patch_order_valid_payload( url, json, fixture_response_ok, client, distribution_profile_header ): """Test that valid payloads will be processed, call logic layer.""" with patch.object( orders, 'update_orders', return_value=fixture_response_ok ) as mock_logic: result = client.patch( url, headers=distribution_profile_header, json=json ) assert result.status_code == 200 identity_id = distribution_profile_header[headers.ORCHARD_IDENTITY_ID] mock_logic.assert_called_once_with( identity_id=identity_id, orders=json['items'] ) @pytest.mark.parametrize('url,json', [ ['/orders', {'missing': 'items'}] ]) def test_patch_order_invalid_payload( url, json, fixture_response_ok, client, distribution_profile_header ): """Test that valid payloads will not be processed, not call logic layer.""" with patch.object( orders, 'update_orders', return_value=fixture_response_ok ) as mock_logic: result = client.patch( url, headers=distribution_profile_header, json=json ) assert result.status_code == 400 mock_logic.assert_not_called()