Skip to content

Commit ece22c0

Browse files
improve error semantics on simulation route crash; make fins and nosecone mandatory parameters
1 parent a03a578 commit ece22c0

File tree

8 files changed

+40
-41
lines changed

8 files changed

+40
-41
lines changed

lib/controllers/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async def simulate_env(
264264
logger.error(f"controllers.environment.simulate: {exc_str}")
265265
raise HTTPException(
266266
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
267-
detail=f"Failed to simulate environment: {exc_str}",
267+
detail=f"Failed to simulate environment, parameters may contain data that is not physically coherent: {exc_str}",
268268
) from e
269269
else:
270270
return env_summary

lib/controllers/flight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ async def simulate_flight(
384384
logger.error(f"controllers.flight.simulate_flight: {exc_str}")
385385
raise HTTPException(
386386
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
387-
detail=f"Failed to simulate flight: {exc_str}",
387+
detail=f"Failed to simulate flight, parameters may contain data that is not physically coherent: {exc_str}",
388388
) from e
389389
else:
390390
return flight_summary

lib/controllers/motor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async def simulate_motor(
279279
logger.error(f"controllers.motor.simulate_motor: {exc_str}")
280280
raise HTTPException(
281281
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
282-
detail=f"Failed to simulate motor: {exc_str}",
282+
detail=f"Failed to simulate motor, parameters may contain data that is not physically coherent: {exc_str}",
283283
) from e
284284
else:
285285
return motor_summary

lib/controllers/rocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async def simulate_rocket(
279279
logger.error(f"controllers.rocket.simulate: {exc_str}")
280280
raise HTTPException(
281281
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
282-
detail=f"Failed to simulate rocket: {exc_str}",
282+
detail=f"Failed to simulate rocket, parameters may contain data that is not physically coherent: {exc_str}",
283283
) from e
284284
else:
285285
return rocket_summary

lib/models/rocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Rocket(BaseModel):
3333
coordinate_system_orientation: CoordinateSystemOrientation = (
3434
CoordinateSystemOrientation.TAIL_TO_NOSE
3535
)
36+
nose: NoseCone
37+
fins: List[Fins]
3638

3739
# Optional parameters
3840
parachutes: Optional[List[Parachute]] = None
3941
rail_buttons: Optional[RailButtons] = None
40-
nose: Optional[NoseCone] = None
41-
fins: Optional[List[Fins]] = None
4242
tail: Optional[Tail] = None

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
flake8
22
pylint
33
ruff
4+
pytest
5+
httpx

tests/test_routes/conftest.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from lib.models.rocket import Rocket
55
from lib.models.motor import Motor, MotorTank, TankFluids, TankKinds
66
from lib.models.environment import Env
7+
from lib.models.aerosurfaces import Fins, NoseCone
78

89

910
@pytest.fixture
@@ -79,7 +80,35 @@ def stub_mass_tank(stub_tank):
7980

8081

8182
@pytest.fixture
82-
def stub_rocket(stub_motor):
83+
def stub_nose_cone():
84+
nose_cone = NoseCone(
85+
name='nose',
86+
length=0,
87+
kind='kind',
88+
position=0,
89+
base_radius=0,
90+
rocket_radius=0,
91+
)
92+
nose_cone_json = nose_cone.model_dump_json()
93+
return json.loads(nose_cone_json)
94+
95+
96+
@pytest.fixture
97+
def stub_fins():
98+
fins = Fins(
99+
fins_kind='TRAPEZOIDAL',
100+
name='fins',
101+
n=0,
102+
root_chord=0,
103+
span=0,
104+
position=0,
105+
)
106+
fins_json = fins.model_dump_json()
107+
return json.loads(fins_json)
108+
109+
110+
@pytest.fixture
111+
def stub_rocket(stub_motor, stub_nose_cone, stub_fins):
83112
rocket = Rocket(
84113
motor=stub_motor,
85114
radius=0,
@@ -89,6 +118,8 @@ def stub_rocket(stub_motor):
89118
inertia=[0, 0, 0],
90119
power_off_drag=[(0, 0)],
91120
power_on_drag=[(0, 0)],
121+
nose=stub_nose_cone,
122+
fins=[stub_fins],
92123
coordinate_system_orientation='TAIL_TO_NOSE',
93124
)
94125
rocket_json = rocket.model_dump_json()

tests/test_routes/test_rockets_route.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from fastapi.testclient import TestClient
55
from fastapi import HTTPException, status
66
from lib.models.aerosurfaces import (
7-
Fins,
8-
NoseCone,
97
Tail,
108
RailButtons,
119
Parachute,
@@ -36,34 +34,6 @@ def stub_rocket_summary():
3634
return json.loads(rocket_summary_json)
3735

3836

39-
@pytest.fixture
40-
def stub_nose_cone():
41-
nose_cone = NoseCone(
42-
name='nose',
43-
length=0,
44-
kind='kind',
45-
position=0,
46-
base_radius=0,
47-
rocket_radius=0,
48-
)
49-
nose_cone_json = nose_cone.model_dump_json()
50-
return json.loads(nose_cone_json)
51-
52-
53-
@pytest.fixture
54-
def stub_fins():
55-
fins = Fins(
56-
fins_kind='TRAPEZOIDAL',
57-
name='fins',
58-
n=0,
59-
root_chord=0,
60-
span=0,
61-
position=0,
62-
)
63-
fins_json = fins.model_dump_json()
64-
return json.loads(fins_json)
65-
66-
6737
@pytest.fixture
6838
def stub_tail():
6939
tail = Tail(
@@ -126,8 +96,6 @@ def test_create_rocket(stub_rocket):
12696

12797
def test_create_rocket_optional_params(
12898
stub_rocket,
129-
stub_nose_cone,
130-
stub_fins,
13199
stub_tail,
132100
stub_rail_buttons,
133101
stub_parachute,
@@ -136,8 +104,6 @@ def test_create_rocket_optional_params(
136104
{
137105
'parachutes': [stub_parachute],
138106
'rail_buttons': stub_rail_buttons,
139-
'nose': stub_nose_cone,
140-
'fins': [stub_fins],
141107
'tail': stub_tail,
142108
}
143109
)

0 commit comments

Comments
 (0)