Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add outputs #37

Merged
merged 16 commits into from
Dec 18, 2024
Merged

feat(api): add outputs #37

merged 16 commits into from
Dec 18, 2024

Conversation

salemsd
Copy link
Collaborator

@salemsd salemsd commented Dec 17, 2024

  • Added outputs and service to study
  • Added unit and integration tests

@@ -52,6 +53,184 @@ class TestCreateAPI:
ServiceFactory(api, study_id).create_thermal_service(),
ServiceFactory(api, study_id).create_renewable_service(),
)
json_output = [
Copy link
Collaborator Author

@salemsd salemsd Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure about the json for the outputs in the unit tests. Since it's very large, should I just include the relevant keys (id, archived) or leave it like that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed we don't need all this. You can just simplify by:

{
    "name": "20241217-1115eco-sdqsd",
    "type": "economy",
    "settings": {},
    "archived": False,
}

for instance

Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, otherwise it's good :)


Returns: (output_id, Output) dictionary
"""
return self._outputs.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing a copy what we do is we return a MappingProxyType. This basically does the same thing but we should keep the code coherent (see get_binding_constraints method for instance)


Returns: Output with the output_id
"""
return self._outputs.get(output_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be crash instead of returning a None ? I don't know

try:
response = self._wrapper.get(url)
outputs_json_list = response.json()
outputs_list: list[Output] = list()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a comprehension list:

outputs_list = [Output(name=output["name"], archived=output["archived"]) for output in outputs_json_list]

@@ -499,7 +499,12 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
new_study.get_binding_constraints().keys()
)

# ===== test run study simulation and wait job completion ======
# ===== Test outputs (Part 1) =====
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add - before simulation


study.read_outputs()
outputs = study.get_outputs()
assert len(outputs) > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check that you have only one and that it's unarchived

@@ -52,6 +53,184 @@ class TestCreateAPI:
ServiceFactory(api, study_id).create_thermal_service(),
ServiceFactory(api, study_id).create_renewable_service(),
)
json_output = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed we don't need all this. You can just simplify by:

{
    "name": "20241217-1115eco-sdqsd",
    "type": "economy",
    "settings": {},
    "archived": False,
}

for instance


Raises: KeyError if it doesn't exist
"""
return self._outputs[f"{output_id}"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just be self._outputs[output_id]

try:
response = self._wrapper.get(url)
outputs_json_list = response.json()
if isinstance(outputs_json_list, dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the endpoint is supposed to return a list so I don't see where you could enter this if

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad i misread the api doc

@@ -215,6 +217,15 @@ def test_read_study_api(self):
mocker.get(renewable_url, json=[])
mocker.get(thermal_url, json=[])
mocker.get(storage_url, json=[])
mocker.get(
output_url,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these 2 tests, you can just return an empty list: mocker.get(output_url, json=[]) as you don't really test the content

assert len(self.study.get_outputs()) == 2
output1 = self.study.get_output(json_output[0].get("name"))
output2 = self.study.get_output(json_output[1].get("name"))
assert output1 is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now you can return the checks of nullity

output = study.read_outputs()[0]
outputs = study.get_outputs()
assert len(outputs) == 1
assert outputs.get(output.name).archived is not False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified in assert outputs.get(output.name).archived I think

@MartinBelthle MartinBelthle merged commit 6c52429 into main Dec 18, 2024
8 checks passed
@MartinBelthle MartinBelthle deleted the feat/add_outputs branch December 18, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants