Esempio n. 1
0
def get(request):
    """ dedicated for get methods """
    template_name = 'food/search_page.html'
    query = request.GET.get('search')
    list = Food.get_substitute(query)
    if list is False:
        return render(request, template_name, {'nofood': "Pas d'aliment trouvé"})
    elif list is "error":
        return render(request, template_name, {'no_substitute': "Votre aliment n'a pas de substitut"})
    substitutes_list = list[0]
    paginator = Paginator(substitutes_list, 6)
    page = request.GET.get('page')
    substitutes_list = paginator.get_page(page)
    args = ({'food_search': list[1],
                'articles_found': substitutes_list,
                'image': list[2],
                'page': page,
                'query': query})
    return render(request, template_name, args)
Esempio n. 2
0
 def test_get_substitutes(self):
     food = Food()
     substitute_list, _, _ = food.get_substitute("test")
     self.assertEqual(len(substitute_list), 1)
Esempio n. 3
0
 def test_get_substitutes_do_not_have_substitute(self):
     """ Test to check if the classmethod
     works if there is no substitute for
     the product researched"""
     substitute_list, _, _ = Food.get_substitute("test")
     self.assertEqual(len(substitute_list), 1)
Esempio n. 4
0
 def test_get_substitute(self):
     """ Test to find a substitute"""
     substitute_list, _, _ = Food.get_substitute("test2")
     self.assertEqual(len(substitute_list), 2)
Esempio n. 5
0
 def test_get_substitutes_do_not_find_food(self):
     """ Test to check if the classmethod
     works if there is no food found"""
     food_search = Food.get_substitute("Nutella")
     self.assertEqual(food_search, False)