Пример #1
0
 def test_search_without_result(self):
     with self.assertRaises(KeyError) :
         """
         Test the search engine , with no results
         context['recipe'] raise a NoKeyError
         """
         util.create_test_recipe()
         self.client.login(username='******', password='******')
         response = self.client.post(reverse('cooking:recipe_search'),{'recipe_search' : 'Crumble'})
         self.assertEqual(response.status_code, 200)
         self.assertFalse(response.context['recipes'])
Пример #2
0
    def test_index_with_latest_recipes(self):
        """
        Test the recipes_index view when a recipe is found in latest_recipes (>=1 recipe in database)
        :return:
        """

        util.create_test_recipe()
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('cooking:recipes_index'))
        self.assertEqual(response.status_code, 200)
        self.assertQuerysetEqual(response.context['latest_recipes'], ['<Recipe: Tarte Tatin>'])
Пример #3
0
 def test_create_recipe(self):
     """
     Test the creation of a recipe
     :return:
     """
     util.create_test_recipe()
     new_recipe = Recipe.objects.get(name='Tarte Tatin')
     self.assertTrue(new_recipe.id is not None)
     self.assertTrue(new_recipe.global_time == 55)
     self.assertTrue(new_recipe.preparation_time == 15)
     self.assertTrue(new_recipe.costs == 1)
     self.assertTrue(new_recipe.user_mod == 'user_test')
     self.assertTrue(new_recipe.num_people == 6)
Пример #4
0
    def test_search_with_result(self):
        with self.assertRaises(KeyError) :
            """
            Test the search engine with results
            context['info_message'] raise a KeyError
            :return:
            """

            util.create_test_recipe()
            self.client.login(username='******', password='******')
            response = self.client.post(reverse('cooking:recipe_search'),{'recipe_search' : 'Tatin'})
            self.assertEqual(response.status_code, 200)
            self.assertQuerysetEqual(response.context['recipes'], ['<Recipe: Tarte Tatin>'])
            self.assertTrue(response.context['latest_recipes'])
            self.assertFalse(response.context['info_messages'])
Пример #5
0
 def test_delete_recipe(self):
     with self.assertRaises(ObjectDoesNotExist):
         """
         Delete a recipe and check if it is not anymore in the DB
         :return:
         """
         recipe = util.create_test_recipe()
         recipe_id = recipe.id
         recipe.delete()
         deleted_recipe = Recipe.objects.get(pk=recipe_id)
Пример #6
0
 def test_update_recipe(self):
     """
     Update a recipe, save it and test if the changes were done.
     :return:
     """
     recipe = util.create_test_recipe()
     old_recipe_id = recipe.id
     old_recipe_global_time = recipe.global_time
     recipe.global_time = 60
     recipe.save()
     new_recipe = Recipe.objects.get(name='Tarte Tatin')
     self.assertTrue(old_recipe_id == new_recipe.id)
     self.assertFalse(old_recipe_global_time == new_recipe.global_time)