Exemple #1
0
    def test_create_recipe(self):
        recipe = Recipe()
        recipe.title = 'Recipechik'
        recipe.text = 'Some text'
        recipe.timestamp = timezone.now()

        recipe.save()

        all_recipes = Recipe.objects.all()
        the_recipe = Recipe.objects.get(id=recipe.id)
        self.assertEqual(the_recipe.text, recipe.text)
    def test_creating_a_new_recipe(self):
        # Create a new recipe object with its recipe.

        recipe = Recipe()
        recipe.title = "What's up?"
        recipe.description = "This is a goldarn recipe."
        recipe.author = UserFactory.create()
        recipe.created = timezone.now()

        # Check if we can save it to the db
        recipe.save()

        # Now check if we can find it in the db again
        all_recipes_in_db = Recipe.objects.all()
        self.assertEqual(len(all_recipes_in_db), 1)
        only_recipe_in_db = all_recipes_in_db[0]
        self.assertEqual(only_recipe_in_db, recipe)

        # And check that it has saved its two attrbs, question and pub_date
        self.assertEqual(only_recipe_in_db.title, recipe.title)
        self.assertEqual(only_recipe_in_db.description, recipe.description)