Skip to content

Commit

Permalink
Modify cache to file test to use different endpoint
Browse files Browse the repository at this point in the history
This avoids wsgiref incorrectly throwing an exception saying that
the return data must be bytes.
  • Loading branch information
tw4l committed May 15, 2024
1 parent a73f0d6 commit 2b1d4b2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/test_capture_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from warcio.utils import BUFF_SIZE
from warcio.warcwriter import BufferWARCWriter, WARCWriter

# ==================================================================



# ==================================================================
class TestCaptureHttpBin(object):
Expand Down Expand Up @@ -68,21 +71,29 @@ def test_get(self):
assert request.rec_headers['WARC-Target-URI'] == url
assert request.rec_headers['WARC-IP-Address'] == '127.0.0.1'

def test_get_cache_to_file(self):
def test_post_cache_to_file(self):
warc_writer = BufferWARCWriter(gzip=False)

url = 'http://localhost:{0}/bytes/{1}'.format(self.port, BUFF_SIZE * 2)
random_bytes = os.urandom(BUFF_SIZE * 2)
request_data = {"data": str(random_bytes)}

url = 'http://localhost:{0}/anything'.format(self.port)
with capture_http(warc_writer):
res = requests.get(url, headers={'Host': 'httpbin.org'})
res = requests.post(
url,
headers={'Host': 'httpbin.org'},
json=request_data
)

assert len(res.content) == BUFF_SIZE * 2
assert res.json()["json"] == request_data

ai = ArchiveIterator(warc_writer.get_stream())
response = next(ai)
assert response.rec_type == 'response'
assert response.rec_headers['WARC-Target-URI'] == url
assert response.rec_headers['WARC-IP-Address'] == '127.0.0.1'
assert res.content == response.content_stream().read()
response_data == json.loads(response.content_stream().read().decode('utf-8'))
assert res.json()["json"] == response_data

request = next(ai)
assert request.rec_type == 'request'
Expand Down

0 comments on commit 2b1d4b2

Please sign in to comment.