def test_add_wait_info_false(self): """Tests adding wait info to a restaurant's dictionary with no matching wait info from database.""" restaurant_mock = {"id": "little-star-pizza-san-francisco", "name": "Little Star Pizza"} add_wait_info(restaurant_mock) self.assertEqual(restaurant_mock["quoted_wait_time"], "Not available") self.assertEqual(restaurant_mock["timestamp_value"], datetime(2000, 2, 2))
def test_add_wait_info_null(self): """Tests adding wait info with null values from database to a matching restaurant's dictionary.""" new_wait = WaitTime(yelp_id="ryokos-san-francisco", quoted_minutes=120, timestamp=datetime(2016, 3, 2, 1, 27, 53, 200319)) db.session.add(new_wait) db.session.commit() restaurant_mock = {"id": "ryokos-san-francisco", "name": "Ryoko's"} add_wait_info(restaurant_mock) self.assertEqual(restaurant_mock["party_size"], "N/A") self.assertEqual(restaurant_mock["parties_ahead"], "N/A")
def display_search_results(): """Display search results.""" search_term = request.args.get("keyword") location_term = request.args.get("location") if not location_term: location_term = "San Francisco" # Yelp API call with user input values search_results = yelp.search_query(term=search_term, location=location_term, category_filter="food,restaurants", limit=10) # result is the list of restaurant dictionaries result = search_results['businesses'] # For each restaurant, add its open status and wait time info to their dictionary for restaurant in result: add_open_status(restaurant) add_wait_info(restaurant) # Handle sorting sort_value = request.args.get("sort_by") result = sorted_result(result, sort_value) # Handle filtering selected_filters = request.args.getlist("filter_by") result = filtered_result(result, selected_filters) # Add result to result_dict, which will be converted to a JSON through Jinja result_dict = {'result': result} return render_template("results.html", result=result, key=BROWSER_KEY, result_dict=result_dict, search_term=search_term, location_term=location_term)
def test_add_wait_info_multiple(self): """Tests adding the most recent wait info to a restaurant's dictionary for multiple matches in the database.""" wait1 = WaitTime(yelp_id="ryokos-san-francisco", party_size=3, parties_ahead=10, quoted_minutes=120, timestamp=datetime(2016, 3, 2, 1, 27, 53, 200319)) wait2 = WaitTime(yelp_id="ryokos-san-francisco", party_size=4, parties_ahead=2, quoted_minutes=60, timestamp=datetime(2016, 3, 1, 1, 26, 00, 200319)) db.session.add_all([wait1, wait2]) db.session.commit() restaurant_mock = {"id": "ryokos-san-francisco", "name": "Ryoko's"} add_wait_info(restaurant_mock) self.assertEqual(restaurant_mock["quoted_wait_time"], 120) self.assertEqual(restaurant_mock["timestamp_value"], datetime(2016, 3, 2, 1, 27, 53, 200319))