Fixing support for package download API.

Adding "application/octet-stream" to default_accept_types
in order to allow calling the package download api with
the header "accept"="application/octet-stream".
Adding test for the fix, including negative test with
bad accept type.

Change-Id: I682e312b24183354b62fe10f45c412bf65e4f71e
Closes-Bug: #1485480
This commit is contained in:
noa 2015-08-17 13:33:30 +00:00
parent e640b075d5
commit fdec9e04ad
3 changed files with 44 additions and 1 deletions

View File

@ -291,7 +291,9 @@ class Request(webob.Request):
'application/xml',
'application/murano-packages-json-patch',
'multipart/form-data')
default_accept_types = ('application/json', 'application/xml')
default_accept_types = ('application/json',
'application/xml',
'application/octet-stream')
def best_match_content_type(self, supported_content_types=None):
"""Determine the requested response content-type.

View File

@ -173,6 +173,14 @@ class ControllerTest(object):
return self._simple_request(path, params=params, user=user,
tenant=tenant)
def _get_with_accept(self, path, params=None, user=DEFAULT_USER,
tenant=DEFAULT_TENANT,
accept='application/octet-stream'):
req = self._simple_request(path, params=params, user=user,
tenant=tenant)
req.accept = accept
return req
def _delete(self, path, params=None, user=DEFAULT_USER,
tenant=DEFAULT_TENANT):
params = params or {}

View File

@ -257,6 +257,39 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase):
self.assertEqual(imghdr.what('', result), 'png')
def test_download_package(self):
self._set_policy_rules(
{'download_package': '@'}
)
package_from_dir, package = self._test_package()
saved_package = db_catalog_api.package_upload(package, '')
self.expect_policy_check('download_package',
{'package_id': saved_package.id})
req = self._get_with_accept('/catalog/packages/%s/download'
% saved_package.id,
accept='application/octet-stream')
result = req.get_response(self.api)
self.assertEqual(200, result.status_code)
def test_download_package_negative(self):
package_from_dir, package = self._test_package()
saved_package = db_catalog_api.package_upload(package, '')
req = self._get_with_accept('/catalog/packages/%s/download'
% saved_package.id,
accept='application/foo')
result = req.get_response(self.api)
self.assertEqual(415, result.status_code)
def test_add_public_unauthorized(self):
self._set_policy_rules({
'upload_package': '@',