test(testing.create_environ): Cover missed branches

This patch adds a couple tests to ensure that a couple code branches
in create_environ are exercised.
This commit is contained in:
kgriffs
2014-03-24 14:13:37 -05:00
parent 40fac7013e
commit 69d89b9521
2 changed files with 25 additions and 1 deletions

View File

@@ -84,7 +84,10 @@ def create_environ(path='/', query_string='', protocol='HTTP/1.1', port='80',
body = io.BytesIO(body.encode('utf-8')
if isinstance(body, six.text_type) else body)
if six.PY2 and isinstance(path, unicode):
# NOTE(kgriffs): nocover since this branch will never be
# taken in Python3. However, the branch is tested under Py2,
# in test_utils.TestFalconTesting.test_unicode_path_in_create_environ
if six.PY2 and isinstance(path, unicode): # pragma: nocover
path = path.encode('utf-8')
env = {

View File

@@ -1,3 +1,5 @@
# -*- coding: utf-8-*-
from datetime import datetime
import functools
import random
@@ -6,6 +8,7 @@ import testtools
import six
import falcon
import falcon.testing
from falcon.util import uri
@@ -158,3 +161,21 @@ class TestFalconUtils(testtools.TestCase):
expect = stdlib_unquote(case)
actual = uri.decode(case)
self.assertEqual(expect, actual)
class TestFalconTesting(testtools.TestCase):
"""Catch some uncommon branches not covered elsewhere."""
def test_unicode_path_in_create_environ(self):
if six.PY3:
self.skip('Test does not apply to Py3K')
env = falcon.testing.create_environ(u'/fancy/unícode')
self.assertEqual(env['PATH_INFO'], '/fancy/un\xc3\xadcode')
env = falcon.testing.create_environ(u'/simple')
self.assertEqual(env['PATH_INFO'], '/simple')
def test_none_header_value_in_create_environ(self):
env = falcon.testing.create_environ('/', headers={'X-Foo': None})
self.assertEqual(env['HTTP_X_FOO'], '')