Skip to content

Commit

Permalink
implements flight route tests; bring common fixturest o toplevel conf…
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
GabrielBarberini committed Dec 7, 2024
1 parent f3e0f56 commit 1e58b4a
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 169 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
│   ├── test_motor_service.py
│   └── test_rocket_serice.py
├── test_routes
│   ├── test_environment_route.py
│   ├── test_flight_route.py
│   ├── test_motor_route.py
│   └── test_rocket_route.py
├── test_repositories
│   ├── test_environment_repo.py
│   ├── test_flight_repo.py
Expand Down
6 changes: 6 additions & 0 deletions lib/models/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class CoordinateSystemOrientation(str, Enum):


class Rocket(BaseModel):

def __eq__(self, other):
if not isinstance(other, Rocket):
return False
return self.dict() == other.dict()

# Required parameters
motor: Motor
radius: float
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ disable = """
broad-exception-caught,
raise-missing-from,
too-many-instance-attributes,
redefined-outer-name,
import-error,
too-many-arguments,
redefined-outer-name,
Expand Down
95 changes: 95 additions & 0 deletions tests/test_routes/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import json
import pytest

from lib.models.rocket import Rocket
from lib.models.motor import Motor, MotorTank, TankFluids, TankKinds
from lib.models.environment import Env


@pytest.fixture
def stub_env():
env = Env(latitude=0, longitude=0)
env_json = env.model_dump_json()
return json.loads(env_json)


@pytest.fixture
def stub_motor():
motor = Motor(
thrust_source=[[0, 0]],
burn_time=0,
nozzle_radius=0,
dry_mass=0,
dry_inertia=[0, 0, 0],
center_of_dry_mass_position=0,
)
motor_json = motor.model_dump_json()
return json.loads(motor_json)


@pytest.fixture
def stub_tank():
tank = MotorTank(
geometry=[[(0, 0), 0]],
gas=TankFluids(name='gas', density=0),
liquid=TankFluids(name='liquid', density=0),
flux_time=(0, 0),
position=0,
discretize=0,
name='tank',
)
tank_json = tank.model_dump_json()
return json.loads(tank_json)


@pytest.fixture
def stub_level_tank(stub_tank):
stub_tank.update({'tank_kind': TankKinds.LEVEL, 'liquid_height': 0})
return stub_tank


@pytest.fixture
def stub_mass_flow_tank(stub_tank):
stub_tank.update(
{
'tank_kind': TankKinds.MASS_FLOW,
'gas_mass_flow_rate_in': 0,
'gas_mass_flow_rate_out': 0,
'liquid_mass_flow_rate_in': 0,
'liquid_mass_flow_rate_out': 0,
'initial_liquid_mass': 0,
'initial_gas_mass': 0,
}
)
return stub_tank


@pytest.fixture
def stub_ullage_tank(stub_tank):
stub_tank.update({'tank_kind': TankKinds.ULLAGE, 'ullage': 0})
return stub_tank


@pytest.fixture
def stub_mass_tank(stub_tank):
stub_tank.update(
{'tank_kind': TankKinds.MASS, 'liquid_mass': 0, 'gas_mass': 0}
)
return stub_tank


@pytest.fixture
def stub_rocket(stub_motor):
rocket = Rocket(
motor=stub_motor,
radius=0,
mass=0,
motor_position=0,
center_of_mass_without_motor=0,
inertia=[0, 0, 0],
power_off_drag=[(0, 0)],
power_on_drag=[(0, 0)],
coordinate_system_orientation='TAIL_TO_NOSE',
)
rocket_json = rocket.model_dump_json()
return json.loads(rocket_json)
7 changes: 0 additions & 7 deletions tests/test_routes/test_environments_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
client = TestClient(app)


@pytest.fixture
def stub_env():
env = Env(latitude=0, longitude=0)
env_json = env.model_dump_json()
return json.loads(env_json)


@pytest.fixture
def stub_env_summary():
env_summary = EnvSummary()
Expand Down
Loading

0 comments on commit 1e58b4a

Please sign in to comment.