"""Get products for project functional test.""" import json from oto import response from owsrequest import request from owsrequest import test_utils from pythonfeatures import pythonfeatures from project_manager.constant import error_const from project_manager.constant import marketing_const from tests.common_assert import assert_header def test_get_products_no_project_func( client, header, db_fixture, monkeypatch, get_vendor_ows_response, get_company_brand_ows_response): """Assert valid response from GET /project/{product_id}/products. Asserts that the route returns a 404 with the appropriate JSON. It tests for correlation-id and content-type in the response header. """ monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests([ get_vendor_ows_response, get_company_brand_ows_response])) server_response = client.get('/project/0/products', headers=header) response_json = json.loads(server_response.data.decode()) expected_json = { 'code': error_const.ERROR_CODE_NOT_FOUND, 'message': 'Unable to find project_id 0'} assert server_response.status_code == 404 assert response_json == expected_json assert_header(header, server_response.headers) def test_get_products_by_project( project_highlight_ok, monkeypatch, mocker, db_fixture, projects, client, header, get_artist_info_ok, get_contentreview_data_ok, get_vendor_ows_response, get_company_brand_ows_response): """Assert that a list of products for a project is returned. Asserts that the route returns a 200 with the appropriate JSON. It tests for correlation-id and content-type in the response header. """ monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests([ project_highlight_ok, get_artist_info_ok, get_contentreview_data_ok, get_vendor_ows_response, get_company_brand_ows_response ])) mocker.patch.object( pythonfeatures, 'get_single_feature', return_value=response.Response(message='disabled')) expected = { 'items': [{ 'artist_names': ['Mike Jones'], 'product_type': 'Music', 'product_type_id': 1, 'product_id': 1001, 'release_name': 'Something Strange Here', 'release_status': 'error_correction', 'is_error_correction_and_action_required': False, 'display_upc': '888831283041', 'upc': 888831283041, 'version': 'Deluxe', 'delivered_version': 'Live at Wembley', 'distribution_format': { 'id': 1, 'name': 'Digital', 'context': 'digital'}, 'format': 'Single', 'not_for_distribution': 'N', 'release_approval_status': None}, { 'artist_names': ['Mike Jones'], 'product_type': 'Music', 'product_type_id': 1, 'product_id': 1002, 'release_name': 'Something Strange Here', 'release_status': 'action_required', 'is_error_correction_and_action_required': False, 'display_upc': '889845667810', 'upc': 889845667810, 'version': 'Unremarkable', 'delivered_version': 'Live in New York', 'distribution_format': { 'id': 2, 'name': 'CD', 'context': 'physical'}, 'format': 'EP', 'not_for_distribution': 'N', 'release_approval_status': 'rejected'}, { 'artist_names': ['Mike Jones'], 'product_type': 'Music', 'product_type_id': 1, 'product_id': 1003, 'release_name': 'Something Strange Here', 'release_status': 'transfer_to_content', 'is_error_correction_and_action_required': False, 'display_upc': '889845667872', 'upc': 889845667872, 'version': 'Target Special Edition', 'delivered_version': 'Live in Berlin', 'distribution_format': { 'id': 1, 'name': 'Digital', 'context': 'digital'}, 'format': 'Full Length', 'not_for_distribution': 'N', 'release_approval_status': 'checked_in'}, { 'artist_names': ['John Mike'], 'product_type': 'Music', 'product_type_id': 1, 'product_id': 1014, 'release_name': 'Herp Derp', 'release_status': 'action_required', 'is_error_correction_and_action_required': True, 'display_upc': '803680422555', 'upc': 803680422555, 'version': 'Le 4th status', 'delivered_version': 'Remixed by Rem', 'distribution_format': { 'id': 1, 'name': 'Digital', 'context': 'digital'}, 'format': 'Single', 'not_for_distribution': 'N', 'release_approval_status': 'rejected'}]} server_response = client.get('/project/1/products', headers=header) assert server_response.status_code == 200 assert json.loads(server_response.data.decode()) == expected assert_header(header, server_response.headers) def test_get_project_with_no_products( monkeypatch, highlight_data, db_fixture, projects, client, header, get_contentreview_data_ok, get_vendor_ows_response, get_company_brand_ows_response): """Assert that an empty set is returned for a project with no products. Asserts that the route returns a 200 with an empty set. It tests for correlation-id and content-type in the response header. """ project_id = 3 artist_spec = { 'service': 'ows-artist', 'path': '/artist/4567', 'status': 200, 'json': { 'id': 4567, 'name': 'Solange Knowles', 'artist_type': 'artist'}} get_specs = [{ 'service': 'ows-marketing', 'path': '/highlights/project/{}?mkt_program_id={}'.format( project_id, marketing_const.PROGRAM_MARKETING_HIGHLIGHTS), 'status': 200, 'json': {'items': [highlight_data]}}, artist_spec, get_contentreview_data_ok, get_vendor_ows_response, get_company_brand_ows_response] monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests(get_specs)) server_response = client.get( '/project/{}/products'.format(project_id), headers=header) assert server_response.status_code == 200 assert json.loads(server_response.data.decode()) == {'items': []} assert_header(header, server_response.headers)