-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MarleySpoon: add precautionary check for unexpected API URLs. (#1069)
- Loading branch information
1 parent
b4567bf
commit 94b2617
Showing
4 changed files
with
75 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script> | ||
gon.current_brand="test_invalid"; gon.current_country="XX"; gon.api_token=" ".trim() || null; gon.api_host="http://api.marlarkey.invalid"; | ||
</script> | ||
</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,6 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script> | ||
gon.current_brand="test_invalid"; gon.current_country="XX"; gon.api_token=" ".trim() || null; gon.api_host="relative_path/unexpected.js"; | ||
</script> | ||
</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,41 @@ | ||
import unittest | ||
|
||
import responses | ||
|
||
from recipe_scrapers._exceptions import RecipeScrapersExceptions | ||
from recipe_scrapers.marleyspoon import MarleySpoon | ||
|
||
|
||
class TestFaultyAPIURLResponse(unittest.TestCase): | ||
|
||
@responses.activate | ||
def test_faulty_response(self): | ||
url = "https://marleyspoon.de/menu/113813-glasierte-veggie-burger-mit-roestkartoffeln-und-apfel-gurken-salat" | ||
with open("tests/legacy/test_data/faulty.testhtml") as faulty_data: | ||
faulty_response = faulty_data.read() | ||
|
||
responses.add( | ||
method=responses.GET, | ||
url=url, | ||
body=faulty_response, | ||
) | ||
|
||
with self.assertRaises(RecipeScrapersExceptions): | ||
MarleySpoon(url=url) | ||
|
||
@responses.activate | ||
def test_relative_api_url(self): | ||
url = "https://marleyspoon.de/menu/113813-glasierte-veggie-burger-mit-roestkartoffeln-und-apfel-gurken-salat" | ||
with open("tests/legacy/test_data/relative_url.testhtml") as relative_url_data: | ||
relative_url_response = relative_url_data.read() | ||
|
||
responses.add( | ||
method=responses.GET, | ||
url=url, | ||
body=relative_url_response, | ||
) | ||
|
||
with self.assertRaises(Exception): | ||
MarleySpoon( | ||
url=url | ||
) # currently this raises an requests.exceptions.MissingSchema exception |