"""Tests for physical product logic.""" from unittest.mock import MagicMock from ows_product_physical.logic import product_physical from ows_product_physical.models import persister from ows_product_physical.models import product_physical_supply_chain_info def test_update_product_supply_chain_info_success( monkeypatch, product_physical_supply_chain_record, product_physical_supply_chain_update_record): """Assert Supply Chain info is set for product.""" product_id = 123 monkeypatch.setattr( persister, 'get_product_by_id', value=MagicMock( return_value=1)) monkeypatch.setattr( product_physical_supply_chain_info, 'update_product_supply_chain_info_by_product_store_id', value=MagicMock( return_value=product_physical_supply_chain_record)) result = product_physical.update_product_supply_chain_info( product_physical_supply_chain_update_record, product_id) assert result.message['product_id'] == product_id def test_update_product_supply_chain_info_failure( monkeypatch, product_physical_supply_chain_update_record, not_found_status): """Assert Supply Chain info is set for product.""" product_id = 'xxxxxx' monkeypatch.setattr( persister, 'get_product_by_id', value=MagicMock( return_value=1)) monkeypatch.setattr( product_physical_supply_chain_info, 'update_product_supply_chain_info_by_product_store_id', value=MagicMock( return_value=not_found_status)) result = product_physical.update_product_supply_chain_info( product_physical_supply_chain_update_record, product_id) assert result.status == 404