-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
414 additions
and
44 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,6 +1,6 @@ | ||
[run] | ||
source=urlquick | ||
branch = True | ||
branch=True | ||
|
||
[report] | ||
exclude_lines = | ||
|
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,46 @@ | ||
import urlquick | ||
import pytest | ||
import shutil | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
def clear_cache(): | ||
shutil.rmtree(urlquick.CACHE_LOCATION, ignore_errors=True) | ||
|
||
|
||
def test_xml(requests_mock): | ||
xml = b""" | ||
<note> | ||
<to>Tove</to> | ||
<from secure="true">Jani</from> | ||
</note> | ||
""" | ||
requests_mock.get('https://www.test.com/cache/1', body=xml) | ||
ret = urlquick.get('https://www.test.com/cache/1') | ||
assert ret.content == xml | ||
tree = ret.xml() | ||
|
||
assert tree.find("to").text == "Tove" | ||
assert tree.find("from").text == "Jani" | ||
assert tree.find("from").get("secure") == "true" | ||
|
||
|
||
def test_parse(requests_mock): | ||
html = b""" | ||
<html> | ||
<head> | ||
<title>Test title</title> | ||
</head> | ||
<body> | ||
<a href="https://google.ie">google</a> | ||
</body> | ||
</html> | ||
""" | ||
requests_mock.get('https://www.test.com/cache/2', body=html) | ||
ret = urlquick.get('https://www.test.com/cache/2') | ||
assert ret.content == html | ||
tree = ret.parse() | ||
|
||
assert tree.find(".//title").text == "Test title" | ||
assert tree.find(".//a").text == "google" | ||
assert tree.find(".//a").get("href") == "https://google.ie" |
Oops, something went wrong.