Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving recipe key derivation to its own module. Tweaking tests so that they depend less on the spiders' internals.
- Loading branch information
Showing
7 changed files
with
75 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import re | ||
|
||
|
||
def from_url(url): | ||
"""Converts a URL to a recipe key.""" | ||
# Strip out http:// or https:// prefix and www. | ||
url = re.sub(r'http.://www\.', '', url) | ||
# Strip trailing slash | ||
url = re.sub(r'/$', '', url) | ||
# Convert all characters to lowercase | ||
url = url.lower() | ||
# Replace all non a-z0-9/ characters with - | ||
url = re.sub(r'[^a-z0-9/]', '-', url) | ||
# Replace all / characters with _ | ||
return re.sub(r'/', '_', url) |
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
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,11 @@ | ||
import unittest | ||
|
||
from ketohub import recipe_key | ||
|
||
|
||
class RawContentSpiderTest(unittest.TestCase): | ||
|
||
def test_from_url_replaces_correct_characters(self): | ||
self.assertEqual( | ||
recipe_key.from_url('https://www.mock.com/Mikes_Chicken_Kiev/'), | ||
'mock-com_mikes-chicken-kiev') |
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