def test_search_from_user_input(self):
     data = {"product": "Indisches Sabji"}
     (
         substitute,
         selected_product,
     ) = ProductManager.search_from_user_input(data)
     self.assertEqual(
         substitute[0]["product_name"],
         self.data["sabji"][1]["product_name_fr"],
     )
     self.assertEqual(
         selected_product[0]["product_name"],
         self.data["sabji"][0]["product_name_fr"],
     )
Exemple #2
0
def sub_list(request):
    """Display the list of substitute for one selected product."""
    if request.method == "POST":
        form = SearchForm(request.POST)
        if form.is_valid():
            (
                substitute,
                selected_product,
            ) = ProductManager.search_from_user_input(form.cleaned_data)
            return render(
                request,
                "products/sub_list.html",
                {"product": substitute, "searched": selected_product},
            )
        else:
            print("form is not valid !")
            raise Http404
    else:
        form = SearchForm()
    return render(request, "products/sub_list.html", {"form": form})