"""Functional tests for product history change creation.""" import json from oto.response import Response from ows_product_physical.constant import field from ows_product_physical.constant import header from ows_product_physical.logic import product_physical_change_history def test_handler_post_product_change_history( mocker, client, valid_post_header, valid_post_physical_product_change_history_fields_artwork, feature_engine): """Test POST product handler post body validation fail state.""" return_val = 'foo' product_id = 12345 post_data = json.dumps( valid_post_physical_product_change_history_fields_artwork) mocker.patch.object( product_physical_change_history, 'create', return_value=Response(return_val)) result = client.post( '/product/{}/change_history'.format(product_id), headers=valid_post_header, data=post_data) product_physical_change_history.create.assert_called_once_with( product_id, valid_post_header[header.GRASS_ACCOUNT_TYPE], valid_post_header[header.GRASS_ACCOUNT_ID], upc=valid_post_physical_product_change_history_fields_artwork[field.UPC], # noqa field_name=valid_post_physical_product_change_history_fields_artwork[field.FIELD_NAME] # noqa ) assert result.status_code == 200 assert result.data.decode() == return_val