-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closetcooking scraper implementation and tests
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from ._abstract import AbstractScraper | ||
from ._utils import get_minutes, normalize_string | ||
|
||
|
||
class ClosetCooking(AbstractScraper): | ||
|
||
@classmethod | ||
def host(self): | ||
return 'closetcooking.com' | ||
|
||
def title(self): | ||
return normalize_string(self.soup.find('h2', {'class': 'post-title'}).get_text()) | ||
|
||
def total_time(self): | ||
return get_minutes(self.soup.find('meta', {'itemprop': 'totalTime'})) | ||
|
||
def ingredients(self): | ||
ingredients_html = self.soup.findAll('li', {'itemprop': "ingredients"}) | ||
|
||
return [ | ||
normalize_string(ingredient.get_text()) | ||
for ingredient in ingredients_html | ||
] | ||
|
||
def instructions(self): | ||
instructions_html = self.soup.findAll('li', {'itemprop': 'recipeInstructions'}) | ||
|
||
return '\n'.join([ | ||
normalize_string(instruction.get_text()) | ||
for instruction in instructions_html | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import unittest | ||
|
||
from recipe_scrapers.closetcooking import ClosetCooking | ||
|
||
|
||
class TestClosetCooking(unittest.TestCase): | ||
def setUp(self): | ||
# tests are run from tests.py | ||
with open(os.path.join( | ||
os.getcwd(), | ||
'recipe_scrapers', | ||
'tests', | ||
'test_data', | ||
'closetcooking.html' | ||
)) as file_opened: | ||
self.harvester_class = ClosetCooking(file_opened, test=True) | ||
|
||
def test_host(self): | ||
self.assertEqual( | ||
'closetcooking.com', | ||
self.harvester_class.host() | ||
) | ||
|
||
def test_title(self): | ||
self.assertEqual( | ||
self.harvester_class.title(), | ||
'Bacon Wrapped Jalapeno Popper Stuffed Chicken' | ||
) | ||
|
||
def test_total_time(self): | ||
self.assertEqual( | ||
40, | ||
self.harvester_class.total_time() | ||
) | ||
|
||
def test_ingredients(self): | ||
self.assertListEqual( | ||
[ | ||
'4 (6 ounce) chicken breasts, pounded thin', | ||
'salt and pepper to taste', | ||
'4 jalapenos, diced', | ||
'4 ounces cream cheese, room temperature', | ||
'1 cup cheddar cheese, shredded', | ||
'8 slices bacon' | ||
], | ||
self.harvester_class.ingredients() | ||
) | ||
|
||
def test_instructions(self): | ||
return self.assertEqual( | ||
'Lay the chicken flat, season both sides with salt and pepper, place 1/4 of the mixture of the jalapenos, cream cheese and cheddar on the chicken and roll them up.\nWrap each chicken breast up in 2 slices of bacon and place them in a baking dish on a wire rack.\nBake in a pre-heated 400F/200C oven until cooked, about 25-35 minutes.', | ||
self.harvester_class.instructions() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters