"""Tests for copy product handler.""" import json from oto import response import pytest from ows_product_physical.logic import product_physical as pp_logic @pytest.mark.parametrize('copy_data', [ ({'product_code': 'productcode001', 'distribution_format_id': 74, 'box_lot': 1, 'initial_stock': 1, 'packaging_id': 1, 'units_per_set': 3, 'display_configuration': '2 x CD + Viking Ship'}), ({'product_code': 'productcode001', 'distribution_format_id': 74, 'box_lot': 1, 'initial_stock': 1, 'packaging_id': 1, 'units_per_set': 3, 'display_configuration': '2 x CD + Viking Ship', 'wholesale_price': 12.99}) ]) def test_handler_copy_product_success( copy_data, client, mocker, valid_copy_header, feature_engine): """Test copy product success.""" existing_product_id = 12321 expected_response = {'product_id': 98765} mocker.patch.object( pp_logic, 'copy_product', return_value=response.Response(message=expected_response)) result = client.post( '/product/{}/copy'.format(existing_product_id), headers=valid_copy_header, data=json.dumps(copy_data)) pp_logic.copy_product.assert_called_once_with( existing_product_id, copy_data) assert result.status_code == 200 assert json.loads(result.data.decode('utf8')) == expected_response def test_handler_copy_product_grass_request_blocking( client, valid_copy_header, feature_engine): """Test copy product grass request blocking.""" result = client.post( '/product/12321/copy', headers=valid_copy_header) assert result.status_code == 400 def test_handler_copy_product_header_error(client, valid_copy_header, feature_engine): """Test copy product header error.""" copy_data = { 'product_code': 'productcode001', 'distribution_format_id': 74, 'units_per_set': 3, 'display_configuration': '2 x CD + Viking Ship'} invalid_copy_header = valid_copy_header del invalid_copy_header['Content-Type'] result = client.post( '/product/12321/copy', headers=invalid_copy_header, data=json.dumps(copy_data)) assert result.status_code == 400 def test_handler_copy_product_body_error(client, valid_copy_header, feature_engine): """Test copy product body error.""" result = client.post( '/product/12321/copy', headers=valid_copy_header, data=json.dumps( {'distribution_format_id': 74, 'units_per_set': 3})) assert result.status_code == 400