From 588425cc36ebd3c511c1a045a5c17678a44c38f2 Mon Sep 17 00:00:00 2001 From: jens persson Date: Tue, 7 May 2013 18:26:45 +0200 Subject: [PATCH 1/4] Add tests for ica.se plugin --- .../tests/test_ica_se_plugin.html | 1009 +++++++++++++++++ .../tests/test_ica_se_plugin.py | 67 ++ 2 files changed, 1076 insertions(+) create mode 100644 gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.html create mode 100644 gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.py diff --git a/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.html b/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.html new file mode 100644 index 000000000..30f2b5321 --- /dev/null +++ b/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.html @@ -0,0 +1,1009 @@ + + + + + + + + + + + + + + + + + + Grillad kyckling med melon | Recept ICA.se + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+

Hej!

+
+
+

Du verkar ha en gammal webbläsare. Uppdatera för att få ut det mesta av ICA.se.

+ +
+
+
+
+
+ + + + + + +
+
+
+ +
+ + + +
+ + + + +
+
+
+
+ + + + + + + + +
+ + +
+ +
+ + + + +
+ + + +
+ + + +
+ + +
+ +
+
+ + + +
+
+ + +
    +
  • Recept
  • +
  • Medel
  • +
  • Tid: Under 45 min
  • +
  • Portioner: 6
  • +
+
+

+ Grillad kyckling med melon + +

+

Grillad kyckling med melon är en fräsch och kryddstark rätt. Chilipulver och soja ger härlig färg och smak till kycklingen och melonen är ett friskt komplement. Servera med fetostdipp.

+ +
+ + + + + +
+ + +Betyg: + + + +4 röster + +Mitt betyg: + + + + + + + +
+ + + + + +
+
+ + Recept: Grillad kyckling med melon + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+

Ingredienser

+ + + + +
+
+
+
+
+

Så här gör du

+
+
+
+
+ +
+ +

Ingredienser

+ +
    + +
  • 8 kycklinglårfiléer (à 62 g)
  • + +
  • 1/2 msk chilipulver
  • + +
  • 1 msk soja
  • + +
  • 600 g vattenmelon
  • + +
  • 1/2 påse babyspenat (à 70 g)
  • + +
  • 1/2 dl olivolja
  • + +
  • 2 krm salt
  • + +
  • 1 krm peppar
  • + +
  • 16 träspett
  • + +
+ + +
Detta recept har omvandlats ifrån orginalreceptets 6 portioner.
+ + +
+ +
+
+
+ +
+

Detta är ett recept från Buffé nr 5 2010

+
+ +
+
    +
  1. Dela varje kycklinglårfilé i 2 bitar. Blanda chilipulver och soja i en skål. Lägg ner kycklingen och blanda runt. Låt stå i kylen 30 minuter.
  2. +
  3. Skala, kärna ur och skär melon i 16 bitar (ca 3 x 3 cm). Blanda dem med olja, salt och peppar.
  4. +
  5. Grilla kycklingbitarna i en grillpanna på medelhög värme tills de fått fin färg, 3–4 minuter på varje sida. Ta upp dem och skölj ur pannan.
  6. +
  7. Grilla melonbitarna runt om på medelhög värme 3–5 minuter.
  8. +
  9. Trä upp en bit kyckling och en melonkub på träspett.
  10. +
  11. Servera på spenatbädd med fetadipp i separat skål.
  12. +
+


För alla

+

Fri från gluten, laktos, mjölkprotein och ägg.

+
+ +
+

Tips

+
+

Rätten passar bra till en buffé. Portionerna är beräknade för att passa buffébordet.

+
+
+ +
+
+
+ + +
+ +
+ + +
+ + + +
+ Visar + + 0 + av + + 0 + kommentarer.  + + Lägg till en egen  + kommentar. + Logga in. +
+ +
+ +
+
+ + + + +
+ + + + +
+
+
+
+ +
+ +
+
+
+ + + + +
+ +
+ +
+ +
+ + +
+ +
+
+ ICA +
+ + +

ICA Sverige AB, 171 93 Solna

+ +

Tel: 08-561 500 00

