def test_reduce_location_list_no_reduce(self): distance = 29 location_list = [{'city': 'Las Vegas', 'state': 'NV', 'distance': 13}] result_list = [('Las Vegas', 'NV', 13)] self.assertTrue( reduce_location_list(distance, location_list) == result_list, "List is not reduced")
def test_reduce_location_list_is_reduced(self): distance = 100 location_list = [{'city': 'Las Vegas', 'state': 'NV', 'distance': 89}, {'city': 'this city', 'state': 'this state', 'distance': 99}, {'city': 'this city2', 'state': 'this state2', 'distance': 25}] result_list = [('Las Vegas', 'NV', 89), ('this city', 'this state', 99)] self.assertTrue( reduce_location_list(distance, location_list) == result_list, "List was reduced")
def test_reduce_location_list_is_reduced(self): distance = 100 location_list = [{ 'city': 'Las Vegas', 'state': 'NV', 'distance': 89 }, { 'city': 'this city', 'state': 'this state', 'distance': 99 }, { 'city': 'this city2', 'state': 'this state2', 'distance': 25 }] result_list = [('Las Vegas', 'NV', 89), ('this city', 'this state', 99)] self.assertTrue( reduce_location_list(distance, location_list) == result_list, "List was reduced")
def location_search(request): """ This is the search view. It calls the zip code api with the starting location of the user and the distance to search. It reduces the list to the outer 25% of the radius It also applies any filter if the user selected one and then builds the dictionary with info for the template :param request: :return: """ if request.method == 'GET': if request.user.is_authenticated(): form = LoggedInSearchForm( initial={'user_filter': request.user.customer.user_filter}) else: form = InitSearchForm() context = {'form': form} return render(request, 'index.html', context) if request.method == 'POST': if request.user.is_authenticated(): form = LoggedInSearchForm(request.POST) else: form = InitSearchForm(request.POST) if form.is_valid(): data = form.cleaned_data distance = data['distance'] zipcode = data['zip_code'] if request.user.is_authenticated(): selected_filter = data['user_filter'] is_filter = True else: selected_filter = 'None' is_filter = False location_list = call_zipcode_api(zipcode, distance) city_list = reduce_location_list(distance, location_list) city_event_list = apply_user_filter(selected_filter, city_list) city_dict_list = build_template_dict(city_event_list, request.user) city_click_list = find_user_clicked(selected_filter) if len(city_dict_list) == 0: if request.user.is_authenticated(): form = LoggedInSearchForm( initial={'user_filter': selected_filter}) else: form = InitSearchForm() context = {'form': form, 'message': 'Your search returned 0 results - ' 'please try again'} return render(request, 'index.html', context) else: context = {'city_dict': city_dict_list, 'filter': is_filter, 'selected_filter': selected_filter, 'city_click_list': city_click_list} return render(request, 'city_list.html', context) else: context = {'form': form} return render(request, 'index.html', context)