def test_wh_save_and_load(): name = "test_warehouse_%s" % time.time() config_url = REMOTE_CONFIG_URL wh = Warehouse(config=config_url) wh_id = wh.save(name, config_url, meta=dict(test=1)) wh = Warehouse.load(wh_id) assert wh.name == name Warehouse.delete(wh_id)
def init_warehouse_data(db: Session) -> None: whs_json_file = os.getenv("INITIAL_WAREHOUSES_FILE", None) if not whs_json_file: print("#### No INITIAL_WAREHOUSES_FILE set") return print(f"#### Adding Initial Warehouses from {whs_json_file}") whs = json.loads(read_filepath_or_buffer(whs_json_file)) engine = db.get_bind() for wh in whs: print("Adding Warehouse...") print(wh) engine.execute( Warehouses.insert(), id=wh["id"], name=wh["name"], params=json.dumps(wh["params"]), meta=None, ) # Load to make sure any required data syncs occur before app start Warehouse.load(wh["id"])
def get_warehouses() -> Dict[str, Any]: """NOTE: this assumes Zillion Web DB is same as Zillion DB""" global warehouses if warehouses: # TODO: cache control? return warehouses print("Building warehouses...") db = SessionLocal() try: result = db.query(Warehouses).all() for row in result: warehouses[row.id] = Warehouse.load(row.id) pp(warehouses) return warehouses finally: db.close()