Skip to content

Commit 1e58b4a

Browse files
implements flight route tests; bring common fixturest o toplevel conftest
1 parent f3e0f56 commit 1e58b4a

8 files changed

+475
-169
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
9999
│   ├── test_motor_service.py
100100
│   └── test_rocket_serice.py
101101
102-
├── test_routes
103-
│   ├── test_environment_route.py
104-
│   ├── test_flight_route.py
105-
│   ├── test_motor_route.py
106-
│   └── test_rocket_route.py
107-
108102
├── test_repositories
109103
│   ├── test_environment_repo.py
110104
│   ├── test_flight_repo.py

lib/models/rocket.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class CoordinateSystemOrientation(str, Enum):
1717

1818

1919
class Rocket(BaseModel):
20+
21+
def __eq__(self, other):
22+
if not isinstance(other, Rocket):
23+
return False
24+
return self.dict() == other.dict()
25+
2026
# Required parameters
2127
motor: Motor
2228
radius: float

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ disable = """
4343
broad-exception-caught,
4444
raise-missing-from,
4545
too-many-instance-attributes,
46-
redefined-outer-name,
4746
import-error,
4847
too-many-arguments,
4948
redefined-outer-name,

tests/test_routes/conftest.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import json
2+
import pytest
3+
4+
from lib.models.rocket import Rocket
5+
from lib.models.motor import Motor, MotorTank, TankFluids, TankKinds
6+
from lib.models.environment import Env
7+
8+
9+
@pytest.fixture
10+
def stub_env():
11+
env = Env(latitude=0, longitude=0)
12+
env_json = env.model_dump_json()
13+
return json.loads(env_json)
14+
15+
16+
@pytest.fixture
17+
def stub_motor():
18+
motor = Motor(
19+
thrust_source=[[0, 0]],
20+
burn_time=0,
21+
nozzle_radius=0,
22+
dry_mass=0,
23+
dry_inertia=[0, 0, 0],
24+
center_of_dry_mass_position=0,
25+
)
26+
motor_json = motor.model_dump_json()
27+
return json.loads(motor_json)
28+
29+
30+
@pytest.fixture
31+
def stub_tank():
32+
tank = MotorTank(
33+
geometry=[[(0, 0), 0]],
34+
gas=TankFluids(name='gas', density=0),
35+
liquid=TankFluids(name='liquid', density=0),
36+
flux_time=(0, 0),
37+
position=0,
38+
discretize=0,
39+
name='tank',
40+
)
41+
tank_json = tank.model_dump_json()
42+
return json.loads(tank_json)
43+
44+
45+
@pytest.fixture
46+
def stub_level_tank(stub_tank):
47+
stub_tank.update({'tank_kind': TankKinds.LEVEL, 'liquid_height': 0})
48+
return stub_tank
49+
50+
51+
@pytest.fixture
52+
def stub_mass_flow_tank(stub_tank):
53+
stub_tank.update(
54+
{
55+
'tank_kind': TankKinds.MASS_FLOW,
56+
'gas_mass_flow_rate_in': 0,
57+
'gas_mass_flow_rate_out': 0,
58+
'liquid_mass_flow_rate_in': 0,
59+
'liquid_mass_flow_rate_out': 0,
60+
'initial_liquid_mass': 0,
61+
'initial_gas_mass': 0,
62+
}
63+
)
64+
return stub_tank
65+
66+
67+
@pytest.fixture
68+
def stub_ullage_tank(stub_tank):
69+
stub_tank.update({'tank_kind': TankKinds.ULLAGE, 'ullage': 0})
70+
return stub_tank
71+
72+
73+
@pytest.fixture
74+
def stub_mass_tank(stub_tank):
75+
stub_tank.update(
76+
{'tank_kind': TankKinds.MASS, 'liquid_mass': 0, 'gas_mass': 0}
77+
)
78+
return stub_tank
79+
80+
81+
@pytest.fixture
82+
def stub_rocket(stub_motor):
83+
rocket = Rocket(
84+
motor=stub_motor,
85+
radius=0,
86+
mass=0,
87+
motor_position=0,
88+
center_of_mass_without_motor=0,
89+
inertia=[0, 0, 0],
90+
power_off_drag=[(0, 0)],
91+
power_on_drag=[(0, 0)],
92+
coordinate_system_orientation='TAIL_TO_NOSE',
93+
)
94+
rocket_json = rocket.model_dump_json()
95+
return json.loads(rocket_json)

tests/test_routes/test_environments_route.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
client = TestClient(app)
1717

1818

19-
@pytest.fixture
20-
def stub_env():
21-
env = Env(latitude=0, longitude=0)
22-
env_json = env.model_dump_json()
23-
return json.loads(env_json)
24-
25-
2619
@pytest.fixture
2720
def stub_env_summary():
2821
env_summary = EnvSummary()

0 commit comments

Comments
 (0)