def test_send_thank_you_sms_invalid_number(self): """Tests sending a thank you sms to an invalid phone number.""" self.assertEqual(send_thank_you_sms("+1231231223", "Sanraku", "15 min"), "Error")
def process_wait_time_form(): """Adds wait time information into database for a restaurant.""" restaurant_name = request.form.get("restaurant_name") location = request.form.get("location") # Yelp API call to get the corresponding yelp id for the restaurant search_results = yelp.search_query(term=restaurant_name, location=location, category_filter="food,restaurants", limit=10) # restaurant_info is a dictionary of the restaurant's info restaurant_info = search_results['businesses'][0] yelp_id = str(restaurant_info['id']) quoted_hr = int(request.form.get("quoted_hr")) quoted_min = int(request.form.get("quoted_min")) # Convert quoted wait time into one value (quoted_minutes) for the database if quoted_hr != 0: quoted_minutes = quoted_min + (quoted_hr * 60) else: quoted_minutes = quoted_min # Interval for sms timer quoted_seconds = quoted_minutes * 60 # Covert quoted wait time into string value for customized sms if quoted_hr and not quoted_min: quoted_time = "%d hr" % (quoted_hr) elif quoted_hr and quoted_min: quoted_time = "%d hr %d min" % (quoted_hr, quoted_min) elif quoted_min and not quoted_hr: quoted_time = "%d min" % (quoted_min) if request.form.get("phone_number"): raw_phone_number = str(request.form.get("phone_number")) phone_number = convert_to_e164(raw_phone_number) # Send thank you sms immediately send_thank_you_sms(phone_number, restaurant_name, quoted_time) # Send reminder sms after quoted time is up send_sms_timer = threading.Timer( quoted_seconds, send_reminder_sms, args=[phone_number, quoted_time, restaurant_name] ) send_sms_timer.start() else: phone_number = None if request.form.get("party_size"): party_size = int(request.form.get("party_size")) else: party_size = None if request.form.get("parties_ahead"): parties_ahead = int(request.form.get("parties_ahead")) else: parties_ahead = None reported_wait_info = WaitTime(yelp_id=yelp_id, party_size=party_size, parties_ahead=parties_ahead, quoted_minutes=quoted_minutes, phone_number=phone_number) db.session.add(reported_wait_info) db.session.commit() flash("Thanks for reporting your wait time!") return redirect("/")
def test_send_thank_you_sms(self): """Tests sending a thank you sms.""" self.assertEqual(send_thank_you_sms("+14235432224", "Sanraku", "15 min"), None)