"""Functional test for updating release status.""" import json from oto import response import pytest from ows_product_physical.constant import service_name from ows_product_physical.logic import carveins @pytest.fixture def status_test_setup(ows_request_mocker, setup_ows_request, mocker): """Mock calls to other microservices for product lookup.""" setup_ows_request({'display_upc': 'control'}) ows_request_mocker.add({ 'method': 'get', 'service': service_name.OWS_ASSETS, 'path': '/image/product/large_cover/{}/location'.format(42), 'status': 200, 'text': 'https://image.com/image.jpg' }) mocker.patch.object( carveins, 'get_carveins_for_upc', return_value=response.Response(message=[20]) ) ows_request_mocker.apply() def test_update_release_status_successful( client, status_test_setup, db_with_data, db_release_id, valid_put_header): """Test successful update of product release status.""" response = client.put( '/product/{}/status'.format(db_release_id), headers=valid_put_header, data=json.dumps({'status': 'transfer_to_content'})) assert response.status_code == 201 def test_update_release_status_validation_failure( client, status_test_setup, db_with_data, db_release_id, valid_put_header): """Test unsuccessful update of product release status.""" response = client.put( '/product/{}/status'.format(db_release_id), headers=valid_put_header, data=json.dumps({'status': 'bogus_status'})) assert response.status_code == 400