Skip to content

Commit d00ae26

Browse files
implements motor route tests
1 parent 1d60ae4 commit d00ae26

File tree

8 files changed

+357
-33
lines changed

8 files changed

+357
-33
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ flake8:
99
flake8 --ignore E501,E402,F401,W503,C0414 ./tests || true
1010

1111
pylint:
12-
pylint --extension-pkg-whitelist='pydantic' ./lib || true
13-
pylint --extension-pkg-whitelist='pydantic' --disable=E0401,W0621 ./tests || true
12+
pylint ./lib || true
13+
pylint --disable=E0401,W0621 ./tests || true
1414

1515
ruff:
1616
ruff check --fix ./lib || true

lib/controllers/motor.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ class MotorController:
2626
- Create a rocketpy.Motor object from a Motor model object.
2727
"""
2828

29-
def __init__(self, motor: Motor):
30-
self.guard(motor)
31-
self._motor = motor
32-
33-
@property
34-
def motor(self) -> Motor:
35-
return self._motor
36-
37-
@motor.setter
38-
def motor(self, motor: Motor):
39-
self._motor = motor
40-
4129
@staticmethod
4230
def guard(motor: Motor):
4331
if (
@@ -51,15 +39,19 @@ def guard(motor: Motor):
5139

5240
# TODO: extend guard to check motor kinds and tank kinds specifics
5341

54-
async def create_motor(self) -> Union[MotorCreated, HTTPException]:
42+
@classmethod
43+
async def create_motor(
44+
cls, motor: Motor
45+
) -> Union[MotorCreated, HTTPException]:
5546
"""
5647
Create a models.Motor in the database.
5748
5849
Returns:
5950
views.MotorCreated
6051
"""
6152
try:
62-
async with MotorRepository(self.motor) as motor_repo:
53+
cls.guard(motor)
54+
async with MotorRepository(motor) as motor_repo:
6355
await motor_repo.create_motor()
6456
except PyMongoError as e:
6557
logger.error(f"controllers.motor.create_motor: PyMongoError {e}")
@@ -173,8 +165,9 @@ async def get_rocketpy_motor_binary(
173165
f"Call to controllers.motor.get_rocketpy_motor_binary completed for Motor {motor_id}"
174166
)
175167

168+
@classmethod
176169
async def update_motor_by_id(
177-
self, motor_id: str
170+
cls, motor_id: str, motor: Motor
178171
) -> Union[MotorUpdated, HTTPException]:
179172
"""
180173
Update a motor in the database.
@@ -189,7 +182,8 @@ async def update_motor_by_id(
189182
HTTP 404 Not Found: If the motor is not found in the database.
190183
"""
191184
try:
192-
async with MotorRepository(self.motor) as motor_repo:
185+
cls.guard(motor)
186+
async with MotorRepository(motor) as motor_repo:
193187
await motor_repo.update_motor_by_id(motor_id)
194188
except PyMongoError as e:
195189
logger.error(f"controllers.motor.update_motor: PyMongoError {e}")

lib/routes/motor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def create_motor(motor: Motor, motor_kind: MotorKinds) -> MotorCreated:
3838
"""
3939
with tracer.start_as_current_span("create_motor"):
4040
motor.set_motor_kind(motor_kind)
41-
return await MotorController(motor).create_motor()
41+
return await MotorController.create_motor(motor)
4242

4343

4444
@router.get("/{motor_id}")
@@ -68,11 +68,11 @@ async def update_motor(
6868
"""
6969
with tracer.start_as_current_span("update_motor"):
7070
motor.set_motor_kind(motor_kind)
71-
return await MotorController(motor).update_motor_by_id(motor_id)
71+
return await MotorController.update_motor_by_id(motor_id, motor)
7272

7373

7474
@router.get(
75-
"/rocketpy/{motor_id}",
75+
"/{motor_id}/rocketpy",
7676
responses={
7777
203: {
7878
"description": "Binary file download",

lib/views/environment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional, Any
22
from datetime import datetime, timedelta
3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, ConfigDict
44
from lib.models.environment import AtmosphericModelTypes
55
from lib.utils import to_python_primitive
66

@@ -49,8 +49,9 @@ class EnvSummary(BaseModel):
4949
geodesic_to_utm: Optional[Any] = None
5050
utm_to_geodesic: Optional[Any] = None
5151

52-
class Config:
53-
json_encoders = {Any: to_python_primitive}
52+
model_config = ConfigDict(
53+
json_encoders={Any: to_python_primitive}
54+
)
5455

5556

5657
class EnvCreated(BaseModel):

lib/views/flight.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Optional, Any
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, ConfigDict
33
from lib.models.flight import Flight
44
from lib.views.rocket import RocketView, RocketSummary
55
from lib.views.environment import EnvSummary
@@ -151,8 +151,9 @@ class FlightSummary(RocketSummary, EnvSummary):
151151
z_impact: Optional[Any] = None
152152
flight_phases: Optional[Any] = None
153153

154-
class Config:
155-
json_encoders = {Any: to_python_primitive}
154+
model_config = ConfigDict(
155+
json_encoders={Any: to_python_primitive}
156+
)
156157

157158

158159
class FlightCreated(BaseModel):

lib/views/motor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Any, Optional
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, ConfigDict
33
from lib.models.motor import Motor, MotorKinds, CoordinateSystemOrientation
44
from lib.utils import to_python_primitive
55

@@ -69,8 +69,9 @@ class MotorSummary(BaseModel):
6969
total_mass_flow_rate: Optional[Any] = None
7070
thrust: Optional[Any] = None
7171

72-
class Config:
73-
json_encoders = {Any: to_python_primitive}
72+
model_config = ConfigDict(
73+
json_encoders={Any: to_python_primitive}
74+
)
7475

7576

7677
class MotorCreated(BaseModel):

lib/views/rocket.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Any, Optional
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, ConfigDict
33
from lib.models.rocket import Rocket, CoordinateSystemOrientation
44
from lib.views.motor import MotorView, MotorSummary
55
from lib.utils import to_python_primitive
@@ -38,8 +38,9 @@ class RocketSummary(MotorSummary):
3838
thrust_to_weight: Optional[Any] = None
3939
total_lift_coeff_der: Optional[Any] = None
4040

41-
class Config:
42-
json_encoders = {Any: to_python_primitive}
41+
model_config = ConfigDict(
42+
json_encoders={Any: to_python_primitive}
43+
)
4344

4445

4546
class RocketCreated(BaseModel):

0 commit comments

Comments
 (0)