Skip to content

Minor adjustment on error semantics and model business rules #42

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

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/controllers/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async def simulate_env(
logger.error(f"controllers.environment.simulate: {exc_str}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to simulate environment: {exc_str}",
detail=f"Failed to simulate environment, parameters may contain data that is not physically coherent: {exc_str}",
) from e
else:
return env_summary
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ async def simulate_flight(
logger.error(f"controllers.flight.simulate_flight: {exc_str}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to simulate flight: {exc_str}",
detail=f"Failed to simulate flight, parameters may contain data that is not physically coherent: {exc_str}",
) from e
else:
return flight_summary
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ async def simulate_motor(
logger.error(f"controllers.motor.simulate_motor: {exc_str}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to simulate motor: {exc_str}",
detail=f"Failed to simulate motor, parameters may contain data that is not physically coherent: {exc_str}",
) from e
else:
return motor_summary
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ async def simulate_rocket(
logger.error(f"controllers.rocket.simulate: {exc_str}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to simulate rocket: {exc_str}",
detail=f"Failed to simulate rocket, parameters may contain data that is not physically coherent: {exc_str}",
) from e
else:
return rocket_summary
Expand Down
4 changes: 2 additions & 2 deletions lib/models/rocket.py
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not allowing rockets without fins or nose?

Copy link
Collaborator Author

@GabrielBarberini GabrielBarberini Feb 2, 2025

Choose a reason for hiding this comment

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

Its a FUP from the recent debug session we had. We understand that rockets without fins or nose are a minor use-case but a major bug raiser. Since changing from mandatory to optional or vice-versa is an easy task we decided to keep it more restrictive for now.

The bug itself we were tracking is not on the API side tho. @phmbressan will probably share more details about this in the upcoming libdev meetings.

Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class Rocket(BaseModel):
coordinate_system_orientation: CoordinateSystemOrientation = (
CoordinateSystemOrientation.TAIL_TO_NOSE
)
nose: NoseCone
fins: List[Fins]

# Optional parameters
parachutes: Optional[List[Parachute]] = None
rail_buttons: Optional[RailButtons] = None
nose: Optional[NoseCone] = None
fins: Optional[List[Fins]] = None
tail: Optional[Tail] = None
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
flake8
pylint
ruff
pytest
httpx
33 changes: 32 additions & 1 deletion tests/test_routes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from lib.models.rocket import Rocket
from lib.models.motor import Motor, MotorTank, TankFluids, TankKinds
from lib.models.environment import Env
from lib.models.aerosurfaces import Fins, NoseCone


@pytest.fixture
Expand Down Expand Up @@ -79,7 +80,35 @@ def stub_mass_tank(stub_tank):


@pytest.fixture
def stub_rocket(stub_motor):
def stub_nose_cone():
nose_cone = NoseCone(
name='nose',
length=0,
kind='kind',
position=0,
base_radius=0,
rocket_radius=0,
)
nose_cone_json = nose_cone.model_dump_json()
return json.loads(nose_cone_json)


@pytest.fixture
def stub_fins():
fins = Fins(
fins_kind='TRAPEZOIDAL',
name='fins',
n=0,
root_chord=0,
span=0,
position=0,
)
fins_json = fins.model_dump_json()
return json.loads(fins_json)


@pytest.fixture
def stub_rocket(stub_motor, stub_nose_cone, stub_fins):
rocket = Rocket(
motor=stub_motor,
radius=0,
Expand All @@ -89,6 +118,8 @@ def stub_rocket(stub_motor):
inertia=[0, 0, 0],
power_off_drag=[(0, 0)],
power_on_drag=[(0, 0)],
nose=stub_nose_cone,
fins=[stub_fins],
coordinate_system_orientation='TAIL_TO_NOSE',
)
rocket_json = rocket.model_dump_json()
Expand Down
34 changes: 0 additions & 34 deletions tests/test_routes/test_rockets_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from fastapi.testclient import TestClient
from fastapi import HTTPException, status
from lib.models.aerosurfaces import (
Fins,
NoseCone,
Tail,
RailButtons,
Parachute,
Expand Down Expand Up @@ -36,34 +34,6 @@ def stub_rocket_summary():
return json.loads(rocket_summary_json)


@pytest.fixture
def stub_nose_cone():
nose_cone = NoseCone(
name='nose',
length=0,
kind='kind',
position=0,
base_radius=0,
rocket_radius=0,
)
nose_cone_json = nose_cone.model_dump_json()
return json.loads(nose_cone_json)


@pytest.fixture
def stub_fins():
fins = Fins(
fins_kind='TRAPEZOIDAL',
name='fins',
n=0,
root_chord=0,
span=0,
position=0,
)
fins_json = fins.model_dump_json()
return json.loads(fins_json)


@pytest.fixture
def stub_tail():
tail = Tail(
Expand Down Expand Up @@ -126,8 +96,6 @@ def test_create_rocket(stub_rocket):

def test_create_rocket_optional_params(
stub_rocket,
stub_nose_cone,
stub_fins,
stub_tail,
stub_rail_buttons,
stub_parachute,
Expand All @@ -136,8 +104,6 @@ def test_create_rocket_optional_params(
{
'parachutes': [stub_parachute],
'rail_buttons': stub_rail_buttons,
'nose': stub_nose_cone,
'fins': [stub_fins],
'tail': stub_tail,
}
)
Expand Down