Beispiel #1
0
    def test_filtered_result_by_open_now(self):
        """Tests returning filtered result by open now status."""

        result = [{"id": "ryokos-san-francisco", "open_now": "Closed"},
                  {"id": "saru-sushi-bar-san-francisco", "open_now": "Open now"}]
        result_filtered = filtered_result(result, ["open_now"])

        self.assertIn({"id": "saru-sushi-bar-san-francisco", "open_now": "Open now"}, result_filtered)
        self.assertNotIn({"id": "ryokos-san-francisco", "open_now": "Closed"}, result_filtered)
Beispiel #2
0
    def test_filtered_result_with_multiple(self):
        """Tests returning filtered result with multiple filters."""

        result = [{"id": "sanraku-san-francisco-2", "quoted_wait_time": 10, "open_now": "Closed"},
                  {"id": "saru-sushi-bar-san-francisco", "quoted_wait_time": 60, "open_now": "Open now"},
                  {"id": "ryokos-san-francisco", "quoted_wait_time": 120, "open_now": "Closed"}]
        result_filtered = filtered_result(result, ["open_now", "60_min_wait"])

        self.assertIn({"id": "saru-sushi-bar-san-francisco", "quoted_wait_time": 60, "open_now": "Open now"}, result_filtered)
        self.assertNotIn({"id": "sanraku-san-francisco-2", "quoted_wait_time": 10, "open_now": "Closed"}, result_filtered)
        self.assertNotIn({"id": "ryokos-san-francisco", "quoted_wait_time": 120, "open_now": "Closed"}, result_filtered)
Beispiel #3
0
    def test_filtered_result_by_60_min_wait(self):
        """Tests returning filtered result by <=60 min wait."""

        result = [{"id": "sanraku-san-francisco-2", "quoted_wait_time": 10},
                  {"id": "saru-sushi-bar-san-francisco", "quoted_wait_time": 60},
                  {"id": "ryokos-san-francisco", "quoted_wait_time": 120}]
        result_filtered = filtered_result(result, ["60_min_wait"])

        self.assertIn({"id": "sanraku-san-francisco-2", "quoted_wait_time": 10}, result_filtered)
        self.assertIn({"id": "saru-sushi-bar-san-francisco", "quoted_wait_time": 60}, result_filtered)
        self.assertNotIn({"id": "ryokos-san-francisco", "quoted_wait_time": 120}, result_filtered)
Beispiel #4
0
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)