Send empty dict when no headers on create/update

When no headers are set on a Container.create, we end up attempting to
send `None` through to the various lower levels, and they depend on
being able to set things like the token on the headers that get sent
through. If `attrs` sent into both Container.create and Container.update
don't actually contain any headers, put an empty dictionary in place of
them.

Change-Id: Iea050976d86a12d7b78245147d3560b188c8a584
This commit is contained in:
Brian Curtin 2015-02-24 20:28:28 -06:00
parent 308960e20d
commit 1d05878fd7
2 changed files with 17 additions and 2 deletions

View File

@ -115,7 +115,7 @@ class Container(resource.Resource):
:return: A ``dict`` representing the response headers.
"""
url = utils.urljoin(cls.base_path, resource_id)
headers = attrs[resource.HEADERS]
headers = attrs.get(resource.HEADERS, dict())
return session.post(url, service=cls.service, accept=None,
headers=headers).headers
@ -133,7 +133,7 @@ class Container(resource.Resource):
:return: A ``dict`` representing the response headers.
"""
url = utils.urljoin(cls.base_path, resource_id)
headers = attrs[resource.HEADERS]
headers = attrs.get(resource.HEADERS, dict())
return session.put(url, service=cls.service, accept=None,
headers=headers).headers

View File

@ -178,3 +178,18 @@ class TestContainer(testtools.TestCase):
def test_update(self):
sot = container.Container.new(name=CONTAINER_NAME)
self._test_create_update(sot, sot.update, self.sess.post)
def _test_no_headers(self, sot, sot_call, sess_method):
sot = container.Container.new(name=CONTAINER_NAME)
sot.create(self.sess)
url = "/%s" % CONTAINER_NAME
self.sess.put.assert_called_with(url, service=sot.service,
accept=None, headers=dict())
def test_create_no_headers(self):
sot = container.Container.new(name=CONTAINER_NAME)
self._test_no_headers(sot, sot.create, self.sess.put)
def test_update_no_headers(self):
sot = container.Container.new(name=CONTAINER_NAME)
self._test_no_headers(sot, sot.update, self.sess.post)