def test_convert_to_e164_period(self): """Tests phone number conversion with periods.""" self.assertEqual(convert_to_e164("423.543.2224"), u'+14235432224')
def test_convert_to_e164_dash(self): """Tests phone number conversion with dashes.""" self.assertEqual(convert_to_e164("423-543-2224"), u'+14235432224')
def test_convert_to_e164_plus(self): """Tests phone number conversion with plus sign.""" self.assertEqual(convert_to_e164("+14235432224"), u'+14235432224')
def test_convert_to_e164_parens(self): """Tests phone number conversion with parens.""" self.assertEqual(convert_to_e164("(423)543-2224)"), u'+14235432224')
def test_convert_to_e164_dash(self): """Test phone number conversion with -""" self.assertEqual(convert_to_e164('123-456-7890'), u'+1234567890')
def test_convert_to_e164(self): """Tests phone number conversion.""" self.assertEqual(convert_to_e164("4235432224"), u'+14235432224')
def test_convert_to_e164_parens(self): """Test phone number conversion with ()""" self.assertEqual(convert_to_e164('(123)456-7890'), u'+1234567890')
def test_convert_to_e164_plus(self): """Test phone number conversion with + sign""" self.assertEqual(convert_to_e164('+1234567890'), u'+1234567890')
def test_convert_to_e164(self): """Test phone number conversion""" self.assertEqual(convert_to_e164('1234567890'), u'+1234567890')
def test_convert_to_e164_period(self): """Test phone number conversion with .""" self.assertEqual(convert_to_e164('123.456.7890'), u'+1234567890')
def test_convert_to_e164_empty(self): """Tests phone number conversion for an empty string.""" self.assertEqual(convert_to_e164(""), None)
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("/")