+ + +
+
+
+ +
+ ver: 3.0.9-112 +
+
+
+ +
+ + + + +
+ + +
+ + diff --git a/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.py b/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.py new file mode 100644 index 000000000..387e4447f --- /dev/null +++ b/gourmet/plugins/import_export/website_import_plugins/tests/test_ica_se_plugin.py @@ -0,0 +1,67 @@ +# encoding: utf-8 +import unittest +import BeautifulSoup + +from gourmet.plugins.import_export.website_import_plugins import ica_se_plugin + +class DummyImporter(object): + class WebParser(object): + pass + + +class TestIcaPlugin(unittest.TestCase): + def test_excluder(self): + url = "/src/doc/" + excluder = ica_se_plugin.Excluder(url) + + self.assertTrue(excluder.search(url+"index.html")) + self.assertTrue(excluder.search("index.html")) + self.assertFalse(excluder.search(url)) + self.assertFalse(excluder.search("http://ica.se/"+url)) + + + url = "http://www.ica.se/recept/grillad-kyckling-med-melon-712641/" + + def _read_html(self): + filename = __file__.rsplit(".", 1)[0]+".html" + return (open(filename).read()) + + def setUp(self): + self.text = self._read_html() + self.plugin = ica_se_plugin.IcaSePlugin() + + def test_url(self): + self.assertEqual(self.plugin.test_url(self.url, self.text), 5) + self.assertEqual(self.plugin.test_url("http://www.ica.se/rec", self.text), 5) + self.assertEqual(self.plugin.test_url("http://ica.se/rec", self.text), 5) + self.assertEqual(self.plugin.test_url("http://ica.com/", self.text), 0) + self.assertEqual(self.plugin.test_url("http://google.com", self.text), 0) + + def test_parse(self): + # Setup + parser = self.plugin.get_importer(DummyImporter)() + parser.soup = BeautifulSoup.BeautifulSoup(self.text, + convertEntities=BeautifulSoup.BeautifulStoneSoup.XHTML_ENTITIES, + ) + # Do the parsing + parser.preparse() + # Pick apart results + result = parser.preparsed_elements + + ingredients = [r for r in result if r[1] == "ingredients"] + name = [r for r in result if r[1] == "recipe"][0][0].text + instructions = [r for r in result if r[1] == "instructions"][0][0].text + # Check results + self.assertEqual(len(ingredients), 9) + + self.assertTrue('Grillad kyckling med melon' in name) + + print type(instructions) + self.assertTrue('Dela varje kycklinglårfilé i 2 bitar.' in instructions, + instructions) + self.assertTrue('Ta upp dem och skölj ur pannan.' in instructions) + self.assertTrue('Fri från gluten, laktos, mjölkprotein och ägg.' in instructions) + + +if __name__ == '__main__': + unittest.main() From e624a4fbee47ab3246be38ff2ee38d015a3b0979 Mon Sep 17 00:00:00 2001 From: jens persson Date: Tue, 7 May 2013 18:27:57 +0200 Subject: [PATCH 2/4] Fix buglet discovered due to tests --- .../import_export/website_import_plugins/ica_se_plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gourmet/plugins/import_export/website_import_plugins/ica_se_plugin.py b/gourmet/plugins/import_export/website_import_plugins/ica_se_plugin.py index dc7c212b9..aaebe0aa2 100644 --- a/gourmet/plugins/import_export/website_import_plugins/ica_se_plugin.py +++ b/gourmet/plugins/import_export/website_import_plugins/ica_se_plugin.py @@ -6,7 +6,7 @@ class Excluder(object): def __init__(self, url): - self.url=url + self.url = url def search(self, other_url): return not (other_url.endswith(self.url)) @@ -19,6 +19,7 @@ def test_url (self, url, data): "Is this url from ica.se" if 'ica.se' in url: return 5 + return 0 def get_importer (self, webpage_importer): From a110ecfc1694a1826db486f590ea41fe066faf5d Mon Sep 17 00:00:00 2001 From: jens persson Date: Tue, 7 May 2013 19:11:34 +0200 Subject: [PATCH 3/4] Add tests for foodnetwork plugin --- .../tests/test_foodnetwork_plugin.html | 2471 +++++++++++++++++ .../tests/test_foodnetwork_plugin.py | 61 + 2 files changed, 2532 insertions(+) create mode 100644 gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.html create mode 100644 gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.py diff --git a/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.html b/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.html new file mode 100644 index 000000000..7b550119f --- /dev/null +++ b/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.html @@ -0,0 +1,2471 @@ + + + + + Pan-Roasted Chicken with Oranges and Rosemary Recipe : Aida Mollenkamp : Recipes : Food Network + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+ + + +
+ + + + + +
+ + + +
+
+
+ + +
+
+
+
+
+
+ + + +
+ + +
+ +

