class CategoryTest(unittest.TestCase, Users): """ Class performing unit testing for class Recipe""" def setUp(self): """Defining setUp() method that runs prior to each test.""" self.newCat = Categories() self.newCat.category_register("category", "*****@*****.**") self.newCat.category_edit("category", "category_one", "*****@*****.**") app.config['TESTING'] = True self.test_app = app.test_client() def test_category_register_route(self): """ Test to check if category register route works""" response = self.test_app.get('/cat_register') self.assertEqual(response.status_code, 200) def test_view_category_route(self): """ Test to check if view category route works""" response = self.test_app.get('/view_category/Lunch') self.assertEqual(response.status_code, 200) def test_category_registration(self): """ Test to check succesful category creation""" category_registration = self.newCat.category_register( "category_one", "*****@*****.**") self.assertEqual("Successfully created category", category_registration) def test_category_exists(self): """ Test to check if category_name exists """ category_exists = self.newCat.category_register( "category", "*****@*****.**") self.assertEqual("Category exists", category_exists) def test_null_category(self): """ Test to test creation of a null category name""" category_registration = self.newCat.category_register( "", "*****@*****.**") self.assertEqual("Category name is null", category_registration) def test_edit_category_route(self): """ Test to check if view category route works""" response = self.test_app.get('/category_edit/Lunch') self.assertEqual(response.status_code, 200) def test_delete_category_route(self): """ Test to check if view category route works""" response = self.test_app.get('/category_delete') self.assertEqual(response.status_code, 200) def test_invalid_category_name(self): """Test to check if category_name follows the one specified by regex""" category_registration = self.newCat.category_register( "&#*", "*****@*****.**") self.assertEqual("category name has special characters", category_registration) def test_update_category_regex(self): """ Test for category name regex pattern name on update """ category_check_regex = self.newCat.category_edit( "category_one", "@@@", "mwaz") self.assertIn("category name has special characters", category_check_regex) def test_update_category_exists(self): """ Test for invalid category name on update """ category_exists = self.newCat.category_edit("categoryone", "category", "mwaz") self.assertEqual("category name exists", category_exists)
class RecipeTest(unittest.TestCase, Categories): """ Class performing unit testing for class Recipe""" def setUp(self): """Defining setUp() method that runs prior to each test.""" self.newRecipe = Recipe() self.newCategory = Categories() self.recipe_register = self.newRecipe.recipe_register( "category", "recipe", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.newCategory.category_register("category_one", "*****@*****.**") app.config['TESTING'] = True self.test_app = app.test_client() def test_recipe_register_route(self): """ Test to check if recipe register route works""" response = self.test_app.get('/recipe_register') self.assertEqual(response.status_code, 200) def test_recipe_registration(self): """ Test for method create recipe """ recipe_success_registration = self.newRecipe.recipe_register( "category_one", "recipee", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.assertEqual("successfully created recipe", recipe_success_registration) def test_recipe_regex_match(self): """ Test for recipe name regex match """ recipe_name_regex_format = self.newRecipe.recipe_register( "category", "@@@", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.assertEqual("Recipe name has special characters", recipe_name_regex_format) def test_recipe_null_name(self): """ Test for null recipe name """ recipe_null_name = self.newRecipe.recipe_register( "category", "", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.assertEqual("Null recipe name", recipe_null_name) def test_recipe_null_ingredients(self): """ Test for null recipe ingredients """ recipe_null_ingredients = self.newRecipe.recipe_register( "category", "recipe_name", "*****@*****.**", "", "recipe_methods") self.assertEqual("Null recipe ingredients", recipe_null_ingredients) def test_recipe_null_methods(self): """ Test for null recipe preparation methods """ recipe_null_methods = self.newRecipe.recipe_register( "category", "recipe_name", "*****@*****.**", "recipe_ingredients", "") self.assertEqual("Null recipe method", recipe_null_methods) def test_recipe_exists(self): """ Test for method if recipe exists """ recipe_exists = self.newRecipe.recipe_register("category", "recipe", "*****@*****.**", "recipe_ingredients", "recipe_methods") self.assertEqual("Recipe exists", recipe_exists) def test_recipe_edit_route(self): """ Test to check if recipe edit route works""" response = self.test_app.get('/recipe_edit/Panckakes') self.assertEqual(response.status_code, 200) def test_edit_recipe_regex_format(self): """ Test for recipe name regex pattern name on update """ edit_recipe_regex = self.newRecipe.recipe_edit("@@@", "recipe_name", "category_one", "mwaz", "recipe_ingredients", "recipe_methods") self.assertEqual("Recipe name has special characters", edit_recipe_regex) def test_edit_recipe_is_null(self): """ Test for null recipe name on update """ recipe_edit_is_null = self.newRecipe.recipe_edit( "", "categoryone", "recipe_name", "mwaz", "recipe_ingredients", "recipe_methods") self.assertEqual("Null recipe name", recipe_edit_is_null) def succss_recipe_name_edit(self): """ Test for successful recipe name on update """ recipe_edit_success = self.newRecipe.recipe_edit( "new_recipe", "categoryone", "recipe_name", "mwaz", "recipe_ingredients", "recipe_methods") self.assertEqual("Successfully edited recipe", recipe_edit_success) def test_recipe_delete_route(self): """ Test to check if recipe delete route works""" response = self.test_app.get('/recipe_delete') self.assertEqual(response.status_code, 200)