"""Functional tests for updating project and product artist_id by PUT call.""" import json from oto import response from owsrequest import request from owsrequest import test_utils from pythonfeatures import pythonfeatures from project_manager.models import ows_product from project_manager.models import persister new_artist_id = 456 update_request_artist_id = {'artist_id': new_artist_id} def test_put_project_artist_success( db_fixture, project_highlight_ok, monkeypatch, project, client, header_user, get_artist_info_ok, project_id, mocker, get_company_brand_ows_response): """Assert valid response from PUT /project when updating artist_id. It checks to see updated json is returned when updating a project artist for a project that has products. """ get_specs = [ project_highlight_ok, get_artist_info_ok, get_company_brand_ows_response, { 'service': 'ows-account', 'path': '/subaccount/1', 'status': 200, 'json': {'vendor_id': 7123} }, { 'service': 'ows-features', 'path': '/features/user/alw:123', 'status': 200, 'json': { 'content_get_rejections_for_workstation': 'control' } } ] put_specs = [ { 'service': 'ows-product-digital', 'path': '/product/audio/{}'.format(123), 'status': 200, 'json': {} } ] products = [ { 'product_id': 123, 'context_type': 'digital' } ] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(get_specs)) monkeypatch.setattr( request, 'put', test_utils.mock_ows_requests(put_specs)) get_products = mocker.patch.object( persister, 'get_products_for_project', return_value=response.Response(status=200, message=products)) mocker.patch.object( ows_product, '_update_products_func', return_value=response.Response(status=200, message=products)) mocker.patch.object( pythonfeatures, 'get_single_feature', return_value=response.Response(message='disabled')) res = client.put( '/project/{}'.format(project_id), data=json.dumps(update_request_artist_id), headers=header_user) get_products.assert_called_once_with(project_id, 7123) assert res.status_code == 200 response_body = json.loads(res.data.decode()) assert response_body['artist_id'] == new_artist_id def test_put_project_artist_failure( db_fixture, project_highlight_ok, monkeypatch, project, client, header_user, get_artist_info_ok, project_id, mocker, get_company_brand_ows_response): """Assert valid response from PUT /project when updating artist_id. It checks to see updated json is returned when updating a project artist for a project that has products. """ get_specs = [ project_highlight_ok, get_artist_info_ok, get_company_brand_ows_response, { 'service': 'ows-account', 'path': '/subaccount/1', 'status': 200, 'json': {'vendor_id': 7123} } ] put_specs = [ { 'service': 'ows-product-digital', 'path': '/product/audio/{}'.format(123), 'status': 400, 'json': {} }, ] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(get_specs)) monkeypatch.setattr( request, 'put', test_utils.mock_ows_requests(put_specs)) get_products = mocker.patch.object( persister, 'get_products_for_project', return_value=response.Response(status=200, message=[{ 'product_id': 123, 'context_type': 'digital'}])) res = client.put( '/project/{}'.format(project_id), data=json.dumps(update_request_artist_id), headers=header_user) get_products.assert_called_once_with(project_id, 7123) assert res.status_code == 400