fix(testing): testing.create_environ(...) should allow headers to be an iterable of tuples as well as a dict.

Fixes #97
This commit is contained in:
kgriffs
2013-04-02 16:45:21 -04:00
parent 720fb8c5e5
commit 31fdaaacb3
2 changed files with 10 additions and 1 deletions

View File

@@ -67,7 +67,8 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
query_string: The query string to simulate (default '')
protocol: The HTTP protocol to simulate (default 'HTTP/1.1')
port: The TCP port to simulate (default '80')
headers: Optional headers to set (default None)
headers: Optional headers to set as a dict or an iterable of tuples
that can be converted to a dict (default None)
app: Value for the SCRIPT_NAME environ variable, described in
PEP-333: 'The initial portion of the request URL's "path" that
corresponds to the application object, so that the application
@@ -122,6 +123,10 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
def _add_headers_to_environ(env, headers):
if not isinstance(headers, dict):
# Try to convert
headers = dict(headers)
for name, value in headers.items():
name = name.upper().replace('-', '_')

View File

@@ -76,6 +76,10 @@ class TestHelloWorld(testing.TestBase):
def after(self):
pass
def test_env_headers_list_of_tuples(self):
env = testing.create_environ(headers=[('User-Agent', 'Falcon-Test')])
self.assertEquals(env['HTTP_USER_AGENT'], 'Falcon-Test')
def test_empty_route(self):
self.simulate_request('')
self.assertTrue(self.root_resource.called)