Skip to content

Commit

Permalink
test(aggregation-api): check that an Error OutputSubFolderNotFound
Browse files Browse the repository at this point in the history
…is raised when relevant
  • Loading branch information
mabw-rte committed Aug 22, 2024
1 parent 875045f commit 1d0b944
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/integration/raw_studies_blueprint/test_aggregate_raw_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import io
import shutil
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -612,6 +614,26 @@ def test_empty_columns(self, client: TestClient, user_access_token: str, interna
df = pd.read_csv(io.BytesIO(res.content), index_col=0, sep=",")
assert df.empty

def test_non_existing_folder(
self, tmp_path: Path, client: TestClient, user_access_token: str, internal_study_id: str
):
"""
Asserts that requests with non-existing folders send an HTTP 404 Exception
"""
client.headers = {"Authorization": f"Bearer {user_access_token}"}

# the mc-ind folder
mc_ind_folder = tmp_path.joinpath("ext_workspace/STA-mini/output/20201014-1425eco-goodbye/economy/mc-ind")
# delete the folder
shutil.rmtree(mc_ind_folder)
res = client.get(
f"/v1/studies/{internal_study_id}/areas/aggregate/mc-ind/20201014-1425eco-goodbye",
params={"query_file": MCIndAreasQueryFile.VALUES, "frequency": MatrixFrequency.HOURLY},
)
assert res.status_code == 404, res.json()
assert "economy/mc-ind" in res.json()["description"]
assert res.json()["exception"] == "OutputSubFolderNotFound"


@pytest.mark.integration_test
class TestRawDataAggregationMCAll:
Expand Down Expand Up @@ -800,3 +822,21 @@ def test_empty_columns(self, client: TestClient, user_access_token: str, interna
assert res.status_code == 200, res.json()
df = pd.read_csv(io.BytesIO(res.content), index_col=0, sep=",")
assert df.empty

def test_non_existing_folder(
self, tmp_path: Path, client: TestClient, user_access_token: str, internal_study_id: str
):
"""
Test that an error 404 is raised when the `economy/mc-all` folder does not exist
"""
client.headers = {"Authorization": f"Bearer {user_access_token}"}
mc_all_path = tmp_path.joinpath("ext_workspace/STA-mini/output/20241807-1540eco-extra-outputs/economy/mc-all")
# delete the folder
shutil.rmtree(mc_all_path)
res = client.get(
f"/v1/studies/{internal_study_id}/links/aggregate/mc-all/20241807-1540eco-extra-outputs",
params={"query_file": MCAllLinksQueryFile.VALUES, "frequency": MatrixFrequency.DAILY},
)
assert res.status_code == 404, res.json()
assert "economy/mc-all" in res.json()["description"]
assert res.json()["exception"] == "OutputSubFolderNotFound"

0 comments on commit 1d0b944

Please sign in to comment.