Skip to content

Commit

Permalink
Merge pull request #238 from cdent/fix-gnocchi
Browse files Browse the repository at this point in the history
Raise GabbiFormatError when headers are None
  • Loading branch information
cdent committed Dec 22, 2017
2 parents d91d8ec + 81500e7 commit 887a893
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gabbi/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,15 @@ def _run_request(self, url, method, headers, body, redirect=False):
def _replace_headers_template(self, test_name, headers):
replaced_headers = {}

for name in headers:
try:
try:
for name in headers:
replaced_name = self.replace_template(name)
replaced_headers[replaced_name] = self.replace_template(
headers[name]
)
except TypeError as exc:
raise exception.GabbiFormatError(
'malformed headers in test %s: %s' % (test_name, exc))
except TypeError as exc:
raise exception.GabbiFormatError(
'malformed headers in test %s: %s' % (test_name, exc))

return replaced_headers

Expand Down
11 changes: 11 additions & 0 deletions gabbi/tests/test_replacers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest

from gabbi import case
from gabbi import exception


class EnvironReplaceTest(unittest.TestCase):
Expand Down Expand Up @@ -56,3 +57,13 @@ def test_environ_boolean(self):

os.environ['moo'] = "True"
self.assertEqual(True, http_case._environ_replace(message))


class TestReplaceHeaders(unittest.TestCase):

def test_empty_headers(self):
"""A None value in headers should cause a GabbiFormatError."""
http_case = case.HTTPTestCase('test_request')
self.assertRaises(
exception.GabbiFormatError,
http_case._replace_headers_template, 'foo', None)

0 comments on commit 887a893

Please sign in to comment.