Skip to content

Commit

Permalink
fix(playlist): change response model to accept optional answers (#2152)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored Sep 23, 2024
1 parent 664a55c commit 749cb28
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
4 changes: 2 additions & 2 deletions antarest/study/web/study_data_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,12 @@ def set_playlist(
"/studies/{uuid}/config/playlist",
tags=[APITag.study_data],
summary="Get playlist config",
response_model=t.Dict[int, float],
response_model=t.Optional[t.Dict[int, float]],
)
def get_playlist_config(
uuid: str,
current_user: JWTUser = Depends(auth.get_current_user),
) -> t.Any:
) -> t.Optional[t.Dict[int, float]]:
logger.info(
f"Fetching playlist config for study {uuid}",
extra={"user": current_user.id},
Expand Down
44 changes: 44 additions & 0 deletions tests/integration/study_data_blueprint/test_playlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from starlette.testclient import TestClient


class TestConfigPlaylist:
"""
Test the end points related to the playlist.
"""

def test_nominal_case(self, client: TestClient, user_access_token: str):
client.headers = {"Authorization": f"Bearer {user_access_token}"}

base_study_res = client.post("/v1/studies?name=foo")
study_id = base_study_res.json()

res = client.get(f"/v1/studies/{study_id}/config/playlist")
assert res.status_code == 200
assert res.json() is None

res = client.post(f"/v1/studies/{study_id}/raw?path=settings/generaldata/general/nbyears", json=5)
assert res.status_code == 204

res = client.put(
f"/v1/studies/{study_id}/config/playlist",
json={"playlist": [1, 2], "weights": {1: 8.0, 3: 9.0}},
)
assert res.status_code == 200

res = client.get(
f"/v1/studies/{study_id}/config/playlist",
)
assert res.status_code == 200
assert res.json() == {"1": 8.0, "2": 1.0}
22 changes: 0 additions & 22 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,6 @@ def test_main(client: TestClient, admin_access_token: str) -> None:
)
assert res.status_code == 200, res.json()

# playlist
res = client.post(
f"/v1/studies/{study_id}/raw?path=settings/generaldata/general/nbyears",
headers={"Authorization": f'Bearer {george_credentials["access_token"]}'},
json=5,
)
assert res.status_code == 204

res = client.put(
f"/v1/studies/{study_id}/config/playlist",
headers={"Authorization": f'Bearer {george_credentials["access_token"]}'},
json={"playlist": [1, 2], "weights": {1: 8.0, 3: 9.0}},
)
assert res.status_code == 200

res = client.get(
f"/v1/studies/{study_id}/config/playlist",
headers={"Authorization": f'Bearer {george_credentials["access_token"]}'},
)
assert res.status_code == 200
assert res.json() == {"1": 8.0, "2": 1.0}

# Update the active ruleset
active_ruleset_name = "ruleset test"
res = client.post(
Expand Down

0 comments on commit 749cb28

Please sign in to comment.