diff --git a/swift3/response.py b/swift3/response.py index 91120919..6c381738 100644 --- a/swift3/response.py +++ b/swift3/response.py @@ -18,6 +18,7 @@ from UserDict import DictMixin from functools import partial from swift.common import swob +from swift.common.utils import config_true_value from swift3.utils import snake_to_camel, sysmeta_prefix from swift3.etree import Element, SubElement, tostring @@ -108,7 +109,7 @@ class Response(ResponseBase, swob.Response): headers[key] = val elif _key == 'x-static-large-object': # for delete slo - self.is_slo = val + self.is_slo = config_true_value(val) self.headers = headers # Used for pure swift header handling at the request layer diff --git a/swift3/test/unit/test_request.py b/swift3/test/unit/test_request.py index e4835c83..35973c76 100644 --- a/swift3/test/unit/test_request.py +++ b/swift3/test/unit/test_request.py @@ -93,7 +93,7 @@ class TestRequest(Swift3TestCase): @patch('swift3.request.S3AclRequest.authenticate', lambda x, y: None) def _test_get_response(self, method, container='bucket', obj=None, permission=None, skip_check=False, - req_klass=S3_Request): + req_klass=S3_Request, fake_swift_resp=None): path = '/' + container + ('/' + obj if obj else '') req = Request.blank(path, environ={'REQUEST_METHOD': method}, @@ -105,7 +105,8 @@ class TestRequest(Swift3TestCase): with nested(patch('swift3.request.Request._get_response'), patch('swift3.subresource.ACL.check_permission')) \ as (mock_get_resp, m_check_permission): - mock_get_resp.return_value = FakeResponse(CONF.s3_acl) + mock_get_resp.return_value = fake_swift_resp \ + or FakeResponse(CONF.s3_acl) return mock_get_resp, m_check_permission,\ s3_req.get_response(self.swift3) diff --git a/swift3/test/unit/test_response.py b/swift3/test/unit/test_response.py new file mode 100644 index 00000000..c10d18d8 --- /dev/null +++ b/swift3/test/unit/test_response.py @@ -0,0 +1,33 @@ +# Copyright (c) 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +from swift.common.swob import Response +from swift3.response import Response as S3Response + + +class TestRequest(unittest.TestCase): + def test_from_swift_resp_slo(self): + for expected, header_vals in \ + ((True, ('true', '1')), (False, ('false', 'ugahhh', None))): + for val in header_vals: + resp = Response(headers={'X-Static-Large-Object': val}) + s3resp = S3Response.from_swift_resp(resp) + self.assertEqual(expected, s3resp.is_slo) + + +if __name__ == '__main__': + unittest.main()