"""Tests for handlers.""" import json from oto import response from ows_product_physical.constant import header from ows_product_physical.logic import product_physical def test_post_set_supply_chain_info_by_product_id_success( client, valid_put_header, product_physical_supply_chain_record_for_insert, mocker): """Test `/product/{productId}/supply-chain-info` success.""" mocker.patch.object( product_physical, 'set_supply_chain_info_by_product_id', return_value=response.Response({}), autospec=True) result = client.post( '/product/123/supply-chain-info', headers=valid_put_header, data=json.dumps( product_physical_supply_chain_record_for_insert)) assert result.status_code == 200 assert product_physical.set_supply_chain_info_by_product_id.called def test_post_set_supply_chain_info_by_product_id_error( client, valid_get_header, product_physical_supply_chain_record_for_insert): """Test `/product/{productId}/supply-chain-info` fails. Should fail on invalid headers. """ invalid_header = valid_get_header invalid_header[header.GRASS_ACCOUNT_TYPE] = 'abc' data = { 'supplychain_info': product_physical_supply_chain_record_for_insert } result = client.post( '/product/123/supply-chain-info', headers=invalid_header, json=data) assert result.status_code == 403