For testing purpose, we should assert the sanity of Object Creation with ETag. This patch produces a way to assert the object etag and apply it to the functional tests. Change-Id: I659ef0d9fa3104392876e23ef699cc9f310b8d85
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
# Copyright (c) 2015 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.
|
|
|
|
from hashlib import md5
|
|
from swift3.etree import fromstring
|
|
|
|
|
|
def assert_common_response_headers(self, headers, etag=None):
|
|
"""
|
|
asserting common response headers with args
|
|
:param headers: a dict of response headers
|
|
:param etag: a string of md5(content).hexdigest() if not given,
|
|
this won't assert anything about etag. (e.g. DELETE obj)
|
|
"""
|
|
self.assertTrue(headers['x-amz-id-2'] is not None)
|
|
self.assertTrue(headers['x-amz-request-id'] is not None)
|
|
self.assertTrue(headers['date'] is not None)
|
|
# TODO; requires consideration
|
|
# self.assertTrue(headers['server'] is not None)
|
|
if etag is not None:
|
|
self.assertTrue('etag' in headers) # sanity
|
|
self.assertEquals(etag, headers['etag'].strip('"'))
|
|
|
|
|
|
def get_error_code(body):
|
|
elem = fromstring(body, 'Error')
|
|
return elem.find('Code').text
|
|
|
|
|
|
def calculate_md5(body):
|
|
return md5(body).digest().encode('base64').strip()
|