-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33e7993
commit 4f4cb40
Showing
8 changed files
with
158 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
[build-system] | ||
requires = ["setuptools", "setuptools_scm"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools.dynamic] | ||
dependencies = {file = ["requirements.txt"]} | ||
|
||
[project] | ||
name = "Infinity-API" | ||
version = "2.2.0" | ||
version = "2.3.0" | ||
description = "RESTFULL open API for rocketpy" | ||
dynamic = ["dependencies"] | ||
requires-python = ">=3.12" | ||
authors = [ | ||
{name = "Gabriel Barberini", email = "[email protected]"} | ||
|
@@ -21,7 +13,7 @@ maintainers = [ | |
readme = "README.md" | ||
keywords = ["rocketpy", "API", "simulation", "rocket", "flight"] | ||
classifiers = [ | ||
"Development Status :: Alpha", | ||
"Development Status :: Production", | ||
"Programming Language :: Python" | ||
] | ||
|
||
|
@@ -52,3 +44,14 @@ disable = """ | |
raise-missing-from, | ||
too-many-instance-attributes, | ||
""" | ||
|
||
[tool.ruff] | ||
line-length = 79 | ||
target-version = "py313" | ||
|
||
[tool.ruff.lint] | ||
select = ["E", "F", "N", "Q"] | ||
ignore = ["N815", "E501", "Q000", "E402"] | ||
fixable = [ | ||
"F401", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flake8 | ||
pylint | ||
ruff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from unittest.mock import patch | ||
from lib.models.environment import Env | ||
from lib.controllers.environment import EnvController | ||
from lib.views.environment import ( | ||
EnvCreated, | ||
EnvUpdated, | ||
EnvDeleted, | ||
EnvSummary, | ||
) | ||
from lib import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
@pytest.fixture | ||
def mock_env(): | ||
return Env(latitude=0, longitude=0) | ||
|
||
|
||
@pytest.fixture | ||
def mock_env_summary(): | ||
return EnvSummary() | ||
|
||
|
||
def test_create_env(mock_env): | ||
with patch.object( | ||
EnvController, "create_env", return_value=EnvCreated(env_id="123") | ||
) as mock_create_env: | ||
response = client.post( | ||
"/environments/", json={"latitude": 0, "longitude": 0} | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"env_id": "123", | ||
"message": "Environment successfully created", | ||
} | ||
mock_create_env.assert_called_once_with(Env(latitude=0, longitude=0)) | ||
|
||
|
||
def test_read_env(mock_env): | ||
with patch.object( | ||
EnvController, "get_env_by_id", return_value=mock_env | ||
) as mock_read_env: | ||
response = client.get("/environments/123") | ||
assert response.status_code == 200 | ||
expected_content = mock_env.model_dump() | ||
expected_content["date"] = expected_content["date"].isoformat() | ||
assert response.json() == expected_content | ||
mock_read_env.assert_called_once_with("123") | ||
|
||
|
||
def test_update_env(): | ||
with patch.object( | ||
EnvController, | ||
"update_env_by_id", | ||
return_value=EnvUpdated(env_id="123"), | ||
) as mock_update_env: | ||
response = client.put( | ||
"/environments/123", json={"longitude": 1, "latitude": 1} | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"env_id": "123", | ||
"message": "Environment successfully updated", | ||
} | ||
mock_update_env.assert_called_once_with( | ||
"123", Env(latitude=1, longitude=1) | ||
) | ||
|
||
|
||
def test_delete_env(): | ||
with patch.object( | ||
EnvController, | ||
"delete_env_by_id", | ||
return_value=EnvDeleted(env_id="123"), | ||
) as mock_delete_env: | ||
response = client.delete("/environments/123") | ||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"env_id": "123", | ||
"message": "Environment successfully deleted", | ||
} | ||
mock_delete_env.assert_called_once_with("123") | ||
|
||
|
||
def test_simulate_env(mock_env_summary): | ||
with patch.object( | ||
EnvController, "simulate_env", return_value=mock_env_summary | ||
) as mock_simulate_env: | ||
response = client.get("/environments/123/summary") | ||
assert response.status_code == 200 | ||
expected_content = mock_env_summary.model_dump() | ||
expected_content["date"] = expected_content["date"].isoformat() | ||
expected_content["local_date"] = expected_content[ | ||
"local_date" | ||
].isoformat() | ||
expected_content["datetime_date"] = expected_content[ | ||
"datetime_date" | ||
].isoformat() | ||
assert response.json() == expected_content | ||
mock_simulate_env.assert_called_once_with("123") | ||
|
||
|
||
def test_read_rocketpy_env(mock_env): | ||
with patch.object( | ||
EnvController, "get_rocketpy_env_binary", return_value=b'rocketpy' | ||
) as mock_read_rocketpy_env: | ||
response = client.get("/environments/123/rocketpy") | ||
assert response.status_code == 203 | ||
assert response.content == b'rocketpy' | ||
assert response.headers["content-type"] == "application/octet-stream" | ||
mock_read_rocketpy_env.assert_called_once_with("123") |