From 69d89b9521118e7e3b564fdda23c2d7b1296a46e Mon Sep 17 00:00:00 2001 From: kgriffs Date: Mon, 24 Mar 2014 14:13:37 -0500 Subject: [PATCH] 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. --- falcon/testing/helpers.py | 5 ++++- tests/test_utils.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/falcon/testing/helpers.py b/falcon/testing/helpers.py index 03fcfb5..f7ec947 100644 --- a/falcon/testing/helpers.py +++ b/falcon/testing/helpers.py @@ -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 = { diff --git a/tests/test_utils.py b/tests/test_utils.py index fc7ea7e..4e7fb59 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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'], '')