Skip to content

Commit 5eb763f

Browse files
MNT: address second round of PR review comments
- Add HTTP 413 to /upload route OpenAPI responses schema - Move grain_fields construction inside SOLID|HYBRID match branch to avoid AttributeError on LIQUID/GENERIC motors - Add test for oversized .rpy upload returning HTTP 413 Made-with: Cursor
1 parent 5d291c7 commit 5eb763f

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

src/routes/flight.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ async def get_rocketpy_flight_rpy(
190190
status_code=201,
191191
responses={
192192
201: {"description": "Flight imported from .rpy file"},
193+
413: {"description": "Uploaded .rpy file exceeds size limit"},
193194
422: {"description": "Invalid .rpy file"},
194195
},
195196
)

src/services/flight.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,24 @@ def _extract_motor(motor) -> MotorModel:
176176
),
177177
}
178178

179-
grain_fields = {
180-
"grain_number": motor.grain_number,
181-
"grain_density": motor.grain_density,
182-
"grain_outer_radius": motor.grain_outer_radius,
183-
"grain_initial_inner_radius": (motor.grain_initial_inner_radius),
184-
"grain_initial_height": motor.grain_initial_height,
185-
"grain_separation": motor.grain_separation,
186-
"grains_center_of_mass_position": (
187-
motor.grains_center_of_mass_position
188-
),
189-
"throat_radius": motor.throat_radius,
190-
}
191-
192179
match kind:
193-
case MotorKinds.SOLID:
194-
data |= grain_fields
195-
case MotorKinds.HYBRID:
196-
data |= grain_fields
197-
data["tanks"] = FlightService._extract_tanks(motor)
180+
case MotorKinds.SOLID | MotorKinds.HYBRID:
181+
data |= {
182+
"grain_number": motor.grain_number,
183+
"grain_density": motor.grain_density,
184+
"grain_outer_radius": motor.grain_outer_radius,
185+
"grain_initial_inner_radius": (
186+
motor.grain_initial_inner_radius
187+
),
188+
"grain_initial_height": (motor.grain_initial_height),
189+
"grain_separation": motor.grain_separation,
190+
"grains_center_of_mass_position": (
191+
motor.grains_center_of_mass_position
192+
),
193+
"throat_radius": motor.throat_radius,
194+
}
195+
if kind is MotorKinds.HYBRID:
196+
data["tanks"] = FlightService._extract_tanks(motor)
198197
case MotorKinds.LIQUID:
199198
data["tanks"] = FlightService._extract_tanks(motor)
200199
case MotorKinds.GENERIC:

tests/unit/test_routes/test_flights_route.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,21 @@ def test_import_flight_from_rpy_server_error(
601601
assert response.status_code == 500
602602

603603

604+
def test_import_flight_from_rpy_payload_too_large(
605+
mock_controller_instance,
606+
):
607+
oversized = b"a" * (10 * 1024 * 1024 + 1)
608+
response = client.post(
609+
'/flights/upload',
610+
files={'file': ('large.rpy', oversized, 'application/json')},
611+
)
612+
assert response.status_code == 413
613+
assert response.json() == {
614+
'detail': 'Uploaded .rpy file exceeds 10 MB limit.'
615+
}
616+
mock_controller_instance.import_flight_from_rpy.assert_not_called()
617+
618+
604619
# --- Issue #57: Export flight as notebook ---
605620

606621

0 commit comments

Comments
 (0)