From d7c3cf420138ef16876d2aafccf6f1a36dae2ee7 Mon Sep 17 00:00:00 2001 From: Igor Sobreira Date: Tue, 2 Apr 2013 05:42:07 +0000 Subject: [PATCH] fix headers capitalization on Entry class --- httpretty/__init__.py | 2 +- tests/functional/test_urllib2.py | 7 ++++--- tests/unit/test_httpretty.py | 13 ++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/httpretty/__init__.py b/httpretty/__init__.py index cad7a03..a6db440 100644 --- a/httpretty/__init__.py +++ b/httpretty/__init__.py @@ -480,7 +480,7 @@ class Entry(Py3kObject): self.status = int(status) for k, v in headers.items(): - name = "-".join(k.split("_")).capitalize() + name = "-".join(k.split("_")).title() self.adding_headers[name] = v self.validate() diff --git a/tests/functional/test_urllib2.py b/tests/functional/test_urllib2.py index 9fc0f47..95b0490 100644 --- a/tests/functional/test_urllib2.py +++ b/tests/functional/test_urllib2.py @@ -149,10 +149,11 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now): u"HTTPretty should allow adding and overwritting headers by " \ "keyword args with urllib2" + body = "this is supposed to be the response, indeed" HTTPretty.register_uri(HTTPretty.GET, "http://github.com/", - body="this is supposed to be the response, indeed", + body=body, server='Apache', - content_length='111111', + content_length=len(body), content_type='application/json') request = urlopen('http://github.com') @@ -163,7 +164,7 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(now): expect(headers).to.equal({ 'content-type': 'application/json', 'connection': 'close', - 'content-length': '111111', + 'content-length': str(len(body)), 'status': '200', 'server': 'Apache', 'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'), diff --git a/tests/unit/test_httpretty.py b/tests/unit/test_httpretty.py index b3b9637..b97c620 100644 --- a/tests/unit/test_httpretty.py +++ b/tests/unit/test_httpretty.py @@ -27,7 +27,7 @@ from __future__ import unicode_literals from sure import expect -from httpretty import HTTPretty, HTTPrettyError, STATUSES, URIInfo, Py3kObject +from httpretty import HTTPretty, HTTPrettyError, STATUSES, URIInfo, Py3kObject, Entry def test_httpretty_should_raise_proper_exception_on_inconsistent_length(): @@ -169,3 +169,14 @@ def test_py3kobject_implements_valid__repr__based_on__str__(): myobj = MyObject() expect(repr(myobj)).to.be.equal('hi') + + +def test_Entry_class_normalizes_headers(): + entry = Entry(HTTPretty.GET, 'http://example.com', 'example', + host='example.com', cache_control='no-cache', x_forward_for='proxy') + + expect(entry.adding_headers).to.equal({ + u'Host': u'example.com', + u'Cache-Control': u'no-cache', + u'X-Forward-For': u'proxy' + })