From bf5401283eed8b7088624122d62f35f90354ddef Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Fri, 26 Jan 2018 10:59:18 -0800 Subject: [PATCH] new test test_needs_browsing currently exposes bug in resolving "location" response header --- tests/test_units.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_units.py b/tests/test_units.py index 3f40863..ce5067c 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -310,3 +310,30 @@ def test_thread_raise_second_with_block(): th.join() assert isinstance(thread_caught_exception, Exception2) +def test_needs_browsing(): + # only one test case here right now, which exposed a bug + + class ConvenientHeaders(http.client.HTTPMessage): + def __init__(self, headers): + http.client.HTTPMessage.__init__(self) + for (k, v) in headers.items(): + self.add_header(k, v) + + page = brozzler.Page(None, { + 'url':'http://example.com/a'}) + + spy = brozzler.worker.YoutubeDLSpy() + spy.transactions.append({ + 'url': 'http://example.com/a', + 'method': 'HEAD', + 'status_code': 301, + 'response_headers': ConvenientHeaders({'Location': '/b'})}) + spy.transactions.append({ + 'url': 'http://example.com/b', + 'method': 'GET', + 'status_code': 200, + 'response_headers': ConvenientHeaders({ + 'Content-Type': 'application/pdf'})}) + + assert not brozzler.worker.BrozzlerWorker._needs_browsing(None, page, spy) +