"""Tests for pricing logic.""" import sentry_sdk from product.constants import service_name from product.models import ows_pricing as op_models def test_model_copy_product_pricing_success(ows_request_mocker): """Test copy product pricing success.""" existing_product_id = 93 new_product_id = 98765 ows_request_mocker.add({ 'method': 'post', 'service': service_name.OWS_PRICING, 'path': '/product/{}/pricing/copy/{}'.format( existing_product_id, new_product_id), 'status': 200 }) ows_request_mocker.apply() result = op_models.copy_product_pricing( existing_product_id, new_product_id) assert result.status == 200 def test_model_copy_product_pricing_exception(mocker): """Test copy product pricing when an exception occurs.""" existing_product_id = 93 new_product_id = 98765 mocker.patch.object(sentry_sdk, 'capture_exception') result = op_models.copy_product_pricing( existing_product_id, new_product_id) assert result.status == 500 assert sentry_sdk.capture_exception.called def test_model_copy_product_pricing_op_down(ows_request_mocker): """Test copy product when ows-pricing returns an error.""" existing_product_id = 93 new_product_id = 98765 expected_status = 500 ows_request_mocker.add({ 'method': 'post', 'service': service_name.OWS_PRICING, 'path': '/product/{}/pricing/copy/{}'.format( existing_product_id, new_product_id), 'status': 500 }) ows_request_mocker.apply() result = op_models.copy_product_pricing( existing_product_id, new_product_id) assert result.status == expected_status