"""Tests for copy product logic.""" from oto import response import pytest from ows_product_physical.logic import product_physical as pp_logic from ows_product_physical.models import persister @pytest.mark.parametrize('copy_data', [ ( { 'product_code': 'productcode001', 'distribution_format_id': 74, 'units_per_set': 3, 'display_configuration': '2 x CD + Viking Ship', 'box_lot': 3, 'initial_stock': 2 } ), ( { 'product_code': 'productcode001', 'distribution_format_id': 74, 'units_per_set': 3, 'display_configuration': '2 x CD + Viking Ship', 'box_lot': 3, 'initial_stock': 2, 'wholesale_price': 12.99, 'packaging_id': 1 } ) ]) def test_logic_copy_product_success(copy_data, mocker): """Test copy product success.""" existing_product_id = 12321 expected_response = {'product_id': 456789} existing_product = { 'will_be_copied': 'existing field that will be copied', 'product_id': "won't be copied", 'upc': "won't be copied", 'display_upc': "won't be copied", 'manufacturer_upc': "won't be copied", 'release_status': 'will be reset to label_processing', 'discount': "won't be copied", 'pricing': "won't be copied", } expected_new_product_fields = { 'will_be_copied': 'existing field that will be copied', 'release_status': 'label_processing' } expected_new_product_fields.update(copy_data) mocker.patch.object( persister, 'get_product_by_id', return_value=response.Response(message=existing_product)) mocker.patch.object( pp_logic, 'create_product', return_value=response.Response(message={'product_id': 456789})) result = pp_logic.copy_product(existing_product_id, copy_data) persister.get_product_by_id.assert_called_once_with(existing_product_id) pp_logic.create_product.assert_called_once_with( expected_new_product_fields) assert result.status == 200 assert result.message == expected_response def test_logic_copy_product_product_not_found(mocker): """Test copy product when product is not found.""" mocker.patch.object( persister, 'get_product_by_id', return_value=response.Response(status=404)) result = pp_logic.copy_product(12321, {}) assert result.status == 404