def test_saving_recipe_general_info(self): recipeSaver = RecipeDAL(**self.config) recipe = Recipe(self.testData["bakedChickenThighs"]) recipeSaver.saveNewRecipeGeneralInfo(recipe) self.sqlConnection = pymysql.connect(**self.config) with self.sqlConnection.cursor() as cursor: cursor.execute('select * from recipes where title=%s', (self.testData["bakedChickenThighs"]["title"])) self.result = cursor.fetchone() self.sqlConnection.close() self.assertTrue(self.result['title'], self.testData["bakedChickenThighs"]["title"])
def test_savingRecipe(self): self.recipeDAL = RecipeDAL(**self.config) self.recipeParserFactory = ParserFactory() self.webRequestorFactory = WebRequestorFactory() self.recipeSaverService = RecipeSaverService(self.recipeDAL, self.recipeParserFactory, self.webRequestorFactory) result = self.recipeSaverService.saveRecipe( 'https://www.allrecipes.com/recipe/10813/best-chocolate-chip-cookies/' ) recipe = result['recipe'] self.assertFalse(result['isError']) for ing in recipe['ingredients']: self.assertTrue(ing in self.testData["ingredients"], True) counter = 0 for dire in recipe['directions']: self.assertTrue(dire, self.testData["directions"][counter]) counter += 1 self.assertTrue(self.testData["recipeTitle"], recipe['title']) self.assertTrue(self.testData["cookTime"], recipe['cookTime']) self.assertTrue(self.testData["prepTime"], recipe['prepTime']) self.assertTrue(self.testData["totalTime"], recipe['totalTime']) ## needs to be fixed for key, amount in self.testData["nutritionFacts"].items(): self.assertTrue(recipe["nutritionFacts"][key][0], amount)
def test_searchingForRecipesWithEmptyList(self): recipeDAL = RecipeDAL(**self.config) recipeSearchService = RecipeSearchService(recipeDAL) result = recipeSearchService.searchRecipesByTitle('xz') self.assertEqual(result['isError'], False) self.assertEqual(len(result['result']), 0)
def test_searchingForRecipesWithChInIt(self): recipeDAL = RecipeDAL(**self.config) recipeSearchService = RecipeSearchService(recipeDAL) result = recipeSearchService.searchRecipesByTitle('Ch') self.assertEqual(result['isError'], False) self.assertEqual(any(title['title'] in 'Crispy and Tender Baked Chicken Thighs' for title in result['result']), True)
def createRecipeDAL(cls): ## read json db file with open(os.path.join(os.path.dirname(__file__), 'DbConfig.json'), 'r') as testData: config = testData.read() cls.config = json.loads(config) ## add cursosr class cls.config["cursorclass"] = pymysql.cursors.DictCursor ## return instance of the recipeDAL layer cls.recipeDal = RecipeDAL(**cls.config) return cls.recipeDal
def getFullRecipe(): dalRunner = DALRunner() recipeSaver = RecipeDAL(**dalRunner.config) result = recipeSaver.getFullRecipeByTitle("Best Chocolate Chip Cookies") print(result)
def getDirections(): dalRunner = DALRunner() recipeSaver = RecipeDAL(**dalRunner.config) result = recipeSaver.getRecipeDirectionsByRecipeId(20) print(result)
def getIngredients(): dalRunner = DALRunner() recipeSaver = RecipeDAL(**dalRunner.config) result = recipeSaver.getRecipeIngredientsByRecipeId(20) print(result)
def getGeneralInfo(): dalRunner = DALRunner() recipeSaver = RecipeDAL(**dalRunner.config) result = recipeSaver.getRecipeGeneralByTitle("Best Chocolate Chip Cookies") print(result)
def saveRecipe(): dalRunner = DALRunner() recipeSaver = RecipeDAL(**dalRunner.config) recipeSaver.saveNewRecipe(dalRunner.testData["chocolateChipCookies"])