"""Tests for assets model.""" from owsrequest import request as requests import sentry_sdk from product.constants import service_name from product.models import ows_assets orchard_user_id = 'alw:12345' existing_product_id = 93 new_product_id = 98765 def test_model_copy_artwork_success(request_engine, context): """Test copy assets success.""" request_engine[service_name.OWS_ASSETS].add_spec( 'POST', '/image/{}/copy/{}'.format( existing_product_id, new_product_id)) with context: result = ows_assets.copy_product_artwork( existing_product_id, new_product_id, orchard_user_id) assert result.status == 200 def test_model_copy_artwork_exception(mocker): """Test copy assets when an exception occurs.""" mocker.patch.object(requests, 'post', side_effect=Exception('oops')) mocker.patch.object(sentry_sdk, 'capture_exception') result = ows_assets.copy_product_artwork( existing_product_id, new_product_id, orchard_user_id) assert result.status == 500 assert sentry_sdk.capture_exception.called def test_model_copy_product_artwork_error_return(request_engine, context): """Test copy assets when ows-assets returns an error.""" request_engine[service_name.OWS_ASSETS].add_spec( 'POST', '/image/{}/copy/{}'.format( existing_product_id, new_product_id), status=404) with context: result = ows_assets.copy_product_artwork( existing_product_id, new_product_id, orchard_user_id) assert result.status == 404