"""Tests for marketing model.""" from collections import namedtuple from owsrequest import request as requests import sentry_sdk from product.constants import service_name from product.models import ows_marketing import product.models.ows_marketing def test_delete_marketing_highlights_success(mocker, test_product): """Test success deletion.""" response = namedtuple('response', 'status_code') mocker.patch.object( requests, 'delete', return_value=response(status_code=200), autospec=True) assert product.models.ows_marketing. \ delete_marketing_highlights_by_release(test_product) def test_delete_marketing_highlights_fail_exception( monkeypatch, mocker, test_product): """Test exception handler.""" monkeypatch.delattr(requests, 'delete') mocker.patch.object( sentry_sdk, 'capture_exception', return_value='', autospec=True) result = product.models.ows_marketing. \ delete_marketing_highlights_by_release(test_product) assert not result assert sentry_sdk.capture_exception.called def test_delete_marketing_highlights_error_response(mocker, test_product): """Test success deletion.""" response = namedtuple('response', 'status_code') mocker.patch.object( requests, 'delete', return_value=response(status_code=500), autospec=True) assert not product.models.ows_marketing. \ delete_marketing_highlights_by_release(test_product) def test_model_copy_product_highlights_success(ows_request_mocker): """Test copy product highlights success.""" existing_product_id = 93 new_product_id = 98765 ows_request_mocker.add({ 'method': 'post', 'service': service_name.OWS_MARKETING, 'path': '/highlights/product/{}/copy/{}'.format( existing_product_id, new_product_id), 'status': 200 }) ows_request_mocker.apply() result = ows_marketing.copy_product_highlights( existing_product_id, new_product_id) assert result.status == 200 def test_model_copy_product_highlights_exception(mocker): """Test copy product highlights when an exception occurs.""" existing_product_id = 93 new_product_id = 98765 mocker.patch.object(sentry_sdk, 'capture_exception') result = ows_marketing.copy_product_highlights( existing_product_id, new_product_id) assert result.status == 500 def test_model_copy_product_highlights_om_down(ows_request_mocker): """Test copy product when ows-marketing returns an error.""" existing_product_id = 93 new_product_id = 98765 expected_status = 500 ows_request_mocker.add({ 'method': 'post', 'service': service_name.OWS_MARKETING, 'path': '/highlights/product/{}/copy/{}'.format( existing_product_id, new_product_id), 'status': 500 }) ows_request_mocker.apply() result = ows_marketing.copy_product_highlights( existing_product_id, new_product_id) assert result.status == expected_status