"""Test project ownership functional test.""" from owsrequest import request from owsrequest import test_utils from project_manager.constant import header_const from project_manager.constant import http_status_codes from tests.utils import logger def test_check_product_ownership( db_fixture, project, client, mocker, monkeypatch, get_artist_info_ok): """Test project ownership check.""" logger.patch(mocker) request_url = '/ownership/{}/{}/project/{}'.format( header_const.GRASS_ACCOUNT_TYPE_SUBACCOUNT, 1, 1) monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests([get_artist_info_ok])) server_response = client.head( request_url.format( header_const.GRASS_ACCOUNT_TYPE_SUBACCOUNT, 1, 1)) assert server_response.status_code == http_status_codes.OK logger.assert_logger_calls( status=http_status_codes.OK, verb='HEAD', path=request_url) def test_check_product_ownership_with_grass_headers( db_fixture, project, client, mocker, monkeypatch, get_artist_info_ok): """Test project ownership check. Test call coming from grass.""" logger.patch(mocker) monkeypatch.setattr( request, 'get', test_utils.mock_ows_requests([get_artist_info_ok])) request_url = '/ownership/{}/{}/project/{}'.format( header_const.GRASS_ACCOUNT_TYPE_SUBACCOUNT, 1, 1) request_headers = { header_const.GRASS_ACCOUNT_TYPE: header_const.GRASS_ACCOUNT_TYPE_VENDOR, header_const.GRASS_ACCOUNT_ID: 7123, } server_response = client.head(request_url, headers=request_headers) assert server_response.status_code == http_status_codes.OK logger.assert_logger_calls( status=http_status_codes.OK, verb='HEAD', path=request_url, resources=dict( account_type=request_headers.get(header_const.GRASS_ACCOUNT_TYPE), account_id=str(request_headers.get(header_const.GRASS_ACCOUNT_ID)) )) def test_check_product_ownership_bad_header_format(client): """Assert header validation is run.""" request_url = '/ownership/{}/{}/project/{}' request_headers = { header_const.GRASS_ACCOUNT_TYPE: 'applesauce', header_const.GRASS_ACCOUNT_ID: 7123, } server_response = client.head( request_url.format( header_const.GRASS_ACCOUNT_TYPE_SUBACCOUNT, 1, 1), headers=request_headers) assert server_response.status_code == http_status_codes.BAD_REQUEST