def deploy(): """Run deployment tasks.""" # migrate database to latest revision upgrade() # Insert fake data mock.everything() Restaurant.force_index()
def test_check_restaurant_ownership(client, db): helpers.create_operator(client) op1 = db.session.query(Operator).filter_by(id=1).first() helpers.create_operator2(client, helpers.operator3) op2 = db.session.query(Operator).filter_by(id=2).first() new_restaurant = Restaurant(**helpers.restaurant) new_restaurant.operator_id = op1.id restaurant.add_new_restaurant(new_restaurant) res = restaurant.check_restaurant_ownership(op1.id, new_restaurant.id) assert res == True res = restaurant.check_restaurant_ownership(op2.id, new_restaurant.id) assert res == False
def _restaurants(message=""): session.pop("previous_search", "") if request.args.get("q"): query = request.args.get("q") session["previous_search"] = query results, total = Restaurant.search(query, 1, 20) allrestaurants = results.all() logger.info(f"Searching for {query}") else: allrestaurants = db.session.query(Restaurant) restaurants = [res.__dict__ for res in allrestaurants] images_path_dict = {} for el in restaurants: # print(el) path = "./monolith/static/uploads/" + str(el["id"]) photos_paths = os.listdir(path) # gets only the first one if photos_paths: el["path"] = os.path.basename(photos_paths[0]) return render_template( "restaurants.html", message=message, restaurants=restaurants, paths=images_path_dict, base_url=request.base_url, operator_restaurants=False, )
def restaurant(): q = db.session.query(Restaurant).filter(Restaurant.id == 1) restaurant = q.first() if restaurant is None: db.session.add( Restaurant( name="Spaghetteria L'Archetto", phone=555123456, lat=43.720586, lon=10.408347, operator_id=1, time_of_stay=30, cuisine_type="ETHNIC", opening_hours=12, closing_hours=24, )) db.session.add( Restaurant( name="Pizzeria Italia dal 1987", phone=555123456, lat=44.720586, lon=10.408347, operator_id=1, time_of_stay=90, cuisine_type="FAST_FOOD", opening_hours=0, closing_hours=24, )) db.session.add( Restaurant( name="Ristorante Pizzeria Golfo di Napoli", phone=555123456, lat=43.720586, lon=9.408347, operator_id=1, time_of_stay=180, cuisine_type="PUB", opening_hours=19, closing_hours=5, )) db.session.commit()
def test_already_added_restaurant(client, db): helpers.create_operator(client) op = db.session.query(Operator).filter_by(id=1).first() new_restaurant1 = Restaurant(**helpers.restaurant) new_restaurant2 = Restaurant( name="Trattoria da Luca", phone=651981916, lat=40.720586, lon=10.10, time_of_stay=30, operator_id=op.id, ) restaurant.add_new_restaurant(new_restaurant1) res = restaurant.add_new_restaurant(new_restaurant2) assert res == False assert ( db.session.query(Restaurant).filter_by(name=new_restaurant2.name).first() is None )
def test_add_new_table(client, db): helpers.create_operator(client) new_restaurant = Restaurant(**helpers.restaurant) restaurant.add_new_restaurant(new_restaurant) new_table = Table(**helpers.table) res = restaurant.check_table_existence(new_table) assert res == False res = restaurant.add_new_table(new_table) assert res == True res = restaurant.check_table_existence(new_table) assert res == True assert db.session.query(Table).filter_by(name=new_table.name).first() is not None
def create_restaurant(): status = 200 form = CreateRestaurantForm() if request.method == "POST": if form.validate_on_submit(): new_restaurant = Restaurant() form.populate_obj(new_restaurant) new_restaurant.operator_id = current_user.id if restaurant.add_new_restaurant( new_restaurant, request.form.getlist("prec_measures")): os.makedirs("./monolith/static/uploads/" + str(new_restaurant.id), exist_ok=True) return redirect("/restaurants/mine") else: flash("Restaurant already added", category="error") status = 400 else: status = 400 return render_template("create_restaurant.html", form=form), status
def test_delete_table_successful(client, db): helpers.create_operator(client) new_restaurant = Restaurant(**helpers.restaurant) restaurant.add_new_restaurant(new_restaurant) new_table = Table(**helpers.table) restaurant.add_new_table(new_table) table_to_delete = Table(**helpers.table) table_to_delete.id = 1 res = restaurant.delete_table(table_to_delete) assert res == True assert db.session.query(Table).filter_by(name=new_table.id).first() is None
def test_add_new_restaurant(client, db): helpers.create_operator(client) new_restaurant = Restaurant(**helpers.restaurant) helpers.insert_precautions(db) res = restaurant.add_new_restaurant(new_restaurant, [1, 2]) q_rest = db.session.query(Restaurant).filter_by(name=new_restaurant.name).first() q_restprec = ( db.session.query(RestaurantsPrecautions) .filter_by(restaurant_id=new_restaurant.id) .first() ) assert res == True assert q_rest is not None assert q_restprec is not None
def test_edit_table_unsuccessful(client, db): helpers.create_operator(client) new_restaurant = Restaurant(**helpers.restaurant) restaurant.add_new_restaurant(new_restaurant) new_table = Table(**helpers.table) restaurant.add_new_table(new_table) restaurant.add_new_table(Table(name="A8", seats=5, restaurant_id=1)) res = restaurant.edit_table(Table(id=1, name="A8", seats=1, restaurant_id=1)) fetched_table = db.session.query(Table).filter_by(id=1).first() assert res == False assert fetched_table.name == "A10" assert fetched_table.seats == 10
def test_already_added_table(client, db): helpers.create_operator(client) new_restaurant = Restaurant(**helpers.restaurant) restaurant.add_new_restaurant(new_restaurant) new_table1 = Table(**helpers.table) restaurant.add_new_table(new_table1) new_table2 = Table(name="A10", seats=5, restaurant_id=new_restaurant.id) res = restaurant.add_new_table(new_table2) assert res == False assert ( db.session.query(Table) .filter_by(name=new_table2.name, seats=new_table2.seats) .first() is None )
def insert_restaurant_db(db, data=restaurant) -> Restaurant: temp = Restaurant(**data) db.session.add(temp) db.session.commit() return temp