"""Test highlight copy.""" import json import pytest from marketing.constants import service_name from marketing.constants import marketing from tests.fixtures.models.highlight import HighlightFactory from tests.utils import db_operations @pytest.fixture(scope='module') def test_highlights(): """Populate the test database with a sample highlight.""" test_highlights = HighlightFactory.build( entity='release', entity_id=12345678, mkt_program_id=marketing.PROGRAM_MARKETING_HIGHLIGHTS) db_operations.seed_models(test_highlights) return test_highlights @pytest.mark.parametrize( ('existing_product_id', 'vendor_id', 'subaccount_id', 'context_type', 'expected_status', 'existing_product_status', 'new_product_status'), # success [(12345678, 111, 222, 'physical', 201, 200, 200), # failure: vendor id mismatch (12345678, 333, 222, 'physical', 403, 200, 200), # failure: subaccount id mismatch (12345678, 111, 333, 'physical', 403, 200, 200), # failure: context_type not physical (12345678, 111, 222, 'digital', 400, 200, 200), # failure: existing product not found (12345678, 111, 222, 'physical', 404, 404, 200), # failure: new product not found (12345678, 111, 222, 'physical', 404, 200, 404), # failure: test for non-existent highlight (99999999, 111, 222, 'physical', 200, 200, 200)]) def test_copy_product_highlights_scenarios( client, ows_request_mocker, vendor_id, subaccount_id, expected_status, context_type, existing_product_status, new_product_status, test_highlights, existing_product_id): """Test copy product highlights senarios.""" new_product_id = 2123212 ows_request_mocker.mock_response( service_name.OWS_PRODUCT, '/product/{}'.format(existing_product_id), json={ 'vendor_id': vendor_id, 'subaccount_id': subaccount_id, 'context_type': context_type }, status=existing_product_status ) ows_request_mocker.mock_response( service_name.OWS_PRODUCT, '/product/{}'.format(new_product_id), json={ 'vendor_id': 111, 'subaccount_id': 222, 'context_type': 'physical' }, status=new_product_status ) copy_highlight_response = client.post( '/highlights/product/{}/copy/{}'.format( existing_product_id, new_product_id)) assert copy_highlight_response.status_code == expected_status def test_copy_product_highlights_success( client, ows_request_mocker, test_highlights): """Test copy product highlights success.""" vendor_id = 1118 subaccount_id = 2228 existing_product_id = 12345678 new_product_id = 21232128 ows_request_mocker.mock_response( service_name.OWS_PRODUCT, '/product/{}'.format(existing_product_id), json={ 'vendor_id': vendor_id, 'subaccount_id': subaccount_id, 'context_type': 'physical' }, status=200 ) ows_request_mocker.mock_response( service_name.OWS_PRODUCT, '/product/{}'.format(new_product_id), json={ 'vendor_id': vendor_id, 'subaccount_id': subaccount_id, 'context_type': 'physical' }, status=200 ) copy_highlight_response = client.post( '/highlights/product/{}/copy/{}'.format( existing_product_id, new_product_id)) assert copy_highlight_response.status_code == 201 get_highlight_response = client.get( '/highlights/{}/{}?mkt_program_id={}'.format( 'release', new_product_id, marketing.PROGRAM_MARKETING_HIGHLIGHTS)) assert len( json.loads(get_highlight_response.data.decode('utf8'))['items']) > 0 highlight_data = json.loads( get_highlight_response.data.decode('utf8'))['items'][0] assert highlight_data.get('entity_id') == new_product_id assert highlight_data.get('description') == test_highlights.description