"""Test highlight copy logic.""" from oto import response import pytest from marketing.logic import highlights from marketing.models import ows_product def get_highlights_response(description='Foo'): """Return highlight as a dict.""" return {'items': [{'highlight_id': 1, 'description': description}]} @pytest.mark.parametrize( ('highlights_response', 'highlights_status', 'vendor_id', 'subaccount_id', 'context_type', 'copy_status', 'existing_product_status', 'new_product_status'), # success [(get_highlights_response(), 200, 111, 222, 'physical', 201, 200, 200), # failure: vendor id mismatch (get_highlights_response(), 200, 333, 222, 'physical', 403, 200, 200), # failure: subaccount id mismatch (get_highlights_response(), 200, 111, 333, 'physical', 403, 200, 200), # failure: context_type not physical (get_highlights_response(), 200, 111, 222, 'digital', 400, 200, 200), # failure: existing product not found (get_highlights_response(), 200, 111, 222, 'physical', 404, 404, 200), # failure: new product not found (get_highlights_response(), 200, 111, 222, 'physical', 404, 200, 404), # success: test for non-existent highlight (None, 404, 111, 222, 'physical', 200, 200, 200), # success: test for highlight with empty description (get_highlights_response( description=''), 200, 111, 222, 'physical', 200, 200, 200)]) def test_copy_product_highlights_logic( mocker, vendor_id, subaccount_id, copy_status, context_type, existing_product_status, new_product_status, highlights_response, highlights_status): """Test copy product highlights senarios.""" existing_product_id = 12345678 new_product_id = 2123212 def mocked_get_product(product_id): if product_id == new_product_id: return response.Response( message={ 'vendor_id': 111, 'subaccount_id': 222, 'context_type': 'physical'}, status=new_product_status) if product_id == existing_product_id: return response.Response( message={ 'vendor_id': vendor_id, 'subaccount_id': subaccount_id, 'context_type': context_type}, status=existing_product_status) return response.Response(status=404) mocker.patch.object(ows_product, 'get_product', mocked_get_product) mocker.patch.object( highlights, 'get_highlights', return_value=response.Response( message=highlights_response, status=highlights_status)) mocker.patch.object( highlights, 'create_highlight', return_value=response.Response()) copy_highlight_response = highlights.copy_product_highlights( existing_product_id, new_product_id) assert copy_highlight_response.status == copy_status