def test_list_cart(self): assert ( models.Cart.query_by_host("1.1.1.1") is None ) # this doesn't match the menu query... this is why we do TDD! db_seed.seed() test_item = models.MenuItem.query_by_id(1) assert test_item.cart_id is None models.Cart.add_item("1.1.1.1", test_item) assert len(models.Cart.query_by_host("1.1.1.1").items) == 1 assert test_item.cart_id == "1.1.1.1"
def test_get_image(self): assert models.Image.get_image(0) is None db_seed.seed() m = models.Image.get_image(1) assert all([m.id, m.data])
def test_add_cart_success(self): db_seed.seed() models.Cart.add_item("1.1.1.1", models.MenuItem.query_by_id(1))
def test_menu_query_by_id(self): assert models.MenuItem.query_by_id(1) is None db_seed.seed() assert models.MenuItem.query_by_id(1) is not None
def test_menu_query(self): assert len([_.serialize() for _ in models.MenuItem.query_all() if _]) == 0 db_seed.seed() assert len([_.serialize() for _ in models.MenuItem.query_all() if _ ]) >= len(db_seed.menu_start_raw)
from openapi_server import encoder from flask_cors import CORS from openapi_server.database import models from openapi_server.database import db_seed app = connexion.App(__name__, specification_dir="./openapi/") app.app.json_encoder = encoder.JSONEncoder # app.app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL", "postgresql:///test-cfd") app.app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv( "DATABASE_URI", "sqlite:///:memory:") # can this work if there's no db to connect to? app.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.add_api("openapi.yaml", arguments={"title": "CFD"}, pythonic_params=True) CORS(app.app) models.db.init_app(app.app) # Seed the database if we're running with an in memory-db if "memory" in app.app.config.get("SQLALCHEMY_DATABASE_URI"): app.app.app_context().push() models.db.create_all() db_seed.seed() def main(): app.run(port=8080, debug=True) if __name__ == "__main__": main()