"""Functional tests for getting report data.""" import json from oto import status from collaborator.utils import s3 from tests.testutils import db, mock_auth @db.test_schema_default_seed def test_get_report_download(auth_client, mock_account, mocker): """Test getting reports with transactions.""" mock_auth(mocker, mock_account.id) PRESIGNED_URL = "PRESIGNED_URL" mocker.patch.object(s3, "extract_bucket_path", return_value=("", "")) mocker.patch.object(s3, "object_exists", return_value=True) mocker.patch.object(s3, "get_presigned_url", return_value=PRESIGNED_URL) result = auth_client.get("/reports/1/download") result_data = json.loads(result.data.decode()) assert result.status_code == status.OK assert result_data["url"] == PRESIGNED_URL @db.test_schema_default_seed def test_get_report_download_moneyhub_profile(auth_client, mocker): """Test getting reports with transactions.""" collab_id = 1 mock_auth(mocker, collab_id) PRESIGNED_URL = "PRESIGNED_URL" mocker.patch.object(s3, "extract_bucket_path", return_value=("", "")) mocker.patch.object(s3, "object_exists", return_value=True) mocker.patch.object(s3, "get_presigned_url", return_value=PRESIGNED_URL) result = auth_client.get( "/reports/1/download", headers=[ ("orchard-identity-id", "7ec441df-7b21-4a71-a9da"), ("orchard-profile-id", "90003"), ("orchard-profile-type", "MoneyhubProfile"), ], ) result_data = json.loads(result.data.decode()) assert result.status_code == status.OK assert result_data["url"] == PRESIGNED_URL @db.test_schema_default_seed def test_get_report_download_no_access(auth_client, mocker): """Test getting reports with transactions.""" mock_auth(mocker, 123) result = auth_client.get("/reports/1/download") assert result.status_code == status.FORBIDDEN