Pan-Roasted Chicken with Oranges and Rosemary

+ +

Show: Episode: +

+
+ +
+ + + +
+
+
+ Picture of Pan-Roasted Chicken with Oranges and Rosemary Recipe + + 1 Video | Photo: Pan-Roasted Chicken with Oranges and Rosemary Recipe +
+
+ Rated 4 stars out of 5 +
+
    +
  • + + Rate This Recipe +
  • + +
  • Read 33 Reviews
+
+
Total Time:
+
42 min
+
Prep
+
5 min
Inactive
+
5 min
Cook
+
32 min
+
+
+
Yield:
+
6 servings
+
+
+
Level:
+
Easy
+
+
+
+
+ + + + + +
    +
  • +
  • + +
  • +
+ +
+
x
+
+

Save To My Recipe Box

+
+
+ + +
+
+ +
+

Please limit to 20 characters

+ + +
+
+

Saving Recipe

+ Adding Recipe +
+

Or Do Not Add

+
+ +
+

Success

+

This recipe was saved to your Folder_Name folder.

+

+ +
+
+
+
+ +
+
x
+
+

Save To My Recipe Box

+ + +

Please sign in to save this recipe to your Recipe Box!!

+
+ +
+
+
+ +
+ +
+ + + +
+ +
+
+
+
+

+ +
+ + + + +
+
+ +
+
+ + + + 25 Characters Max + +

Enter Time:

+
+
+ + + +
+
:
+
+ + + +
+
:
+
+ + + +
+
+
+ Start +
+ +

You can create up to five timers

+
+
+
+
+ +
+
+
+
    +
  • +
    + +
    + + + +
    +
    +
    +
  • +
  • +
    + +
    + + + +
    +
    +
    +
  • +
  • +
    + +
    + + + +
    +
    +
    +
  • +
  • +
    + +
    + + + +
    +
    +
    +
  • +
  • +
    + +
    + + + +
    +
    +
    +
  • +
+
+
+
+
+
+
+
+
+
+ +
+
+
+

Ingredients

+ +
    +
  • 5 tablespoons olive oil
  • +
  • 6 tablespoons rosemary leaves
  • +
  • 1 tablespoon kosher salt
  • +
  • 2 teaspoons red pepper flakes
  • +
  • 3/4 teaspoon freshly ground black pepper
  • +
  • 4 pounds chicken thighs and drumsticks (6 thighs and 6 drumsticks)
  • +
  • 1/2 medium orange, cut into 6 very thin slices and slices cut into half moons
  • +
  • 1 tablespoon unsalted butter
  • +
+ +

Directions

+
+

Heat oven to 450 degrees F and arrange rack in middle.

+

In a large bowl, mix together 1/4 cup of the oil, rosemary, salt, red pepper flakes, and freshly ground black pepper. Add chicken pieces and turn to coat well. Slip 1 piece of orange under skin of each piece.

+

