-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved protocol/domain splitting, added tests
- Loading branch information
1 parent
7b7635b
commit 15d49d8
Showing
5 changed files
with
41 additions
and
9 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 |
---|---|---|
@@ -1 +0,0 @@ | ||
from .crawler import Crawler | ||
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
Empty file.
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,35 @@ | ||
from unittest import TestCase | ||
|
||
import sys | ||
|
||
sys.path.append("..") | ||
|
||
from crawler.urls import get_protocol_and_domain_from_url | ||
|
||
|
||
class TestURLs(TestCase): | ||
def test_protocol_domain(self): | ||
urls = { | ||
"http://example.com/path?query=123#section": ["http:", "example.com"], | ||
"https://example.com?query": ["https:", "example.com"], | ||
"http://example.com/path": ["http:", "example.com"], | ||
"http://example.com": ["http:", "example.com"], | ||
"https://example.com/path?query#section": ["https:", "example.com"], | ||
"http://example.com/path/another#section": ["http:", "example.com"], | ||
"http://example.com/path/another?query": ["http:", "example.com"], | ||
"http://example.com?query#section": ["http:", "example.com"], | ||
"http://subdomain.example.com/path": ["http:", "subdomain.example.com"], | ||
"https://example.com:8080/path": ["https:", "example.com:8080"], | ||
"http://example.com//////path": ["http:", "example.com"], | ||
"http://example.com/path?query=1/2/3": ["http:", "example.com"], | ||
"http://example.com/path#": ["http:", "example.com"], | ||
"http://example.com?query?more": ["http:", "example.com"], | ||
"http://example.com/path;param?query#fragment": ["http:", "example.com"], | ||
"https://example.com#fragment": ["https:", "example.com"], | ||
"http://192.168.0.1/path": ["http:", "192.168.0.1"], | ||
"http://[::1]/path": ["http:", "[::1]"] | ||
} | ||
|
||
for url, expected in urls.items(): | ||
protocol, domain = get_protocol_and_domain_from_url(url) | ||
self.assertEqual([protocol, domain], expected) |