-
-
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.
Add support for 'knockout' selectors that get filtered from output
- Loading branch information
Showing
3 changed files
with
65 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
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,47 @@ | ||
import pytest | ||
|
||
import requests | ||
from requests_testadapter import TestAdapter, TestSession | ||
|
||
from frozen_soup import freeze_to_string | ||
|
||
@pytest.fixture | ||
def session() -> requests.Session: | ||
s = TestSession() | ||
|
||
s.mount("http://test/content", TestAdapter( | ||
b'/* WONTON */', | ||
headers= { 'Content-type' : 'text/plain' } | ||
)) | ||
|
||
s.mount( | ||
"http://test/html", | ||
TestAdapter(b'<i class="ko">pow!</i><img src="/content">') | ||
) | ||
s.mount( | ||
"http://test/multiple", | ||
TestAdapter(b'<i class="ko">pow!</i><b class="ko">bang!</b><img src="/content">') | ||
) | ||
s.mount( | ||
"http://test/bad-img", | ||
TestAdapter(b'<i class="ko">pow!</i><img src="/error">') | ||
) | ||
|
||
return s | ||
|
||
def test_knockout(session): | ||
out = freeze_to_string('http://test/html', session, knockouts=['.ko']) | ||
assert out == '<img src="data:text/plain;base64,LyogV09OVE9OICov">' | ||
|
||
def test_knockout_multiple_elements(session): | ||
out = freeze_to_string('http://test/multiple', session, knockouts=['.ko']) | ||
assert out == '<img src="data:text/plain;base64,LyogV09OVE9OICov">' | ||
|
||
def test_knockout_multiple_selectors(session): | ||
out = freeze_to_string('http://test/multiple', session, knockouts=['i', 'b']) | ||
assert out == '<img src="data:text/plain;base64,LyogV09OVE9OICov">' | ||
|
||
# if the knockout doesn't kill the <img> we'll get an exception | ||
def test_knockout_img(session): | ||
out = freeze_to_string('http://test/bad-img', session, knockouts=['img']) | ||
assert out == '<i class="ko">pow!</i>' |