Heat remaining 1 tablespoon olive oil and butter in a cast iron skillet or large frying pan over medium-high heat until butter foams. Working in batches, add 3 or 4 chicken pieces (don't overcrowd the pan) and brown on both sides until skin is crisp and golden, about 2 to 3 minutes per batch. As chicken is finished, place in a 13 by 9-inch baking dish.

+

Once all chicken has browned, place in oven to roast until juices run clear when pricked with a knife and meat registers 160 to 165 degrees F on an instant-read thermometer, about 20 to 25 minutes. Let rest 5 minutes before serving.

+
+ + + + +

+ Print Recipe +

+ +
+
+
+
+ + + +
+

Browse Reviews by Keywordnew!

+
+ Loading review filters... +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+
+
+
+

COMMENT ON THIS PROJECT

+
    
+
+
+
+ +
+

Sign in

+

All fields are required.

+
+
+ +
+
+

E-mail Address:

+
+
+
+
+
+

Password:

+ +
+
+
+
+
+ + +
+

Remember me on this computer

+
+ + +
+
+ + +
+
+
+
+
+ +
+
+

Signing in

+

+
+
+ + +
+
+

Please enter your email address and we will send your password

+
+
+

E-mail Address

+
+
+
+
+ +
+
+
+ +
+
+

Your password has been sent and should arrive in your mailbox very soon.

+
+
+
+ +
+
+
+
+
+
+
+
+

Not a member?

+ +

Sign up for My Food Network to share photos, show off your style, and connect to an enthusiastic and helpful community.

+ + + +

It's free and easy.

+ + +
+
+ + + +
+
+
+
+
+
+
+
+ + + + + + + + + + + +
+
+
+ + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+

Review This Recipe

+

You must be logged in to review this recipe.

+ +
+
+
+ + + + + +
+
+ + +
+ + +

Newest Ratings and Reviews

+ +

Read all 33 reviews

+ + +
+
+
+ + + + + + + + + +
    + + +
  • +
    + + + + + + + +
    + + +

    on August 11, 2012

    + +
    +
    + + + +
    +
    +
    +
    + +
    + +
    +
    +

    + + + + + +

    Flag

    + + + +
    +
    + +
    +
    +
    +
    + +
    +

    This recipe is a BIG family favorite at my house. For a more orange taste I added fresh orange juice and orange zest to the marinade. Also don't forget to add the left over marinade to the chicken before finishing it in the oven, don't want to waste a single drop of that delicious nectar!!! It turns into a type of glaze, really good on potatoes, be they roasted, mashed, or boiled! Bon Appetit fellow foodies!

    + +
    + +
    + + people found this review Helpful. + + +
    + Was this review helpful to you? + Yes | + No +
    + + +
    + + + + +
    +
    +
    + + + + +
  • + + + + +
  • +
    + + + + + + + +
    + + +

    on May 18, 2012

    + +
    +
    + + + +
    +
    +
    +
    + +
    + +
    +
    +

    + + + + + +

    Flag

    + + + +
    +
    + +
    +
    +
    +
    + +
    +

    We absolutely loved this recipe! I highly recommend it!!!

    + +
    + +
    + + people found this review Helpful. + + +
    + Was this review helpful to you? + Yes | + No +
    + + +
    + + + + +
    +
    +
    + + + + +
  • + + + + +
  • +
    + + + + + + + +
    + + +

    on March 20, 2012

    + +
    +
    + + + +
    +
    +
    +
    + +
    + +
    +
    +

    + + + + + +

    Flag

    + + + +
    +
    + +
    +
    +
    +
    + +
    +

    My family loves this recipe! I'm not really sure that I understand the negative comments, because I think the ingredients all come through wonderfully. The only change I make is that I do two slices of orange for each piece of chicken.

    The sauteed-then-baked skin is divine!

    + +
    + +
    + + people found this review Helpful. + + +
    + Was this review helpful to you? + Yes | + No +
    + + +
    + + + + +
    +
    +
    + + + + +
  • + + + + + +
+ + +
+
+ + + + + +
+ + + + + + +
+ + + + + + +
+ + + +
+ + + + + + +
+
+ +
+

Next Recipe

+ +
+ + + + +
+ +
+ Advertisement +
+ + + +
+
+

On TV

+

Full Schedule · Shows A-Z

+
+
+ +
+

What's Hot

+
+

Chopped All-Stars

Hosted by: Ted Allen
+
+
+
+
+ + + + +
+

See More Recipes Like This From Food.com

+
+
+
+
+ + + + + +
+
+
+

+ Free Recipe of the Day Newsletter +

+
+
+
+

+ Let Food Network chefs plan what's for dinner, with quick and easy recipes delivered to your inbox daily. +

+

+
+ + + + + + + +
+
+ +
+
+
+
+ + + + +
+
+

Ads by Google

+
+
+ +
+
+
+ + + +
+ +
+
+
+
+
+ + + + + + +
+
+ + + + + © 2013 Television Food Network G.P. All rights reserved. + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.py b/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.py new file mode 100644 index 000000000..80dd0c74b --- /dev/null +++ b/gourmet/plugins/import_export/website_import_plugins/tests/test_foodnetwork_plugin.py @@ -0,0 +1,61 @@ +# encoding: utf-8 +import unittest +import BeautifulSoup + +from gourmet.plugins.import_export.website_import_plugins import foodnetwork_plugin + +class DummyImporter(object): + class MenuAndAdStrippingWebParser(object): + pass + + +class TestFoodnetworkPlugin(unittest.TestCase): + + url = "http://www.foodnetwork.com/recipes/ask-aida/pan-roasted-chicken-with-oranges-and-rosemary-recipe/index.html" + + def _read_html(self): + filename = __file__.rsplit(".", 1)[0]+".html" + return (open(filename).read()) + + def setUp(self): + self.text = self._read_html() + self.plugin = foodnetwork_plugin.FoodNetworkPlugin() + + def test_url(self): + self.assertEqual(self.plugin.test_url(self.url, self.text), 5) + self.assertEqual(self.plugin.test_url("http://www.foodnetwork.com/rec", self.text), 5) + self.assertEqual(self.plugin.test_url("http://foodnetwork.com/rec", self.text), 5) + self.assertEqual(self.plugin.test_url("http://www.foodnetwork.com", self.text), 5) + self.assertEqual(self.plugin.test_url("http://www.foodnetwork.net", self.text), 0) + self.assertEqual(self.plugin.test_url("http://google.com", self.text), 0) + + def test_parse(self): + # Setup + parser = self.plugin.get_importer(DummyImporter)() + parser.soup = BeautifulSoup.BeautifulSoup(self.text, + convertEntities=BeautifulSoup.BeautifulStoneSoup.XHTML_ENTITIES, + ) + # Do the parsing + parser.preparse() + # Pick apart results + result = parser.preparsed_elements + + ingredients = [r for r in result if r[1] == "ingredients"][0][0] + ingredients = [i for i in ingredients if type(i) == BeautifulSoup.Tag] + name = [r for r in result if r[1] == "title"][0][0][0].text + instructions = [r for r in result if r[1] == "recipe"][0][0].text + + # Check results + self.assertEqual(len(ingredients), 8) + + self.assertTrue('Pan-Roasted Chicken with Oranges and Rosemary' in name) + + self.assertTrue('Heat oven to 450 degrees F and arrange rack in middle.' in instructions) + self.assertTrue('Let rest 5 minutes before serving.' in instructions) + + self.assertFalse('You must be logged in to review this recipe.' in instructions) + + + +if __name__ == '__main__': + unittest.main() From cf3f435f499d181f1b026998e10c0d3854b93652 Mon Sep 17 00:00:00 2001 From: jens persson Date: Tue, 7 May 2013 19:12:50 +0200 Subject: [PATCH 4/4] Buglet found with tests and som whitespace triming in foodnetwork plugin --- .../website_import_plugins/foodnetwork_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gourmet/plugins/import_export/website_import_plugins/foodnetwork_plugin.py b/gourmet/plugins/import_export/website_import_plugins/foodnetwork_plugin.py index a81ee7d0d..21dcc12cc 100644 --- a/gourmet/plugins/import_export/website_import_plugins/foodnetwork_plugin.py +++ b/gourmet/plugins/import_export/website_import_plugins/foodnetwork_plugin.py @@ -8,13 +8,14 @@ class FoodNetworkPlugin (PluginPlugin): def test_url (self, url, data): if 'foodnetwork.com' in url: return 5 + return 0 def get_importer (self, webpage_importer): class FoodNetworkParser (webpage_importer.MenuAndAdStrippingWebParser): imageexcluders = [re.compile('foodnetworkstore|googlead|ft-|banner')] - + def preparse (self): headm = re.compile('rcp-head.*') textm = re.compile('body-text.*') @@ -51,4 +52,3 @@ def preparse (self): webpage_importer.MenuAndAdStrippingWebParser.preparse(self) return FoodNetworkParser -