diff --git a/tests/unit/test_response.py b/tests/unit/test_response.py new file mode 100644 index 0000000..4ba6dcc --- /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": b"" + } + } + response = VCRHTTPResponse(recorded_response) + + assert response.headers is not None + + +def test_response_headers_should_be_equal_to_msg(): + recorded_response = { + "status": { + "message": b"OK", + "code": 200 + }, + "headers": { + "content-length": ["0"], + "server": ["gunicorn/18.0"], + "connection": ["Close"], + "content-type": ["text/html; charset=utf-8"], + }, + "body": { + "string": b"" + } + } + 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": b"" + } + } + response = VCRHTTPResponse(recorded_response) + + assert response.headers.get('content-length') == "10806" + assert response.headers.get('date') == "Fri, 24 Oct 2014 18:35:37 GMT" 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