Skip to content

Commit

Permalink
fix import bug (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner authored Jan 12, 2025
2 parents fa1255e + 0e31fca commit 891e07b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
22 changes: 12 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ def app():
app = create_app()
with app.app_context():
dbm.Base.metadata.create_all(db.engine)
yield app
dbm.Base.metadata.drop_all(db.engine)

tenant = dbm.Tenant(
name="Default",
hostname="localhost",
)
db.session.add(tenant)
db.session.commit()
g.tenant = tenant

yield app
@pytest.fixture
def tenant(app: Flask):
tenant = dbm.Tenant(
name="Default",
hostname="localhost",
)
db.session.add(tenant)
db.session.commit()

dbm.Base.metadata.drop_all(db.engine)
return tenant


@pytest.fixture
def client(app: Flask) -> FlaskClient:
def client(app: Flask, tenant) -> FlaskClient:
return app.test_client()
25 changes: 11 additions & 14 deletions tests/test_flight.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import json

from flask import g
from flask.testing import FlaskClient
from sqlalchemy.sql import func, select

from teufa import db as dbm
from teufa.ext import db


def test_create_flight(client: FlaskClient):
def test_create_flight(client: FlaskClient, tenant: dbm.Tenant):
aircraft = dbm.Aircraft(
tenant_id=g.tenant.id,
tenant_id=tenant.id,
icao="B737",
tail_number="N12345",
range_nm=3000,
Expand Down Expand Up @@ -40,9 +37,9 @@ def test_create_flight(client: FlaskClient):
}


def test_get_flight(client: FlaskClient):
def test_get_flight(client: FlaskClient, tenant: dbm.Tenant):
aircraft = dbm.Aircraft(
tenant_id=g.tenant.id,
tenant_id=tenant.id,
icao="B737",
tail_number="N12345",
range_nm=3000,
Expand All @@ -52,7 +49,7 @@ def test_get_flight(client: FlaskClient):
db.session.add(
dbm.Flight(
id=1,
tenant_id=g.tenant.id,
tenant_id=tenant.id,
departure_icao="KDEN",
arrival_icao="KLGA",
aircraft_id=aircraft.id,
Expand Down Expand Up @@ -80,9 +77,9 @@ def test_get_flight_not_found(client: FlaskClient):
assert response.json == {"message": "Flight not found"}


def test_update_flight(client: FlaskClient):
def test_update_flight(client: FlaskClient, tenant: dbm.Tenant):
aircraft = dbm.Aircraft(
tenant_id=g.tenant.id,
tenant_id=tenant.id,
icao="B737",
tail_number="N12345",
range_nm=3000,
Expand All @@ -92,7 +89,7 @@ def test_update_flight(client: FlaskClient):
db.session.add(
dbm.Flight(
id=1,
tenant_id=g.tenant.id,
tenant_id=tenant.id,
departure_icao="KDEN",
arrival_icao="KLGA",
aircraft_id=aircraft.id,
Expand Down Expand Up @@ -137,9 +134,9 @@ def test_update_flight_not_found(client: FlaskClient):
assert response.json == {"message": "Flight not found"}


def test_delete_flight(client: FlaskClient):
def test_delete_flight(client: FlaskClient, tenant: dbm.Tenant):
aircraft = dbm.Aircraft(
tenant_id=g.tenant.id,
tenant_id=tenant.id,
icao="B737",
tail_number="N12345",
range_nm=3000,
Expand All @@ -149,7 +146,7 @@ def test_delete_flight(client: FlaskClient):
db.session.add(
dbm.Flight(
id=1,
tenant_id=g.tenant.id,
tenant_id=tenant.id,
departure_icao="KDEN",
arrival_icao="KLGA",
aircraft_id=aircraft.id,
Expand Down
2 changes: 1 addition & 1 deletion teufa/v1_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from flask_restful import Api
from sqlalchemy import select

from .. import db as dbm
from ..ext import db
from . import db as dbm
from .flights import FlightCollectionResource, FlightResource

bp = Blueprint("api", __name__, url_prefix="/api")
Expand Down

0 comments on commit 891e07b

Please sign in to comment.