Replace assertEquals with assertEqual

The method assertEquals has been deprecated since python 2.7.
http://docs.python.org/2/library/unittest.html#deprecated-aliases

Also in Python 3, a deprecated warning is raised when using assertEquals
therefore we should use assertEqual instead.

This is part of blueprint assertequal

Change-Id: Ie8887ba468bee10ddeb5b7a1d095821f898b9302
This commit is contained in:
Luong Anh Tuan 2016-11-21 15:56:30 +07:00
parent cdb589c32d
commit e9878374b4
5 changed files with 16 additions and 16 deletions

View File

@ -140,7 +140,7 @@ class TestSwiftOnFile(Base):
file_name), 'r') as fhOnMountPoint: file_name), 'r') as fhOnMountPoint:
data_read_from_mountP = fhOnMountPoint.read() data_read_from_mountP = fhOnMountPoint.read()
md5_returned = hashlib.md5(data_read_from_mountP).hexdigest() md5_returned = hashlib.md5(data_read_from_mountP).hexdigest()
self.assertEquals(md5_returned, file_info['etag']) self.assertEqual(md5_returned, file_info['etag'])
def test_GET_on_file_created_over_mountpoint(self): def test_GET_on_file_created_over_mountpoint(self):
file_name = Utils.create_name() file_name = Utils.create_name()

View File

@ -2871,7 +2871,7 @@ class TestObjectVersioning(Base):
container = self.env.container container = self.env.container
versions_container = self.env.versions_container versions_container = self.env.versions_container
cont_info = container.info() cont_info = container.info()
self.assertEquals(cont_info['versions'], versions_container.name) self.assertEqual(cont_info['versions'], versions_container.name)
obj_name = Utils.create_name() obj_name = Utils.create_name()

View File

@ -67,13 +67,13 @@ class TestConstraintsMiddleware(unittest.TestCase):
path = '/V1.0/a/c/o' path = '/V1.0/a/c/o'
resp = Request.blank(path, environ={'REQUEST_METHOD': 'GET'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'GET'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
def test_PUT_container(self): def test_PUT_container(self):
path = '/V1.0/a/c' path = '/V1.0/a/c'
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
def test_PUT_object_with_double_slashes(self): def test_PUT_object_with_double_slashes(self):
path = '/V1.0/a/c2//o' path = '/V1.0/a/c2//o'
@ -85,7 +85,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
"POLICIES", self.policies_mock)): "POLICIES", self.policies_mock)):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
self.assertTrue('Invalid object name' in resp.body) self.assertTrue('Invalid object name' in resp.body)
self.assertTrue('cannot begin, end, or have' in resp.body) self.assertTrue('cannot begin, end, or have' in resp.body)
@ -99,7 +99,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
"POLICIES", self.policies_mock)): "POLICIES", self.policies_mock)):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
self.assertTrue('Invalid object name' in resp.body) self.assertTrue('Invalid object name' in resp.body)
self.assertTrue('can end with a slash only if it is a directory' self.assertTrue('can end with a slash only if it is a directory'
in resp.body) in resp.body)
@ -114,7 +114,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
"POLICIES", self.policies_mock)): "POLICIES", self.policies_mock)):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
self.assertTrue('Invalid object name' in resp.body) self.assertTrue('Invalid object name' in resp.body)
self.assertTrue('cannot have . or ..' in resp.body) self.assertTrue('cannot have . or ..' in resp.body)
@ -124,7 +124,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
resp = Request.blank(path, method='PUT', resp = Request.blank(path, method='PUT',
headers={'X-Storage-Policy': 'swiftonhpss'} headers={'X-Storage-Policy': 'swiftonhpss'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
# test case where storage policy is not defined in header and # test case where storage policy is not defined in header and
# container would be created in default policy, which happens to be # container would be created in default policy, which happens to be
@ -137,7 +137,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
with patch("swiftonhpss.swift.common.middleware.check_constraints." with patch("swiftonhpss.swift.common.middleware.check_constraints."
"POLICIES", default_policies_mock): "POLICIES", default_policies_mock):
resp = Request.blank(path, method='PUT').get_response(self.test_check) resp = Request.blank(path, method='PUT').get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
def test_PUT_object_with_long_names(self): def test_PUT_object_with_long_names(self):
for i in (220,221): for i in (220,221):
@ -152,7 +152,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
"check_constraints.POLICIES", self.policies_mock)): "check_constraints.POLICIES", self.policies_mock)):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
longname = 'o' * 222 longname = 'o' * 222
path = '/V1.0/a/c2/' + longname path = '/V1.0/a/c2/' + longname
@ -164,7 +164,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
"POLICIES", self.policies_mock)): "POLICIES", self.policies_mock)):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 400) self.assertEqual(resp.status_int, 400)
self.assertTrue('too long' in resp.body) self.assertTrue('too long' in resp.body)
def test_PUT_object_with_policy0(self): def test_PUT_object_with_policy0(self):
@ -175,7 +175,7 @@ class TestConstraintsMiddleware(unittest.TestCase):
self.container1_info_mock): self.container1_info_mock):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
longname = 'o' * 222 longname = 'o' * 222
path = '/V1.0/a/c2/' + longname path = '/V1.0/a/c2/' + longname
@ -184,4 +184,4 @@ class TestConstraintsMiddleware(unittest.TestCase):
"get_container_info", self.container1_info_mock): "get_container_info", self.container1_info_mock):
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check) ).get_response(self.test_check)
self.assertEquals(resp.status_int, 200) self.assertEqual(resp.status_int, 200)

View File

@ -541,7 +541,7 @@ class TestDiskFile(unittest.TestCase):
the_dir = os.path.join(the_cont, "dir") the_dir = os.path.join(the_cont, "dir")
os.makedirs(the_dir) os.makedirs(the_dir)
gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "dir") gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "dir")
self.assertEquals(gdf._metadata, None) self.assertEqual(gdf._metadata, None)
init_md = { init_md = {
'X-Type': 'Object', 'X-Type': 'Object',
'Content-Length': 0, 'Content-Length': 0,

View File

@ -54,11 +54,11 @@ class TestObjectController(unittest.TestCase):
environ={'REQUEST_METHOD': 'REPLICATE'}, environ={'REQUEST_METHOD': 'REPLICATE'},
headers={}) headers={})
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 501) # HTTPNotImplemented self.assertEqual(resp.status_int, 501) # HTTPNotImplemented
def test_REPLICATION(self): def test_REPLICATION(self):
req = Request.blank('/sda1/p/suff', req = Request.blank('/sda1/p/suff',
environ={'REQUEST_METHOD': 'REPLICATION'}, environ={'REQUEST_METHOD': 'REPLICATION'},
headers={}) headers={})
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEquals(resp.status_int, 501) # HTTPNotImplemented self.assertEqual(resp.status_int, 501) # HTTPNotImplemented