-
Notifications
You must be signed in to change notification settings - Fork 8
Scraper parsing tests #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee1bd36
Extract extraction of zone URLs
kgaughan fbf9b9e
Extract extraction of WHOIS server address
kgaughan 8fd9259
A bit more test coverage
kgaughan bca6202
Test empty documents
kgaughan b923218
More reasonable tests
kgaughan 090a7a7
Parametrise the no-match tests
kgaughan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,69 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="body"> | ||
<article class="hemmed sidenav"> | ||
<main> | ||
<div class="iana-table-frame"> | ||
<table id="tld-table" class="iana-table"> | ||
<thead> | ||
<tr> | ||
<th>Domain</th> | ||
<th>Type</th> | ||
<th>TLD Manager</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><span | ||
class="domain tld"><a>.broken</a></span></td> | ||
<td>broken</td> | ||
<td>This is just here for coverage</td> | ||
</tr> | ||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/aaa.html">.aaa</a></span></td> | ||
<td>generic</td> | ||
<td>American Automobile Association, | ||
Inc.</td> | ||
</tr> | ||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/bt.html">.bt</a></span></td> | ||
<td>country-code</td> | ||
<td>Ministry of Information and | ||
Communications</td> | ||
</tr> | ||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/dummy.html">.dummy</a></span></td> | ||
<td>generic</td> | ||
<td>Not assigned</td> | ||
</tr> | ||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/silly.html">.silly</a></span></td> | ||
<td>generic</td> | ||
<td>Retired</td> | ||
</tr> | ||
|
||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/xn--9t4b11yi5a.html">.테스트</a></span></td> | ||
<td>test</td> | ||
<td>Not assigned</td> | ||
</tr> | ||
<tr> | ||
<td><span class="domain tld"><a | ||
href="/domains/root/db/xxx.html">.xxx</a></span></td> | ||
<td>sponsored</td> | ||
<td>ICM Registry LLC</td> | ||
</tr> | ||
</tbody> | 10000 tr>||
</table> | ||
</div> | ||
</main> | ||
</article> | ||
</div> | ||
</body> | ||
</html> |
This file contains hidden or 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,46 @@ | ||
from os import path | ||
|
||
import bs4 | ||
import pytest | ||
|
||
from uwhoisd import scraper | ||
|
||
HERE = path.dirname(__file__) | ||
|
||
|
||
def test_extract_zone_urls(): | ||
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(path.join(path.dirname(__file__), "iana-root-zone.html"), encoding="utf-8") as fh: | ||
body = bs4.BeautifulSoup(fh, "html.parser") | ||
result = list(scraper.extract_zone_urls("http://example.com", body)) | ||
# The test zone should not appear | ||
assert result == [ | ||
("aaa", "http://example.com/domains/root/db/aaa.html"), | ||
("bt", "http://example.com/domains/root/db/bt.html"), | ||
("xxx", "http://example.com/domains/root/db/xxx.html"), | ||
] | ||
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_extract_zone_urls_edge_cases(): | ||
empty_body = bs4.BeautifulSoup("", "html.parser") | ||
assert list(scraper.extract_zone_urls("http://example.com", empty_body)) == [] | ||
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_extract_whois_server(): | ||
with open(path.join(path.dirname(__file__), "zone-info-fragment.html"), encoding="utf-8") as fh: | ||
body = bs4.BeautifulSoup(fh, "html.parser") | ||
result = scraper.extract_whois_server(body) | ||
assert result == "whois.nic.abc" | ||
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
kgaughan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
"fragment", | ||
[ | ||
"<html><body></body></html>", | ||
"<html><body><b>WHOIS Server:</b> </body></html>", | ||
"<html><body><b>WHOIS Server:</b></body></html>", | ||
], | ||
) | ||
def test_extract_whois_server_no_matches(fragment): | ||
body = bs4.BeautifulSoup(fragment, "html.parser") | ||
result = scraper.extract_whois_server(body) | ||
assert result is None |
This file contains hidden or 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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h2>Registry Information</h2> | ||
<p> | ||
<b>URL for registration services:</b> <a | ||
href="http://abc.com">http://abc.com</a><br> | ||
<b>WHOIS Server:</b> whois.nic.abc | ||
</p> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.