"""Unit tests for MetaUpdateQueue logic.""" from oto import response from product_workflow.constants import success from product_workflow.logic import meta_update_queue as meta_update_queue_logic from product_workflow.models import meta_update_queue from product_workflow.models import ows_account as ows_account_model from product_workflow.models import ows_product as ows_product_model def test_create_meta_update_queue(mocker): """Test that calls the model layer and returns its response.""" product_id = 2958087 upc = 123 data = { 'description': 'Scheduled update', 'delivery_store_ids': [12] } expected_result = response.Response( message=success.CREATE_META_UPDATE_SUCCESS, status=201) mocker.patch.object( meta_update_queue, 'create_meta_update_queue', return_value=expected_result ) ows_product_response = response.Response( message={'vendor_id': 123, 'upc': upc}) mocker.patch.object( ows_product_model, 'get_product_by_id', return_value=ows_product_response ) mocker.patch.object( ows_account_model, 'get_vendor', return_value='signed' ) result = meta_update_queue_logic.create_meta_update_queue(product_id, data) meta_update_queue.create_meta_update_queue.assert_called_with(upc, data) assert result.message == expected_result.message assert result.status == 201 def test_create_meta_update_queue_with_description(mocker): """Test that calls the model layer and returns its response.""" product_id = 2958087 upc = 123 data = { 'description': 'Scheduled update', 'delivery_store_ids': [12] } expected_result = response.Response( message=success.CREATE_META_UPDATE_SUCCESS, status=201) mocker.patch.object( meta_update_queue, 'create_meta_update_queue', return_value=expected_result ) ows_product_response = response.Response( message={'vendor_id': 123, 'upc': upc}) mocker.patch.object( ows_product_model, 'get_product_by_id', return_value=ows_product_response ) mocker.patch.object( ows_account_model, 'get_vendor', return_value='signed' ) result = meta_update_queue_logic.create_meta_update_queue( product_id, data) meta_update_queue.create_meta_update_queue.assert_called_with(upc, data) assert result.message == expected_result.message assert result.status == 201