"""Get product for project functional test.""" import json from owsrequest import request from owsrequest import test_utils from project_manager.constant import error_const from tests.common_assert import assert_header def test_get_product_no_project(db_fixture, projects, client, header): """404 response from GET/project/{project_id}/product/{product_id}. Asserts that the route returns a 404 with the appropriate JSON. It tests for correlation-id and content-type in the response header. """ server_response = client.get('/project/0/product/235', 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_product_no_product( db_fixture, project_highlight_ok, monkeypatch, projects, client, header, get_artist_info_ok): """404 response from GET/project/{project_id}/product/{product_id}. 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([ project_highlight_ok, get_artist_info_ok])) server_response = client.get('/project/1/product/0', headers=header) response_json = json.loads(server_response.data.decode()) expected_json = { 'code': error_const.ERROR_CODE_NOT_FOUND, 'message': 'Unable to find product_id 0'} assert server_response.status_code == 404 assert response_json == expected_json assert_header(header, server_response.headers) def test_get_product_by_project( db_fixture, project_highlight_ok, monkeypatch, projects, client, header, get_artist_info_ok, get_vendor_ows_response, get_company_brand_ows_response): """Assert that a product associated with a project is returned. Asserts that the route returns a 200 with a JSON object that represents the product. Asserts correlation-id and content-type in the response header. """ monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests([ project_highlight_ok, get_company_brand_ows_response, get_vendor_ows_response, get_artist_info_ok])) expected_json = { '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' } server_response = client.get('/project/1/product/1003', headers=header) assert server_response.status_code == 200 assert json.loads(server_response.data.decode()) == expected_json assert_header(header, server_response.headers)