From a71c15f398ff4f31a53b62345ccbace556740d49 Mon Sep 17 00:00:00 2001 From: Rodrigo Taboada Date: Fri, 24 Oct 2014 15:42:30 -0200 Subject: [PATCH 1/3] Create headers field in VCRHTTPResponse. Fixes #117. --- vcr/stubs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 4e534f4..8dd40d3 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -76,7 +76,7 @@ class VCRHTTPResponse(HTTPResponse): self._closed = False headers = self.recorded_response['headers'] - self.msg = parse_headers(headers) + self.headers = self.msg = parse_headers(headers) self.length = compat.get_header(self.msg, 'content-length') or None From 5423d99f5ad2917d1cb472a8fe61a06a278e641b Mon Sep 17 00:00:00 2001 From: Rodrigo Taboada Date: Fri, 24 Oct 2014 17:40:51 -0200 Subject: [PATCH 2/3] Tests for VCRHTTPResponse headers field. --- tests/unit/test_response.py | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/unit/test_response.py diff --git a/tests/unit/test_response.py b/tests/unit/test_response.py new file mode 100644 index 0000000..503cf34 --- /dev/null +++ b/tests/unit/test_response.py @@ -0,0 +1,68 @@ +# coding: UTF-8 +from vcr.stubs import VCRHTTPResponse + + +def test_response_should_have_headers_field(): + recorded_response = { + "status": { + "message": "OK", + "code": 200 + }, + "headers": { + "content-length": ["0"], + "server": ["gunicorn/18.0"], + "connection": ["Close"], + "access-control-allow-credentials": ["true"], + "date": ["Fri, 24 Oct 2014 18:35:37 GMT"], + "access-control-allow-origin": ["*"], + "content-type": ["text/html; charset=utf-8"], + }, + "body": { + "string": "" + } + } + response = VCRHTTPResponse(recorded_response) + + assert response.headers is not None + + +def test_response_headers_should_be_equal_to_msg(): + recorded_response = { + "status": { + "message": "OK", + "code": 200 + }, + "headers": { + "content-length": ["0"], + "server": ["gunicorn/18.0"], + "connection": ["Close"], + "content-type": ["text/html; charset=utf-8"], + }, + "body": { + "string": "" + } + } + response = VCRHTTPResponse(recorded_response) + + assert response.headers == response.msg + + +def test_response_headers_should_have_correct_values(): + recorded_response = { + "status": { + "message": "OK", + "code": 200 + }, + "headers": { + "content-length": ["10806"], + "date": ["Fri, 24 Oct 2014 18:35:37 GMT"], + "content-type": ["text/html; charset=utf-8"], + }, + "body": { + "string": "" + } + } + response = VCRHTTPResponse(recorded_response) + + assert response.headers.get('content-length') == "10806" + assert response.headers.get('date') == "Fri, 24 Oct 2014 18:35:37 GMT" From c955a5ea888fb899abd177497768b6ec4bd2653d Mon Sep 17 00:00:00 2001 From: Rodrigo Taboada Date: Fri, 24 Oct 2014 18:30:06 -0200 Subject: [PATCH 3/3] String in request body should be bytes. --- tests/unit/test_response.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_response.py b/tests/unit/test_response.py index 503cf34..4ba6dcc 100644 --- a/tests/unit/test_response.py +++ b/tests/unit/test_response.py @@ -18,7 +18,7 @@ def test_response_should_have_headers_field(): "content-type": ["text/html; charset=utf-8"], }, "body": { - "string": "" + "string": b"" } } response = VCRHTTPResponse(recorded_response) @@ -29,7 +29,7 @@ def test_response_should_have_headers_field(): def test_response_headers_should_be_equal_to_msg(): recorded_response = { "status": { - "message": "OK", + "message": b"OK", "code": 200 }, "headers": { @@ -39,7 +39,7 @@ def test_response_headers_should_be_equal_to_msg(): "content-type": ["text/html; charset=utf-8"], }, "body": { - "string": "" + "string": b"" } } response = VCRHTTPResponse(recorded_response) @@ -59,7 +59,7 @@ def test_response_headers_should_have_correct_values(): "content-type": ["text/html; charset=utf-8"], }, "body": { - "string": "" + "string": b"" } } response = VCRHTTPResponse(recorded_response)