class TestCategory(unittest.TestCase): """ These are tests for Category methods. The Category methods are; 1. Add recipe 2. Edit recipe 3. Delete recipe """ def setUp(self): """ Sets up tests Category object : Category(categorytitle, categorydescription) The constructor of the Category class is; self.categorytitle = categorytitle self.categorydescription = categorydescription """ self.sample_category = Category('Kenyan dishes', 'Dishes made in Kenya') def test_add_recipe(self): """ Test whether a recipe has been saved """ before_add = len(self.sample_category.recipes) self.sample_category.add_recipe('chapati', 'round brown and good') after_add = len(self.sample_category.recipes) self.assertEqual(after_add - before_add, 1) def test_edit_recipe(self): """ Test whether an recipe has been edited """ id = self.sample_category.add_recipe('not chapati', 'not round or brown or good') self.sample_category.edit_recipe(id, 'chapati', 'round brown and good') recipe = self.sample_category.recipes[id] self.assertEqual(recipe.recipetitle, 'chapati') def test_delete_recipe(self): """Test whether a recipe has been deleted""" id = self.sample_category.add_recipe('not chapati', 'not round or brown or good') size_before = len(self.sample_category.recipes) self.sample_category.delete_recipe(id) size_after = len(self.sample_category.recipes) self.assertTrue(size_before - size_after, 1)