def test_new_booking(self): """ TEST FOR ADDING A RESERVATION test flow - Create a new customer - Create a new restaurant owner - create a new restaurant - check on Reservation (what we aspect) - erase friends from reservation - erase opening hours - erase restaurants (included the tables) - erase user """ user = create_user_on_db(randrange(100000)) rest_owner = create_user_on_db(ran=2) restaurant = create_restaurants_on_db(user_id=rest_owner.id) book = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=13), 4, "[email protected];[email protected];[email protected]", ) book2 = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=13), 6, "[email protected];[email protected];[email protected];[email protected];[email protected]", ) assert book[0] is not None assert book2[0] is not None # delete friends del_friends_of_reservation(book[0].id) del_friends_of_reservation(book2[0].id) # delete reservations del_booking_services(book[0].id) del_booking_services(book2[0].id) # delete restaurants (so also tables) del_restaurant_on_db(restaurant.id) # delete users del_user_on_db(user.id) del_user_on_db(rest_owner.id) # AT THE END THERE MUST TO BE ONLY ONE RESERVATION q = db.session.query(func.count(Reservation.id)).scalar() assert q == 1
def test_delete_booking(self): """ test for deletion """ user = create_user_on_db() rest_owner = create_user_on_db(ran=2) restaurant = create_restaurants_on_db(user_id=rest_owner.id) book = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=12), 6, "[email protected];[email protected];[email protected];[email protected];[email protected]", ) assert book[0] is not None # delete the reservation BookingServices.delete_book(book[0].id, user.id) # check how many reservations q = db.session.query(func.count(Reservation.id)).scalar() assert q == 1 # delete restaurants (so also tables) del_restaurant_on_db(restaurant.id) # delete users del_user_on_db(user.id) del_user_on_db(rest_owner.id)
def test_booking_in_past(self): """ check if i can book in the past """ """ restaurant closed """ user = create_user_on_db() rest_owner = create_user_on_db(ran=2) restaurant = create_restaurants_on_db(user_id=rest_owner.id, tables=1) book = BookingServices.book( restaurant.id, user, datetime.datetime(year=1999, month=11, day=25, hour=10), 4, "[email protected];[email protected];[email protected]", ) assert book[0] is None # delete restaurants (so also tables) del_restaurant_on_db(restaurant.id) # delete users del_user_on_db(user.id) del_user_on_db(rest_owner.id) # AT THE END THERE MUST TO BE ONLY ONE RESERVATION q = db.session.query(func.count(Reservation.id)).scalar() assert q == 1
def index(): if current_user is not None and hasattr(current_user, "id"): # check on the inputs if (request.form.get("reservation_date") is None or request.form.get("reservation_date") == ""): return render_template( "booking.html", success=False, error="You have to specify a reservation date", ) # the date and time come as string, so I have to parse them and transform them in python datetime # py_datetime = datetime.datetime.strptime( request.form.get("reservation_date"), "%d/%m/%Y %H:%M") # check on people number if (request.form.get("people_number") is None or request.form.get("people_number") == ""): return render_template("booking.html", success=False, error="You have to specify people number") people_number = int(request.form.get("people_number")) # check on restaurant_id (hidden field) if (request.form.get("restaurant_id") is None or request.form.get("restaurant_id") == ""): return render_template( "booking.html", success=False, error= "An error occured during the insertion your reservation. Please try later.", ) # CALL TO BOOK SERVICE book = BookingServices.book( request.form.get("restaurant_id"), current_user, py_datetime, people_number, request.form.get("friends"), ) if book[0] is None: return render_template("booking.html", success=False, error=book[1]) else: return render_template( "booking.html", success=True, restaurant_name=book[1], table_name=book[2], ) else: return render_template("booking.html", success=False, error="not logged in")
def test_new_booking_overlaps(self): """ overlapped reservations """ user = create_user_on_db() rest_owner = create_user_on_db(ran=2) restaurant = create_restaurants_on_db(user_id=rest_owner.id, tables=1) book = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=13), 4, "[email protected];[email protected];[email protected]", ) book2 = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=13, minute=29), 6, "[email protected];[email protected];[email protected];[email protected];[email protected]", ) assert book[0] is not None assert book2[0] is None # delete friends del_friends_of_reservation(book[0].id) # delete reservations del_booking_services(book[0].id) # delete restaurants (so also tables) del_restaurant_on_db(restaurant.id) # delete users del_user_on_db(user.id) del_user_on_db(rest_owner.id) # AT THE END THERE MUST TO BE ONLY ONE RESERVATION q = db.session.query(func.count(Reservation.id)).scalar() assert q == 1
def test_update_booking(self): """ this test insert two reservation that should be ok """ user = create_user_on_db() rest_owner = create_user_on_db(ran=2) restaurant = create_restaurants_on_db(user_id=rest_owner.id) book = BookingServices.book( restaurant.id, user, datetime.datetime(year=2120, month=11, day=25, hour=13), 4, "[email protected];[email protected];[email protected]", ) assert book[0] is not None book = BookingServices.update_book( book[0].id, user, datetime.datetime(year=2120, month=11, day=25, hour=14), 2, "*****@*****.**", ) assert book[0] is not None # delete friends del_friends_of_reservation(book[0].id) # delete reservations del_booking_services(book[0].id) # delete restaurants (so also tables) del_restaurant_on_db(restaurant.id) # delete users del_user_on_db(user.id) del_user_on_db(rest_owner.id) # AT THE END THERE MUST TO BE ONLY ONE RESERVATION q = db.session.query(func.count(Reservation.id)).scalar() assert q == 1