"""Tests for POST /reports/dataloader endpoint.""" import json from oto import status from tests.testutils import db, mock_auth @db.test_schema_default_seed def test_post_reports_dataloader(auth_client, mocker): """Expect to bulk fetch reports.""" mock_auth(mocker, 120594) data = {"report_ids": [6, 7]} result = auth_client.post( "/reports/dataloader", data=json.dumps(data), content_type="application/json" ) result_data = json.loads(result.data.decode()) assert result.status_code == status.OK assert result_data == [ { "data": { "amount": 1234.0, "collaborator_id": 10, "currency": "NOK", "deleted_by": None, "deleted_datetime": None, "exclude_transaction_types": None, "file_location": "s3://test.xls", "filename": "test.xls", "generated_datetime": "2019-10-09T08:07:06", "id": 6, "report_run_id": 1, "requested_datetime": "2019-09-08T07:06:05", "status": "GENERATED", "transaction_id": 2, "collaborator_dp_enabled": True, } }, { "data": { "amount": 1234.0, "collaborator_id": 10, "currency": "NOK", "deleted_by": None, "deleted_datetime": None, "exclude_transaction_types": None, "file_location": "s3://test.xls", "filename": "test.xls", "generated_datetime": "2019-10-09T08:07:06", "id": 7, "report_run_id": 1, "requested_datetime": "2019-09-08T07:06:05", "status": "GENERATED", "transaction_id": None, "collaborator_dp_enabled": True, } }, ] @db.test_schema_default_seed def test_post_reports_dataloader_missing_report_ids(auth_client, mocker): """Expect a 400 when report_ids is absent.""" mock_auth(mocker, 120594) result = auth_client.post( "/reports/dataloader", data=json.dumps({}), content_type="application/json" ) assert result.status_code == status.BAD_REQUEST @db.test_schema_default_seed def test_post_reports_dataloader_report_ids_not_a_list(auth_client, mocker): """Expect a 400 when report_ids is not a list.""" mock_auth(mocker, 120594) result = auth_client.post( "/reports/dataloader", data=json.dumps({"report_ids": "6"}), content_type="application/json", ) assert result.status_code == status.BAD_REQUEST