test/(functional, probe): Replace "self.assert_" by "self.assertTrue"

The assert_() method is deprecated and can be safely replaced by assertTrue().
This patch makes sure that running the tests does not generate warnings
all over the screen.

Change-Id: I74705c6498249337bfdf955d62e0ad972035bc1f
This commit is contained in:
janonymous 2015-07-21 18:06:32 +05:30 committed by Alistair Coles
parent f244caf794
commit 8fe8bee7e0
8 changed files with 308 additions and 294 deletions

View File

@ -89,22 +89,22 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-test'), None) self.assertEqual(resp.getheader('x-account-meta-test'), None)
resp = retry(get) resp = retry(get)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-test'), None) self.assertEqual(resp.getheader('x-account-meta-test'), None)
resp = retry(post, 'Value') resp = retry(post, 'Value')
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-test'), 'Value') self.assertEqual(resp.getheader('x-account-meta-test'), 'Value')
resp = retry(get) resp = retry(get)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-test'), 'Value') self.assertEqual(resp.getheader('x-account-meta-test'), 'Value')
def test_invalid_acls(self): def test_invalid_acls(self):
@ -204,7 +204,7 @@ class TestAccount(unittest.TestCase):
# read-only can read account headers # read-only can read account headers
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204)) self.assertTrue(resp.status in (200, 204))
# but not acls # but not acls
self.assertEqual(resp.getheader('X-Account-Access-Control'), None) self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
@ -221,7 +221,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204)) self.assertTrue(resp.status in (200, 204))
self.assertEqual(resp.getheader('X-Account-Meta-Test'), 'value') self.assertEqual(resp.getheader('X-Account-Meta-Test'), 'value')
@requires_acls @requires_acls
@ -255,7 +255,7 @@ class TestAccount(unittest.TestCase):
# read-write can read account headers # read-write can read account headers
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204)) self.assertTrue(resp.status in (200, 204))
# but not acls # but not acls
self.assertEqual(resp.getheader('X-Account-Access-Control'), None) self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
@ -296,7 +296,7 @@ class TestAccount(unittest.TestCase):
# admin can read account headers # admin can read account headers
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204)) self.assertTrue(resp.status in (200, 204))
# including acls # including acls
self.assertEqual(resp.getheader('X-Account-Access-Control'), self.assertEqual(resp.getheader('X-Account-Access-Control'),
acl_json_str) acl_json_str)
@ -309,7 +309,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204)) self.assertTrue(resp.status in (200, 204))
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value) self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# admin can even revoke their own access # admin can even revoke their own access
@ -359,7 +359,8 @@ class TestAccount(unittest.TestCase):
# read-only tester3 can read account metadata # read-only tester3 can read account metadata
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), self.assertTrue(
resp.status in (200, 204),
'Expected status in (200, 204), got %s' % resp.status) 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value) self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# but not temp-url-key # but not temp-url-key
@ -377,7 +378,8 @@ class TestAccount(unittest.TestCase):
# read-write tester3 can read account metadata # read-write tester3 can read account metadata
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), self.assertTrue(
resp.status in (200, 204),
'Expected status in (200, 204), got %s' % resp.status) 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value) self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# but not temp-url-key # but not temp-url-key
@ -395,7 +397,8 @@ class TestAccount(unittest.TestCase):
# admin tester3 can read account metadata # admin tester3 can read account metadata
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), self.assertTrue(
resp.status in (200, 204),
'Expected status in (200, 204), got %s' % resp.status) 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value) self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# including temp-url-key # including temp-url-key
@ -412,7 +415,8 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), self.assertTrue(
resp.status in (200, 204),
'Expected status in (200, 204), got %s' % resp.status) 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'), self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'),
secret) secret)
@ -692,14 +696,14 @@ class TestAccount(unittest.TestCase):
self.assertTrue(resp.status in (201, 204)) self.assertTrue(resp.status in (201, 204))
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader(uni_key.encode('utf-8')), '1') self.assertEqual(resp.getheader(uni_key.encode('utf-8')), '1')
resp = retry(post, 'X-Account-Meta-uni', uni_value) resp = retry(post, 'X-Account-Meta-uni', uni_value)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-uni'), self.assertEqual(resp.getheader('X-Account-Meta-uni'),
uni_value.encode('utf-8')) uni_value.encode('utf-8'))
if (tf.web_front_end == 'integral'): if (tf.web_front_end == 'integral'):
@ -708,7 +712,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader(uni_key.encode('utf-8')), self.assertEqual(resp.getheader(uni_key.encode('utf-8')),
uni_value.encode('utf-8')) uni_value.encode('utf-8'))
@ -730,14 +734,14 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-one'), '1') self.assertEqual(resp.getheader('x-account-meta-one'), '1')
resp = retry(post, 'X-Account-Meta-Two', '2') resp = retry(post, 'X-Account-Meta-Two', '2')
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-account-meta-one'), '1') self.assertEqual(resp.getheader('x-account-meta-one'), '1')
self.assertEqual(resp.getheader('x-account-meta-two'), '2') self.assertEqual(resp.getheader('x-account-meta-two'), '2')

View File

@ -72,7 +72,7 @@ class TestContainer(unittest.TestCase):
body = resp.read() body = resp.read()
if resp.status == 404: if resp.status == 404:
break break
self.assert_(resp.status // 100 == 2, resp.status) self.assertTrue(resp.status // 100 == 2, resp.status)
objs = json.loads(body) objs = json.loads(body)
if not objs: if not objs:
break break
@ -93,7 +93,7 @@ class TestContainer(unittest.TestCase):
# container may have not been created # container may have not been created
resp = retry(delete, self.container) resp = retry(delete, self.container)
resp.read() resp.read()
self.assert_(resp.status in (204, 404)) self.assertTrue(resp.status in (204, 404))
def test_multi_metadata(self): def test_multi_metadata(self):
if tf.skip: if tf.skip:
@ -114,14 +114,14 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-one'), '1') self.assertEqual(resp.getheader('x-container-meta-one'), '1')
resp = retry(post, 'X-Container-Meta-Two', '2') resp = retry(post, 'X-Container-Meta-Two', '2')
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-one'), '1') self.assertEqual(resp.getheader('x-container-meta-one'), '1')
self.assertEqual(resp.getheader('x-container-meta-two'), '2') self.assertEqual(resp.getheader('x-container-meta-two'), '2')
@ -147,14 +147,14 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader(uni_key.encode('utf-8')), '1') self.assertEqual(resp.getheader(uni_key.encode('utf-8')), '1')
resp = retry(post, 'X-Container-Meta-uni', uni_value) resp = retry(post, 'X-Container-Meta-uni', uni_value)
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('X-Container-Meta-uni'), self.assertEqual(resp.getheader('X-Container-Meta-uni'),
uni_value.encode('utf-8')) uni_value.encode('utf-8'))
if (tf.web_front_end == 'integral'): if (tf.web_front_end == 'integral'):
@ -163,7 +163,7 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader(uni_key.encode('utf-8')), self.assertEqual(resp.getheader(uni_key.encode('utf-8')),
uni_value.encode('utf-8')) uni_value.encode('utf-8'))
@ -198,11 +198,11 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 201) self.assertEqual(resp.status, 201)
resp = retry(head, name) resp = retry(head, name)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), 'Value') self.assertEqual(resp.getheader('x-container-meta-test'), 'Value')
resp = retry(get, name) resp = retry(get, name)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), 'Value') self.assertEqual(resp.getheader('x-container-meta-test'), 'Value')
resp = retry(delete, name) resp = retry(delete, name)
resp.read() resp.read()
@ -214,11 +214,11 @@ class TestContainer(unittest.TestCase):
self.assertEqual(resp.status, 201) self.assertEqual(resp.status, 201)
resp = retry(head, name) resp = retry(head, name)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), None) self.assertEqual(resp.getheader('x-container-meta-test'), None)
resp = retry(get, name) resp = retry(get, name)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), None) self.assertEqual(resp.getheader('x-container-meta-test'), None)
resp = retry(delete, name) resp = retry(delete, name)
resp.read() resp.read()
@ -246,22 +246,22 @@ class TestContainer(unittest.TestCase):
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), None) self.assertEqual(resp.getheader('x-container-meta-test'), None)
resp = retry(get) resp = retry(get)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), None) self.assertEqual(resp.getheader('x-container-meta-test'), None)
resp = retry(post, 'Value') resp = retry(post, 'Value')
resp.read() resp.read()
self.assertEqual(resp.status, 204) self.assertEqual(resp.status, 204)
resp = retry(head) resp = retry(head)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), 'Value') self.assertEqual(resp.getheader('x-container-meta-test'), 'Value')
resp = retry(get) resp = retry(get)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
self.assertEqual(resp.getheader('x-container-meta-test'), 'Value') self.assertEqual(resp.getheader('x-container-meta-test'), 'Value')
def test_PUT_bad_metadata(self): def test_PUT_bad_metadata(self):
@ -484,7 +484,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get) resp = retry(get)
raise Exception('Should not have been able to GET') raise Exception('Should not have been able to GET')
except Exception as err: except Exception as err:
self.assert_(str(err).startswith('No result after '), err) self.assertTrue(str(err).startswith('No result after '), err)
def post(url, token, parsed, conn): def post(url, token, parsed, conn):
conn.request('POST', parsed.path + '/' + self.name, '', conn.request('POST', parsed.path + '/' + self.name, '',
@ -511,7 +511,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get) resp = retry(get)
raise Exception('Should not have been able to GET') raise Exception('Should not have been able to GET')
except Exception as err: except Exception as err:
self.assert_(str(err).startswith('No result after '), err) self.assertTrue(str(err).startswith('No result after '), err)
def test_cross_account_container(self): def test_cross_account_container(self):
if tf.skip or tf.skip2: if tf.skip or tf.skip2:
@ -743,7 +743,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.name in listing) self.assertTrue(self.name in listing)
# read-only can not create containers # read-only can not create containers
new_container_name = str(uuid4()) new_container_name = str(uuid4())
@ -758,7 +758,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(new_container_name in listing) self.assertTrue(new_container_name in listing)
@requires_acls @requires_acls
def test_read_only_acl_metadata(self): def test_read_only_acl_metadata(self):
@ -858,7 +858,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.name in listing) self.assertTrue(self.name in listing)
# can create new containers # can create new containers
new_container_name = str(uuid4()) new_container_name = str(uuid4())
@ -868,7 +868,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(new_container_name in listing) self.assertTrue(new_container_name in listing)
# can also delete them # can also delete them
resp = retry(delete, new_container_name, use_account=3) resp = retry(delete, new_container_name, use_account=3)
@ -877,7 +877,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(new_container_name not in listing) self.assertTrue(new_container_name not in listing)
# even if they didn't create them # even if they didn't create them
empty_container_name = str(uuid4()) empty_container_name = str(uuid4())
@ -1000,7 +1000,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.name in listing) self.assertTrue(self.name in listing)
# can create new containers # can create new containers
new_container_name = str(uuid4()) new_container_name = str(uuid4())
@ -1010,7 +1010,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(new_container_name in listing) self.assertTrue(new_container_name in listing)
# can also delete them # can also delete them
resp = retry(delete, new_container_name, use_account=3) resp = retry(delete, new_container_name, use_account=3)
@ -1019,7 +1019,7 @@ class TestContainer(unittest.TestCase):
resp = retry(get, use_account=3) resp = retry(get, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(new_container_name not in listing) self.assertTrue(new_container_name not in listing)
# even if they didn't create them # even if they didn't create them
empty_container_name = str(uuid4()) empty_container_name = str(uuid4())
@ -1595,7 +1595,7 @@ class BaseTestContainerACLs(unittest.TestCase):
while True: while True:
resp = retry(get, use_account=self.account) resp = retry(get, use_account=self.account)
body = resp.read() body = resp.read()
self.assert_(resp.status // 100 == 2, resp.status) self.assertTrue(resp.status // 100 == 2, resp.status)
objs = json.loads(body) objs = json.loads(body)
if not objs: if not objs:
break break

View File

@ -89,7 +89,7 @@ class TestObject(unittest.TestCase):
body = resp.read() body = resp.read()
if resp.status == 404: if resp.status == 404:
break break
self.assert_(resp.status // 100 == 2, resp.status) self.assertTrue(resp.status // 100 == 2, resp.status)
objs = json.loads(body) objs = json.loads(body)
if not objs: if not objs:
break break
@ -107,7 +107,7 @@ class TestObject(unittest.TestCase):
for container in self.containers: for container in self.containers:
resp = retry(delete, container) resp = retry(delete, container)
resp.read() resp.read()
self.assert_(resp.status in (204, 404)) self.assertTrue(resp.status in (204, 404))
def test_if_none_match(self): def test_if_none_match(self):
def put(url, token, parsed, conn): def put(url, token, parsed, conn):
@ -387,7 +387,7 @@ class TestObject(unittest.TestCase):
resp = retry(get) resp = retry(get)
raise Exception('Should not have been able to GET') raise Exception('Should not have been able to GET')
except Exception as err: except Exception as err:
self.assert_(str(err).startswith('No result after ')) self.assertTrue(str(err).startswith('No result after '))
def post(url, token, parsed, conn): def post(url, token, parsed, conn):
conn.request('POST', parsed.path + '/' + self.container, '', conn.request('POST', parsed.path + '/' + self.container, '',
@ -412,7 +412,7 @@ class TestObject(unittest.TestCase):
resp = retry(get) resp = retry(get)
raise Exception('Should not have been able to GET') raise Exception('Should not have been able to GET')
except Exception as err: except Exception as err:
self.assert_(str(err).startswith('No result after ')) self.assertTrue(str(err).startswith('No result after '))
def test_private_object(self): def test_private_object(self):
if tf.skip or tf.skip3: if tf.skip or tf.skip3:
@ -562,7 +562,7 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.obj in listing) self.assertTrue(self.obj in listing)
# can get object # can get object
resp = retry(get, self.obj, use_account=3) resp = retry(get, self.obj, use_account=3)
@ -585,8 +585,8 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(obj_name not in listing) self.assertTrue(obj_name not in listing)
self.assert_(self.obj in listing) self.assertTrue(self.obj in listing)
@requires_acls @requires_acls
def test_read_write(self): def test_read_write(self):
@ -643,7 +643,7 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.obj in listing) self.assertTrue(self.obj in listing)
# can get object # can get object
resp = retry(get, self.obj, use_account=3) resp = retry(get, self.obj, use_account=3)
@ -666,8 +666,8 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(obj_name in listing) self.assertTrue(obj_name in listing)
self.assert_(self.obj not in listing) self.assertTrue(self.obj not in listing)
@requires_acls @requires_acls
def test_admin(self): def test_admin(self):
@ -724,7 +724,7 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(self.obj in listing) self.assertTrue(self.obj in listing)
# can get object # can get object
resp = retry(get, self.obj, use_account=3) resp = retry(get, self.obj, use_account=3)
@ -747,8 +747,8 @@ class TestObject(unittest.TestCase):
resp = retry(get_listing, use_account=3) resp = retry(get_listing, use_account=3)
listing = resp.read() listing = resp.read()
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
self.assert_(obj_name in listing) self.assertTrue(obj_name in listing)
self.assert_(self.obj not in listing) self.assertTrue(self.obj not in listing)
def test_manifest(self): def test_manifest(self):
if tf.skip: if tf.skip:

View File

@ -69,11 +69,12 @@ class Base(unittest.TestCase):
def assert_body(self, body): def assert_body(self, body):
response_body = self.env.conn.response.read() response_body = self.env.conn.response.read()
self.assert_(response_body == body, self.assertTrue(response_body == body,
'Body returned: %s' % (response_body)) 'Body returned: %s' % (response_body))
def assert_status(self, status_or_statuses): def assert_status(self, status_or_statuses):
self.assert_(self.env.conn.response.status == status_or_statuses or self.assertTrue(
self.env.conn.response.status == status_or_statuses or
(hasattr(status_or_statuses, '__iter__') and (hasattr(status_or_statuses, '__iter__') and
self.env.conn.response.status in status_or_statuses), self.env.conn.response.status in status_or_statuses),
'Status returned: %d Expected: %s' % 'Status returned: %d Expected: %s' %
@ -132,7 +133,7 @@ class TestAccount(Base):
def testInvalidUTF8Path(self): def testInvalidUTF8Path(self):
invalid_utf8 = Utils.create_utf8_name()[::-1] invalid_utf8 = Utils.create_utf8_name()[::-1]
container = self.env.account.container(invalid_utf8) container = self.env.account.container(invalid_utf8)
self.assert_(not container.create(cfg={'no_path_quote': True})) self.assertTrue(not container.create(cfg={'no_path_quote': True}))
self.assert_status(412) self.assert_status(412)
self.assert_body('Invalid UTF8 or contains NULL') self.assert_body('Invalid UTF8 or contains NULL')
@ -165,7 +166,7 @@ class TestAccount(Base):
info = self.env.account.info() info = self.env.account.info()
for field in ['object_count', 'container_count', 'bytes_used']: for field in ['object_count', 'container_count', 'bytes_used']:
self.assert_(info[field] >= 0) self.assertTrue(info[field] >= 0)
if info['container_count'] == len(self.env.containers): if info['container_count'] == len(self.env.containers):
break break
@ -192,8 +193,8 @@ class TestAccount(Base):
for format_type in ['json', 'xml']: for format_type in ['json', 'xml']:
for a in self.env.account.containers( for a in self.env.account.containers(
parms={'format': format_type}): parms={'format': format_type}):
self.assert_(a['count'] >= 0) self.assertTrue(a['count'] >= 0)
self.assert_(a['bytes'] >= 0) self.assertTrue(a['bytes'] >= 0)
headers = dict(self.env.conn.response.getheaders()) headers = dict(self.env.conn.response.getheaders())
if format_type == 'json': if format_type == 'json':
@ -209,7 +210,7 @@ class TestAccount(Base):
p = {'limit': l} p = {'limit': l}
if l <= limit: if l <= limit:
self.assert_(len(self.env.account.containers(parms=p)) <= l) self.assertTrue(len(self.env.account.containers(parms=p)) <= l)
self.assert_status(200) self.assert_status(200)
else: else:
self.assertRaises(ResponseError, self.assertRaises(ResponseError,
@ -256,11 +257,11 @@ class TestAccount(Base):
parms={'format': format_type, parms={'format': format_type,
'marker': marker, 'marker': marker,
'limit': limit}) 'limit': limit})
self.assert_(len(containers) <= limit) self.assertTrue(len(containers) <= limit)
if containers: if containers:
if isinstance(containers[0], dict): if isinstance(containers[0], dict):
containers = [x['name'] for x in containers] containers = [x['name'] for x in containers]
self.assert_(locale.strcoll(containers[0], marker) > 0) self.assertTrue(locale.strcoll(containers[0], marker) > 0)
def testContainersOrderedByName(self): def testContainersOrderedByName(self):
for format_type in [None, 'json', 'xml']: for format_type in [None, 'json', 'xml']:
@ -314,7 +315,7 @@ class TestAccountNoContainers(Base):
def testGetRequest(self): def testGetRequest(self):
for format_type in [None, 'json', 'xml']: for format_type in [None, 'json', 'xml']:
self.assert_(not self.env.account.containers( self.assertTrue(not self.env.account.containers(
parms={'format': format_type})) parms={'format': format_type}))
if format_type is None: if format_type is None:
@ -369,48 +370,49 @@ class TestContainer(Base):
limit + 1, limit + 10, limit + 100): limit + 1, limit + 10, limit + 100):
cont = self.env.account.container('a' * l) cont = self.env.account.container('a' * l)
if l <= limit: if l <= limit:
self.assert_(cont.create()) self.assertTrue(cont.create())
self.assert_status(201) self.assert_status(201)
else: else:
self.assert_(not cont.create()) self.assertTrue(not cont.create())
self.assert_status(400) self.assert_status(400)
def testFileThenContainerDelete(self): def testFileThenContainerDelete(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
file_item = cont.file(Utils.create_name()) file_item = cont.file(Utils.create_name())
self.assert_(file_item.write_random()) self.assertTrue(file_item.write_random())
self.assert_(file_item.delete()) self.assertTrue(file_item.delete())
self.assert_status(204) self.assert_status(204)
self.assert_(file_item.name not in cont.files()) self.assertTrue(file_item.name not in cont.files())
self.assert_(cont.delete()) self.assertTrue(cont.delete())
self.assert_status(204) self.assert_status(204)
self.assert_(cont.name not in self.env.account.containers()) self.assertTrue(cont.name not in self.env.account.containers())
def testFileListingLimitMarkerPrefix(self): def testFileListingLimitMarkerPrefix(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
files = sorted([Utils.create_name() for x in range(10)]) files = sorted([Utils.create_name() for x in range(10)])
for f in files: for f in files:
file_item = cont.file(f) file_item = cont.file(f)
self.assert_(file_item.write_random()) self.assertTrue(file_item.write_random())
for i in range(len(files)): for i in range(len(files)):
f = files[i] f = files[i]
for j in range(1, len(files) - i): for j in range(1, len(files) - i):
self.assert_(cont.files(parms={'limit': j, 'marker': f}) == self.assertTrue(
cont.files(parms={'limit': j, 'marker': f}) ==
files[i + 1: i + j + 1]) files[i + 1: i + j + 1])
self.assert_(cont.files(parms={'marker': f}) == files[i + 1:]) self.assertTrue(cont.files(parms={'marker': f}) == files[i + 1:])
self.assert_(cont.files(parms={'marker': f, 'prefix': f}) == []) self.assertTrue(cont.files(parms={'marker': f, 'prefix': f}) == [])
self.assert_(cont.files(parms={'prefix': f}) == [f]) self.assertTrue(cont.files(parms={'prefix': f}) == [f])
def testPrefixAndLimit(self): def testPrefixAndLimit(self):
load_constraint('container_listing_limit') load_constraint('container_listing_limit')
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
prefix_file_count = 10 prefix_file_count = 10
limit_count = 2 limit_count = 2
@ -437,7 +439,7 @@ class TestContainer(Base):
self.assertEqual(len(files), limit_count) self.assertEqual(len(files), limit_count)
for file_item in files: for file_item in files:
self.assert_(file_item.startswith(prefix)) self.assertTrue(file_item.startswith(prefix))
def testListDelimiter(self): def testListDelimiter(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
@ -469,9 +471,9 @@ class TestContainer(Base):
def testCreate(self): def testCreate(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
self.assert_status(201) self.assert_status(201)
self.assert_(cont.name in self.env.account.containers()) self.assertTrue(cont.name in self.env.account.containers())
def testContainerFileListOnContainerThatDoesNotExist(self): def testContainerFileListOnContainerThatDoesNotExist(self):
for format_type in [None, 'json', 'xml']: for format_type in [None, 'json', 'xml']:
@ -484,13 +486,13 @@ class TestContainer(Base):
valid_utf8 = Utils.create_utf8_name() valid_utf8 = Utils.create_utf8_name()
invalid_utf8 = valid_utf8[::-1] invalid_utf8 = valid_utf8[::-1]
container = self.env.account.container(valid_utf8) container = self.env.account.container(valid_utf8)
self.assert_(container.create(cfg={'no_path_quote': True})) self.assertTrue(container.create(cfg={'no_path_quote': True}))
self.assert_(container.name in self.env.account.containers()) self.assertTrue(container.name in self.env.account.containers())
self.assertEqual(container.files(), []) self.assertEqual(container.files(), [])
self.assert_(container.delete()) self.assertTrue(container.delete())
container = self.env.account.container(invalid_utf8) container = self.env.account.container(invalid_utf8)
self.assert_(not container.create(cfg={'no_path_quote': True})) self.assertTrue(not container.create(cfg={'no_path_quote': True}))
self.assert_status(412) self.assert_status(412)
self.assertRaises(ResponseError, container.files, self.assertRaises(ResponseError, container.files,
cfg={'no_path_quote': True}) cfg={'no_path_quote': True})
@ -498,9 +500,9 @@ class TestContainer(Base):
def testCreateOnExisting(self): def testCreateOnExisting(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
self.assert_status(201) self.assert_status(201)
self.assert_(cont.create()) self.assertTrue(cont.create())
self.assert_status(202) self.assert_status(202)
def testSlashInName(self): def testSlashInName(self):
@ -516,31 +518,31 @@ class TestContainer(Base):
cont_name = cont_name.encode('utf-8') cont_name = cont_name.encode('utf-8')
cont = self.env.account.container(cont_name) cont = self.env.account.container(cont_name)
self.assert_(not cont.create(cfg={'no_path_quote': True}), self.assertTrue(not cont.create(cfg={'no_path_quote': True}),
'created container with name %s' % (cont_name)) 'created container with name %s' % (cont_name))
self.assert_status(404) self.assert_status(404)
self.assert_(cont.name not in self.env.account.containers()) self.assertTrue(cont.name not in self.env.account.containers())
def testDelete(self): def testDelete(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
self.assert_status(201) self.assert_status(201)
self.assert_(cont.delete()) self.assertTrue(cont.delete())
self.assert_status(204) self.assert_status(204)
self.assert_(cont.name not in self.env.account.containers()) self.assertTrue(cont.name not in self.env.account.containers())
def testDeleteOnContainerThatDoesNotExist(self): def testDeleteOnContainerThatDoesNotExist(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(not cont.delete()) self.assertTrue(not cont.delete())
self.assert_status(404) self.assert_status(404)
def testDeleteOnContainerWithFiles(self): def testDeleteOnContainerWithFiles(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assert_(cont.create()) self.assertTrue(cont.create())
file_item = cont.file(Utils.create_name()) file_item = cont.file(Utils.create_name())
file_item.write_random(self.env.file_size) file_item.write_random(self.env.file_size)
self.assert_(file_item.name in cont.files()) self.assertTrue(file_item.name in cont.files())
self.assert_(not cont.delete()) self.assertTrue(not cont.delete())
self.assert_status(409) self.assert_status(409)
def testFileCreateInContainerThatDoesNotExist(self): def testFileCreateInContainerThatDoesNotExist(self):
@ -572,10 +574,10 @@ class TestContainer(Base):
files = [x['name'] for x in files] files = [x['name'] for x in files]
for file_item in self.env.files: for file_item in self.env.files:
self.assert_(file_item in files) self.assertTrue(file_item in files)
for file_item in files: for file_item in files:
self.assert_(file_item in self.env.files) self.assertTrue(file_item in self.env.files)
def testMarkerLimitFileList(self): def testMarkerLimitFileList(self):
for format_type in [None, 'json', 'xml']: for format_type in [None, 'json', 'xml']:
@ -592,11 +594,11 @@ class TestContainer(Base):
if isinstance(files[0], dict): if isinstance(files[0], dict):
files = [x['name'] for x in files] files = [x['name'] for x in files]
self.assert_(len(files) <= limit) self.assertTrue(len(files) <= limit)
if files: if files:
if isinstance(files[0], dict): if isinstance(files[0], dict):
files = [x['name'] for x in files] files = [x['name'] for x in files]
self.assert_(locale.strcoll(files[0], marker) > 0) self.assertTrue(locale.strcoll(files[0], marker) > 0)
def testFileOrder(self): def testFileOrder(self):
for format_type in [None, 'json', 'xml']: for format_type in [None, 'json', 'xml']:
@ -625,19 +627,19 @@ class TestContainer(Base):
def testTooLongName(self): def testTooLongName(self):
cont = self.env.account.container('x' * 257) cont = self.env.account.container('x' * 257)
self.assert_(not cont.create(), self.assertTrue(not cont.create(),
'created container with name %s' % (cont.name)) 'created container with name %s' % (cont.name))
self.assert_status(400) self.assert_status(400)
def testContainerExistenceCachingProblem(self): def testContainerExistenceCachingProblem(self):
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assertRaises(ResponseError, cont.files) self.assertRaises(ResponseError, cont.files)
self.assert_(cont.create()) self.assertTrue(cont.create())
cont.files() cont.files()
cont = self.env.account.container(Utils.create_name()) cont = self.env.account.container(Utils.create_name())
self.assertRaises(ResponseError, cont.files) self.assertRaises(ResponseError, cont.files)
self.assert_(cont.create()) self.assertTrue(cont.create())
file_item = cont.file(Utils.create_name()) file_item = cont.file(Utils.create_name())
file_item.write_random() file_item.write_random()
@ -735,7 +737,7 @@ class TestContainerPaths(Base):
raise ValueError('too deep recursion') raise ValueError('too deep recursion')
for file_item in self.env.container.files(parms={'path': path}): for file_item in self.env.container.files(parms={'path': path}):
self.assert_(file_item.startswith(path)) self.assertTrue(file_item.startswith(path))
if file_item.endswith('/'): if file_item.endswith('/'):
recurse_path(file_item, count + 1) recurse_path(file_item, count + 1)
found_dirs.append(file_item) found_dirs.append(file_item)
@ -745,28 +747,28 @@ class TestContainerPaths(Base):
recurse_path('') recurse_path('')
for file_item in self.env.stored_files: for file_item in self.env.stored_files:
if file_item.startswith('/'): if file_item.startswith('/'):
self.assert_(file_item not in found_dirs) self.assertTrue(file_item not in found_dirs)
self.assert_(file_item not in found_files) self.assertTrue(file_item not in found_files)
elif file_item.endswith('/'): elif file_item.endswith('/'):
self.assert_(file_item in found_dirs) self.assertTrue(file_item in found_dirs)
self.assert_(file_item not in found_files) self.assertTrue(file_item not in found_files)
else: else:
self.assert_(file_item in found_files) self.assertTrue(file_item in found_files)
self.assert_(file_item not in found_dirs) self.assertTrue(file_item not in found_dirs)
found_files = [] found_files = []
found_dirs = [] found_dirs = []
recurse_path('/') recurse_path('/')
for file_item in self.env.stored_files: for file_item in self.env.stored_files:
if not file_item.startswith('/'): if not file_item.startswith('/'):
self.assert_(file_item not in found_dirs) self.assertTrue(file_item not in found_dirs)
self.assert_(file_item not in found_files) self.assertTrue(file_item not in found_files)
elif file_item.endswith('/'): elif file_item.endswith('/'):
self.assert_(file_item in found_dirs) self.assertTrue(file_item in found_dirs)
self.assert_(file_item not in found_files) self.assertTrue(file_item not in found_files)
else: else:
self.assert_(file_item in found_files) self.assertTrue(file_item in found_files)
self.assert_(file_item not in found_dirs) self.assertTrue(file_item not in found_dirs)
def testContainerListing(self): def testContainerListing(self):
for format_type in (None, 'json', 'xml'): for format_type in (None, 'json', 'xml'):
@ -780,8 +782,8 @@ class TestContainerPaths(Base):
for format_type in ('json', 'xml'): for format_type in ('json', 'xml'):
for file_item in self.env.container.files(parms={'format': for file_item in self.env.container.files(parms={'format':
format_type}): format_type}):
self.assert_(int(file_item['bytes']) >= 0) self.assertTrue(int(file_item['bytes']) >= 0)
self.assert_('last_modified' in file_item) self.assertTrue('last_modified' in file_item)
if file_item['name'].endswith('/'): if file_item['name'].endswith('/'):
self.assertEqual(file_item['content_type'], self.assertEqual(file_item['content_type'],
'application/directory') 'application/directory')
@ -880,7 +882,7 @@ class TestFile(Base):
file_item.sync_metadata(metadata) file_item.sync_metadata(metadata)
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
# copy both from within and across containers # copy both from within and across containers
for cont in (self.env.container, dest_cont): for cont in (self.env.container, dest_cont):
@ -891,13 +893,13 @@ class TestFile(Base):
file_item = self.env.container.file(source_filename) file_item = self.env.container.file(source_filename)
file_item.copy('%s%s' % (prefix, cont), dest_filename) file_item.copy('%s%s' % (prefix, cont), dest_filename)
self.assert_(dest_filename in cont.files()) self.assertTrue(dest_filename in cont.files())
file_item = cont.file(dest_filename) file_item = cont.file(dest_filename)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_(metadata == file_item.metadata) self.assertTrue(metadata == file_item.metadata)
def testCopyAccount(self): def testCopyAccount(self):
# makes sure to test encoded characters # makes sure to test encoded characters
@ -910,7 +912,7 @@ class TestFile(Base):
file_item.sync_metadata(metadata) file_item.sync_metadata(metadata)
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
acct = self.env.conn.account_name acct = self.env.conn.account_name
# copy both from within and across containers # copy both from within and across containers
@ -924,16 +926,16 @@ class TestFile(Base):
'%s%s' % (prefix, cont), '%s%s' % (prefix, cont),
dest_filename) dest_filename)
self.assert_(dest_filename in cont.files()) self.assertTrue(dest_filename in cont.files())
file_item = cont.file(dest_filename) file_item = cont.file(dest_filename)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_(metadata == file_item.metadata) self.assertTrue(metadata == file_item.metadata)
dest_cont = self.env.account2.container(Utils.create_name()) dest_cont = self.env.account2.container(Utils.create_name())
self.assert_(dest_cont.create(hdrs={ self.assertTrue(dest_cont.create(hdrs={
'X-Container-Write': self.env.conn.user_acl 'X-Container-Write': self.env.conn.user_acl
})) }))
@ -947,13 +949,13 @@ class TestFile(Base):
'%s%s' % (prefix, dest_cont), '%s%s' % (prefix, dest_cont),
dest_filename) dest_filename)
self.assert_(dest_filename in dest_cont.files()) self.assertTrue(dest_filename in dest_cont.files())
file_item = dest_cont.file(dest_filename) file_item = dest_cont.file(dest_filename)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_(metadata == file_item.metadata) self.assertTrue(metadata == file_item.metadata)
def testCopy404s(self): def testCopy404s(self):
source_filename = Utils.create_name() source_filename = Utils.create_name()
@ -961,35 +963,36 @@ class TestFile(Base):
file_item.write_random() file_item.write_random()
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
for prefix in ('', '/'): for prefix in ('', '/'):
# invalid source container # invalid source container
source_cont = self.env.account.container(Utils.create_name()) source_cont = self.env.account.container(Utils.create_name())
file_item = source_cont.file(source_filename) file_item = source_cont.file(source_filename)
self.assert_(not file_item.copy( self.assertTrue(not file_item.copy(
'%s%s' % (prefix, self.env.container), '%s%s' % (prefix, self.env.container),
Utils.create_name())) Utils.create_name()))
self.assert_status(404) self.assert_status(404)
self.assert_(not file_item.copy('%s%s' % (prefix, dest_cont), self.assertTrue(not file_item.copy('%s%s' % (prefix, dest_cont),
Utils.create_name())) Utils.create_name()))
self.assert_status(404) self.assert_status(404)
# invalid source object # invalid source object
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
self.assert_(not file_item.copy( self.assertTrue(not file_item.copy(
'%s%s' % (prefix, self.env.container), '%s%s' % (prefix, self.env.container),
Utils.create_name())) Utils.create_name()))
self.assert_status(404) self.assert_status(404)
self.assert_(not file_item.copy('%s%s' % (prefix, dest_cont), self.assertTrue(not file_item.copy('%s%s' % (prefix, dest_cont),
Utils.create_name())) Utils.create_name()))
self.assert_status(404) self.assert_status(404)
# invalid destination container # invalid destination container
file_item = self.env.container.file(source_filename) file_item = self.env.container.file(source_filename)
self.assert_(not file_item.copy( self.assertTrue(
not file_item.copy(
'%s%s' % (prefix, Utils.create_name()), '%s%s' % (prefix, Utils.create_name()),
Utils.create_name())) Utils.create_name()))
@ -1001,11 +1004,11 @@ class TestFile(Base):
file_item.write_random() file_item.write_random()
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create(hdrs={ self.assertTrue(dest_cont.create(hdrs={
'X-Container-Read': self.env.conn2.user_acl 'X-Container-Read': self.env.conn2.user_acl
})) }))
dest_cont2 = self.env.account2.container(Utils.create_name()) dest_cont2 = self.env.account2.container(Utils.create_name())
self.assert_(dest_cont2.create(hdrs={ self.assertTrue(dest_cont2.create(hdrs={
'X-Container-Write': self.env.conn.user_acl, 'X-Container-Write': self.env.conn.user_acl,
'X-Container-Read': self.env.conn.user_acl 'X-Container-Read': self.env.conn.user_acl
})) }))
@ -1015,7 +1018,7 @@ class TestFile(Base):
# invalid source container # invalid source container
source_cont = self.env.account.container(Utils.create_name()) source_cont = self.env.account.container(Utils.create_name())
file_item = source_cont.file(source_filename) file_item = source_cont.file(source_filename)
self.assert_(not file_item.copy_account( self.assertTrue(not file_item.copy_account(
acct, acct,
'%s%s' % (prefix, self.env.container), '%s%s' % (prefix, self.env.container),
Utils.create_name())) Utils.create_name()))
@ -1026,7 +1029,7 @@ class TestFile(Base):
else: else:
self.assert_status(404) self.assert_status(404)
self.assert_(not file_item.copy_account( self.assertTrue(not file_item.copy_account(
acct, acct,
'%s%s' % (prefix, cont), '%s%s' % (prefix, cont),
Utils.create_name())) Utils.create_name()))
@ -1034,7 +1037,7 @@ class TestFile(Base):
# invalid source object # invalid source object
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
self.assert_(not file_item.copy_account( self.assertTrue(not file_item.copy_account(
acct, acct,
'%s%s' % (prefix, self.env.container), '%s%s' % (prefix, self.env.container),
Utils.create_name())) Utils.create_name()))
@ -1045,7 +1048,7 @@ class TestFile(Base):
else: else:
self.assert_status(404) self.assert_status(404)
self.assert_(not file_item.copy_account( self.assertTrue(not file_item.copy_account(
acct, acct,
'%s%s' % (prefix, cont), '%s%s' % (prefix, cont),
Utils.create_name())) Utils.create_name()))
@ -1053,7 +1056,7 @@ class TestFile(Base):
# invalid destination container # invalid destination container
file_item = self.env.container.file(source_filename) file_item = self.env.container.file(source_filename)
self.assert_(not file_item.copy_account( self.assertTrue(not file_item.copy_account(
acct, acct,
'%s%s' % (prefix, Utils.create_name()), '%s%s' % (prefix, Utils.create_name()),
Utils.create_name())) Utils.create_name()))
@ -1070,7 +1073,7 @@ class TestFile(Base):
file_item.write_random() file_item.write_random()
file_item = self.env.container.file(source_filename) file_item = self.env.container.file(source_filename)
self.assert_(not file_item.copy(Utils.create_name(), self.assertTrue(not file_item.copy(Utils.create_name(),
Utils.create_name(), Utils.create_name(),
cfg={'no_destination': True})) cfg={'no_destination': True}))
self.assert_status(412) self.assert_status(412)
@ -1081,7 +1084,7 @@ class TestFile(Base):
file_item.write_random() file_item.write_random()
# no slash # no slash
self.assert_(not file_item.copy(Utils.create_name(), self.assertTrue(not file_item.copy(Utils.create_name(),
Utils.create_name(), Utils.create_name(),
cfg={'destination': Utils.create_name()})) cfg={'destination': Utils.create_name()}))
self.assert_status(412) self.assert_status(412)
@ -1098,7 +1101,7 @@ class TestFile(Base):
data = file_item.write_random() data = file_item.write_random()
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
# copy both from within and across containers # copy both from within and across containers
for cont in (self.env.container, dest_cont): for cont in (self.env.container, dest_cont):
@ -1110,18 +1113,18 @@ class TestFile(Base):
file_item.write(hdrs={'X-Copy-From': '%s%s/%s' % ( file_item.write(hdrs={'X-Copy-From': '%s%s/%s' % (
prefix, self.env.container.name, source_filename)}) prefix, self.env.container.name, source_filename)})
self.assert_(dest_filename in cont.files()) self.assertTrue(dest_filename in cont.files())
file_item = cont.file(dest_filename) file_item = cont.file(dest_filename)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_(metadata == file_item.metadata) self.assertTrue(metadata == file_item.metadata)
def testCopyFromAccountHeader(self): def testCopyFromAccountHeader(self):
acct = self.env.conn.account_name acct = self.env.conn.account_name
src_cont = self.env.account.container(Utils.create_name()) src_cont = self.env.account.container(Utils.create_name())
self.assert_(src_cont.create(hdrs={ self.assertTrue(src_cont.create(hdrs={
'X-Container-Read': self.env.conn2.user_acl 'X-Container-Read': self.env.conn2.user_acl
})) }))
source_filename = Utils.create_name() source_filename = Utils.create_name()
@ -1135,9 +1138,9 @@ class TestFile(Base):
data = file_item.write_random() data = file_item.write_random()
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
dest_cont2 = self.env.account2.container(Utils.create_name()) dest_cont2 = self.env.account2.container(Utils.create_name())
self.assert_(dest_cont2.create(hdrs={ self.assertTrue(dest_cont2.create(hdrs={
'X-Container-Write': self.env.conn.user_acl 'X-Container-Write': self.env.conn.user_acl
})) }))
@ -1153,13 +1156,13 @@ class TestFile(Base):
src_cont.name, src_cont.name,
source_filename)}) source_filename)})
self.assert_(dest_filename in cont.files()) self.assertTrue(dest_filename in cont.files())
file_item = cont.file(dest_filename) file_item = cont.file(dest_filename)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_(metadata == file_item.metadata) self.assertTrue(metadata == file_item.metadata)
def testCopyFromHeader404s(self): def testCopyFromHeader404s(self):
source_filename = Utils.create_name() source_filename = Utils.create_name()
@ -1195,14 +1198,14 @@ class TestFile(Base):
def testCopyFromAccountHeader404s(self): def testCopyFromAccountHeader404s(self):
acct = self.env.conn2.account_name acct = self.env.conn2.account_name
src_cont = self.env.account2.container(Utils.create_name()) src_cont = self.env.account2.container(Utils.create_name())
self.assert_(src_cont.create(hdrs={ self.assertTrue(src_cont.create(hdrs={
'X-Container-Read': self.env.conn.user_acl 'X-Container-Read': self.env.conn.user_acl
})) }))
source_filename = Utils.create_name() source_filename = Utils.create_name()
file_item = src_cont.file(source_filename) file_item = src_cont.file(source_filename)
file_item.write_random() file_item.write_random()
dest_cont = self.env.account.container(Utils.create_name()) dest_cont = self.env.account.container(Utils.create_name())
self.assert_(dest_cont.create()) self.assertTrue(dest_cont.create())
for prefix in ('', '/'): for prefix in ('', '/'):
# invalid source container # invalid source container
@ -1245,7 +1248,7 @@ class TestFile(Base):
file_item = self.env.container.file('a' * l) file_item = self.env.container.file('a' * l)
if l <= limit: if l <= limit:
self.assert_(file_item.write()) self.assertTrue(file_item.write())
self.assert_status(201) self.assert_status(201)
else: else:
self.assertRaises(ResponseError, file_item.write) self.assertRaises(ResponseError, file_item.write)
@ -1260,16 +1263,16 @@ class TestFile(Base):
file_name = Utils.create_name(6) + '?' + Utils.create_name(6) file_name = Utils.create_name(6) + '?' + Utils.create_name(6)
file_item = self.env.container.file(file_name) file_item = self.env.container.file(file_name)
self.assert_(file_item.write(cfg={'no_path_quote': True})) self.assertTrue(file_item.write(cfg={'no_path_quote': True}))
self.assert_(file_name not in self.env.container.files()) self.assertTrue(file_name not in self.env.container.files())
self.assert_(file_name.split('?')[0] in self.env.container.files()) self.assertTrue(file_name.split('?')[0] in self.env.container.files())
def testDeleteThen404s(self): def testDeleteThen404s(self):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
self.assert_(file_item.write_random()) self.assertTrue(file_item.write_random())
self.assert_status(201) self.assert_status(201)
self.assert_(file_item.delete()) self.assertTrue(file_item.delete())
self.assert_status(204) self.assert_status(204)
file_item.metadata = {Utils.create_ascii_name(): Utils.create_name()} file_item.metadata = {Utils.create_ascii_name(): Utils.create_name()}
@ -1313,15 +1316,15 @@ class TestFile(Base):
file_item.metadata = metadata file_item.metadata = metadata
if i <= number_limit: if i <= number_limit:
self.assert_(file_item.write()) self.assertTrue(file_item.write())
self.assert_status(201) self.assert_status(201)
self.assert_(file_item.sync_metadata()) self.assertTrue(file_item.sync_metadata())
self.assert_status((201, 202)) self.assert_status((201, 202))
else: else:
self.assertRaises(ResponseError, file_item.write) self.assertRaises(ResponseError, file_item.write)
self.assert_status(400) self.assert_status(400)
file_item.metadata = {} file_item.metadata = {}
self.assert_(file_item.write()) self.assertTrue(file_item.write())
self.assert_status(201) self.assert_status(201)
file_item.metadata = metadata file_item.metadata = metadata
self.assertRaises(ResponseError, file_item.sync_metadata) self.assertRaises(ResponseError, file_item.sync_metadata)
@ -1332,7 +1335,7 @@ class TestFile(Base):
'zip': 'application/zip'} 'zip': 'application/zip'}
container = self.env.account.container(Utils.create_name()) container = self.env.account.container(Utils.create_name())
self.assert_(container.create()) self.assertTrue(container.create())
for i in file_types.keys(): for i in file_types.keys():
file_item = container.file(Utils.create_name() + '.' + i) file_item = container.file(Utils.create_name() + '.' + i)
@ -1358,7 +1361,8 @@ class TestFile(Base):
for i in range(0, file_length, range_size): for i in range(0, file_length, range_size):
range_string = 'bytes=%d-%d' % (i, i + range_size - 1) range_string = 'bytes=%d-%d' % (i, i + range_size - 1)
hdrs = {'Range': range_string} hdrs = {'Range': range_string}
self.assert_(data[i: i + range_size] == file_item.read(hdrs=hdrs), self.assertTrue(
data[i: i + range_size] == file_item.read(hdrs=hdrs),
range_string) range_string)
range_string = 'bytes=-%d' % (i) range_string = 'bytes=-%d' % (i)
@ -1376,7 +1380,8 @@ class TestFile(Base):
range_string = 'bytes=%d-' % (i) range_string = 'bytes=%d-' % (i)
hdrs = {'Range': range_string} hdrs = {'Range': range_string}
self.assert_(file_item.read(hdrs=hdrs) == data[i - file_length:], self.assertTrue(
file_item.read(hdrs=hdrs) == data[i - file_length:],
range_string) range_string)
range_string = 'bytes=%d-%d' % (file_length + 1000, file_length + 2000) range_string = 'bytes=%d-%d' % (file_length + 1000, file_length + 2000)
@ -1386,17 +1391,18 @@ class TestFile(Base):
range_string = 'bytes=%d-%d' % (file_length - 1000, file_length + 2000) range_string = 'bytes=%d-%d' % (file_length - 1000, file_length + 2000)
hdrs = {'Range': range_string} hdrs = {'Range': range_string}
self.assert_(file_item.read(hdrs=hdrs) == data[-1000:], range_string) self.assertTrue(
file_item.read(hdrs=hdrs) == data[-1000:], range_string)
hdrs = {'Range': '0-4'} hdrs = {'Range': '0-4'}
self.assert_(file_item.read(hdrs=hdrs) == data, range_string) self.assertTrue(file_item.read(hdrs=hdrs) == data, range_string)
# RFC 2616 14.35.1 # RFC 2616 14.35.1
# "If the entity is shorter than the specified suffix-length, the # "If the entity is shorter than the specified suffix-length, the
# entire entity-body is used." # entire entity-body is used."
range_string = 'bytes=-%d' % (file_length + 10) range_string = 'bytes=-%d' % (file_length + 10)
hdrs = {'Range': range_string} hdrs = {'Range': range_string}
self.assert_(file_item.read(hdrs=hdrs) == data, range_string) self.assertTrue(file_item.read(hdrs=hdrs) == data, range_string)
def testRangedGetsWithLWSinHeader(self): def testRangedGetsWithLWSinHeader(self):
#Skip this test until webob 1.2 can tolerate LWS in Range header. #Skip this test until webob 1.2 can tolerate LWS in Range header.
@ -1407,7 +1413,7 @@ class TestFile(Base):
for r in ('BYTES=0-999', 'bytes = 0-999', 'BYTES = 0 - 999', for r in ('BYTES=0-999', 'bytes = 0-999', 'BYTES = 0 - 999',
'bytes = 0 - 999', 'bytes=0 - 999', 'bytes=0-999 '): 'bytes = 0 - 999', 'bytes=0 - 999', 'bytes=0-999 '):
self.assert_(file_item.read(hdrs={'Range': r}) == data[0:1000]) self.assertTrue(file_item.read(hdrs={'Range': r}) == data[0:1000])
def testFileSizeLimit(self): def testFileSizeLimit(self):
limit = load_constraint('max_file_size') limit = load_constraint('max_file_size')
@ -1428,7 +1434,7 @@ class TestFile(Base):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
if i <= limit: if i <= limit:
self.assert_(timeout(tsecs, file_item.write, self.assertTrue(timeout(tsecs, file_item.write,
cfg={'set_content_length': i})) cfg={'set_content_length': i}))
else: else:
self.assertRaises(ResponseError, timeout, tsecs, self.assertRaises(ResponseError, timeout, tsecs,
@ -1445,9 +1451,9 @@ class TestFile(Base):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
file_item.write_random(self.env.file_size) file_item.write_random(self.env.file_size)
self.assert_(file_item.name in self.env.container.files()) self.assertTrue(file_item.name in self.env.container.files())
self.assert_(file_item.delete()) self.assertTrue(file_item.delete())
self.assert_(file_item.name not in self.env.container.files()) self.assertTrue(file_item.name not in self.env.container.files())
def testBadHeaders(self): def testBadHeaders(self):
file_length = 100 file_length = 100
@ -1481,7 +1487,8 @@ class TestFile(Base):
self.assert_status(405) self.assert_status(405)
# bad range headers # bad range headers
self.assert_(len(file_item.read(hdrs={'Range': 'parsecs=8-12'})) == self.assertTrue(
len(file_item.read(hdrs={'Range': 'parsecs=8-12'})) ==
file_length) file_length)
self.assert_status(200) self.assert_status(200)
@ -1499,14 +1506,14 @@ class TestFile(Base):
file_item.metadata = metadata file_item.metadata = metadata
if l[0] <= key_limit and l[1] <= value_limit: if l[0] <= key_limit and l[1] <= value_limit:
self.assert_(file_item.write()) self.assertTrue(file_item.write())
self.assert_status(201) self.assert_status(201)
self.assert_(file_item.sync_metadata()) self.assertTrue(file_item.sync_metadata())
else: else:
self.assertRaises(ResponseError, file_item.write) self.assertRaises(ResponseError, file_item.write)
self.assert_status(400) self.assert_status(400)
file_item.metadata = {} file_item.metadata = {}
self.assert_(file_item.write()) self.assertTrue(file_item.write())
self.assert_status(201) self.assert_status(201)
file_item.metadata = metadata file_item.metadata = metadata
self.assertRaises(ResponseError, file_item.sync_metadata) self.assertRaises(ResponseError, file_item.sync_metadata)
@ -1523,7 +1530,7 @@ class TestFile(Base):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
data = file_item.write_random() data = file_item.write_random()
self.assert_status(201) self.assert_status(201)
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
self.assert_status(200) self.assert_status(200)
def testHead(self): def testHead(self):
@ -1543,7 +1550,7 @@ class TestFile(Base):
self.assertEqual(info['content_length'], self.env.file_size) self.assertEqual(info['content_length'], self.env.file_size)
self.assertEqual(info['etag'], md5) self.assertEqual(info['etag'], md5)
self.assertEqual(info['content_type'], content_type) self.assertEqual(info['content_type'], content_type)
self.assert_('last_modified' in info) self.assertTrue('last_modified' in info)
def testDeleteOfFileThatDoesNotExist(self): def testDeleteOfFileThatDoesNotExist(self):
# in container that exists # in container that exists
@ -1579,11 +1586,11 @@ class TestFile(Base):
metadata[Utils.create_ascii_name()] = Utils.create_name() metadata[Utils.create_ascii_name()] = Utils.create_name()
file_item.metadata = metadata file_item.metadata = metadata
self.assert_(file_item.sync_metadata()) self.assertTrue(file_item.sync_metadata())
self.assert_status((201, 202)) self.assert_status((201, 202))
file_item = self.env.container.file(file_item.name) file_item = self.env.container.file(file_item.name)
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_status(200) self.assert_status(200)
self.assertEqual(file_item.metadata, metadata) self.assertEqual(file_item.metadata, metadata)
@ -1637,13 +1644,13 @@ class TestFile(Base):
file_item.write_random(self.env.file_size) file_item.write_random(self.env.file_size)
file_item = self.env.container.file(file_item.name) file_item = self.env.container.file(file_item.name)
self.assert_(file_item.initialize()) self.assertTrue(file_item.initialize())
self.assert_status(200) self.assert_status(200)
self.assertEqual(file_item.metadata, metadata) self.assertEqual(file_item.metadata, metadata)
def testSerialization(self): def testSerialization(self):
container = self.env.account.container(Utils.create_name()) container = self.env.account.container(Utils.create_name())
self.assert_(container.create()) self.assertTrue(container.create())
files = [] files = []
for i in (0, 1, 10, 100, 1000, 10000): for i in (0, 1, 10, 100, 1000, 10000):
@ -1685,7 +1692,8 @@ class TestFile(Base):
f[format_type] = True f[format_type] = True
found = True found = True
self.assert_(found, 'Unexpected file %s found in ' self.assertTrue(
found, 'Unexpected file %s found in '
'%s listing' % (file_item['name'], format_type)) '%s listing' % (file_item['name'], format_type))
headers = dict(self.env.conn.response.getheaders()) headers = dict(self.env.conn.response.getheaders())
@ -1698,12 +1706,14 @@ class TestFile(Base):
lm_diff = max([f['last_modified'] for f in files]) -\ lm_diff = max([f['last_modified'] for f in files]) -\
min([f['last_modified'] for f in files]) min([f['last_modified'] for f in files])
self.assert_(lm_diff < write_time + 1, 'Diff in last ' self.assertTrue(
lm_diff < write_time + 1, 'Diff in last '
'modified times should be less than time to write files') 'modified times should be less than time to write files')
for f in files: for f in files:
for format_type in ['json', 'xml']: for format_type in ['json', 'xml']:
self.assert_(f[format_type], 'File %s not found in %s listing' self.assertTrue(
f[format_type], 'File %s not found in %s listing'
% (f['name'], format_type)) % (f['name'], format_type))
def testStackedOverwrite(self): def testStackedOverwrite(self):
@ -1713,7 +1723,7 @@ class TestFile(Base):
data = file_item.write_random(512) data = file_item.write_random(512)
file_item.write(data) file_item.write(data)
self.assert_(file_item.read() == data) self.assertTrue(file_item.read() == data)
def testTooLongName(self): def testTooLongName(self):
file_item = self.env.container.file('x' * 1025) file_item = self.env.container.file('x' * 1025)
@ -1723,9 +1733,9 @@ class TestFile(Base):
def testZeroByteFile(self): def testZeroByteFile(self):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
self.assert_(file_item.write('')) self.assertTrue(file_item.write(''))
self.assert_(file_item.name in self.env.container.files()) self.assertTrue(file_item.name in self.env.container.files())
self.assert_(file_item.read() == '') self.assertTrue(file_item.read() == '')
def testEtagResponse(self): def testEtagResponse(self):
file_item = self.env.container.file(Utils.create_name()) file_item = self.env.container.file(Utils.create_name())
@ -1734,7 +1744,7 @@ class TestFile(Base):
etag = File.compute_md5sum(data) etag = File.compute_md5sum(data)
headers = dict(self.env.conn.response.getheaders()) headers = dict(self.env.conn.response.getheaders())
self.assert_('etag' in headers.keys()) self.assertTrue('etag' in headers.keys())
header_etag = headers['etag'].strip('"') header_etag = headers['etag'].strip('"')
self.assertEqual(etag, header_etag) self.assertEqual(etag, header_etag)
@ -1759,8 +1769,8 @@ class TestFile(Base):
for j in chunks(data, i): for j in chunks(data, i):
file_item.chunked_write(j) file_item.chunked_write(j)
self.assert_(file_item.chunked_write()) self.assertTrue(file_item.chunked_write())
self.assert_(data == file_item.read()) self.assertTrue(data == file_item.read())
info = file_item.info() info = file_item.info()
self.assertEqual(etag, info['etag']) self.assertEqual(etag, info['etag'])
@ -2016,7 +2026,7 @@ class TestFileComparison(Base):
def testIfMatch(self): def testIfMatch(self):
for file_item in self.env.files: for file_item in self.env.files:
hdrs = {'If-Match': file_item.md5} hdrs = {'If-Match': file_item.md5}
self.assert_(file_item.read(hdrs=hdrs)) self.assertTrue(file_item.read(hdrs=hdrs))
hdrs = {'If-Match': 'bogus'} hdrs = {'If-Match': 'bogus'}
self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assertRaises(ResponseError, file_item.read, hdrs=hdrs)
@ -2025,7 +2035,7 @@ class TestFileComparison(Base):
def testIfNoneMatch(self): def testIfNoneMatch(self):
for file_item in self.env.files: for file_item in self.env.files:
hdrs = {'If-None-Match': 'bogus'} hdrs = {'If-None-Match': 'bogus'}
self.assert_(file_item.read(hdrs=hdrs)) self.assertTrue(file_item.read(hdrs=hdrs))
hdrs = {'If-None-Match': file_item.md5} hdrs = {'If-None-Match': file_item.md5}
self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assertRaises(ResponseError, file_item.read, hdrs=hdrs)
@ -2034,8 +2044,8 @@ class TestFileComparison(Base):
def testIfModifiedSince(self): def testIfModifiedSince(self):
for file_item in self.env.files: for file_item in self.env.files:
hdrs = {'If-Modified-Since': self.env.time_old_f1} hdrs = {'If-Modified-Since': self.env.time_old_f1}
self.assert_(file_item.read(hdrs=hdrs)) self.assertTrue(file_item.read(hdrs=hdrs))
self.assert_(file_item.info(hdrs=hdrs)) self.assertTrue(file_item.info(hdrs=hdrs))
hdrs = {'If-Modified-Since': self.env.time_new} hdrs = {'If-Modified-Since': self.env.time_new}
self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assertRaises(ResponseError, file_item.read, hdrs=hdrs)
@ -2046,8 +2056,8 @@ class TestFileComparison(Base):
def testIfUnmodifiedSince(self): def testIfUnmodifiedSince(self):
for file_item in self.env.files: for file_item in self.env.files:
hdrs = {'If-Unmodified-Since': self.env.time_new} hdrs = {'If-Unmodified-Since': self.env.time_new}
self.assert_(file_item.read(hdrs=hdrs)) self.assertTrue(file_item.read(hdrs=hdrs))
self.assert_(file_item.info(hdrs=hdrs)) self.assertTrue(file_item.info(hdrs=hdrs))
hdrs = {'If-Unmodified-Since': self.env.time_old_f2} hdrs = {'If-Unmodified-Since': self.env.time_old_f2}
self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assertRaises(ResponseError, file_item.read, hdrs=hdrs)
@ -2059,7 +2069,7 @@ class TestFileComparison(Base):
for file_item in self.env.files: for file_item in self.env.files:
hdrs = {'If-Match': file_item.md5, hdrs = {'If-Match': file_item.md5,
'If-Unmodified-Since': self.env.time_new} 'If-Unmodified-Since': self.env.time_new}
self.assert_(file_item.read(hdrs=hdrs)) self.assertTrue(file_item.read(hdrs=hdrs))
hdrs = {'If-Match': 'bogus', hdrs = {'If-Match': 'bogus',
'If-Unmodified-Since': self.env.time_new} 'If-Unmodified-Since': self.env.time_new}
@ -2082,7 +2092,7 @@ class TestFileComparison(Base):
file = self.env.container.file(file_name) file = self.env.container.file(file_name)
info = file.info() info = file.info()
self.assert_('last_modified' in info) self.assertTrue('last_modified' in info)
last_modified = info['last_modified'] last_modified = info['last_modified']
self.assertEqual(put_last_modified, info['last_modified']) self.assertEqual(put_last_modified, info['last_modified'])
@ -2091,7 +2101,7 @@ class TestFileComparison(Base):
self.assert_status(304) self.assert_status(304)
hdrs = {'If-Unmodified-Since': last_modified} hdrs = {'If-Unmodified-Since': last_modified}
self.assert_(file.read(hdrs=hdrs)) self.assertTrue(file.read(hdrs=hdrs))
class TestFileComparisonUTF8(Base2, TestFileComparison): class TestFileComparisonUTF8(Base2, TestFileComparison):
@ -2384,7 +2394,7 @@ class TestSlo(Base):
# copy to different account # copy to different account
acct = self.env.conn2.account_name acct = self.env.conn2.account_name
dest_cont = self.env.account2.container(Utils.create_name()) dest_cont = self.env.account2.container(Utils.create_name())
self.assert_(dest_cont.create(hdrs={ self.assertTrue(dest_cont.create(hdrs={
'X-Container-Write': self.env.conn.user_acl 'X-Container-Write': self.env.conn.user_acl
})) }))
file_item = self.env.container.file("manifest-abcde") file_item = self.env.container.file("manifest-abcde")
@ -2425,7 +2435,7 @@ class TestSlo(Base):
# different account # different account
acct = self.env.conn2.account_name acct = self.env.conn2.account_name
dest_cont = self.env.account2.container(Utils.create_name()) dest_cont = self.env.account2.container(Utils.create_name())
self.assert_(dest_cont.create(hdrs={ self.assertTrue(dest_cont.create(hdrs={
'X-Container-Write': self.env.conn.user_acl 'X-Container-Write': self.env.conn.user_acl
})) }))
file_item.copy_account(acct, file_item.copy_account(acct,
@ -2880,7 +2890,7 @@ class TestTempurl(Base):
self.assertEqual(contents, "obj contents") self.assertEqual(contents, "obj contents")
# GET tempurls also allow HEAD requests # GET tempurls also allow HEAD requests
self.assert_(self.env.obj.info(parms=self.obj_tempurl_parms, self.assertTrue(self.env.obj.info(parms=self.obj_tempurl_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
def test_GET_with_key_2(self): def test_GET_with_key_2(self):
@ -2909,7 +2919,7 @@ class TestTempurl(Base):
self.assertEqual(new_obj.read(), "new obj contents") self.assertEqual(new_obj.read(), "new obj contents")
# PUT tempurls also allow HEAD requests # PUT tempurls also allow HEAD requests
self.assert_(new_obj.info(parms=put_parms, self.assertTrue(new_obj.info(parms=put_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
def test_HEAD(self): def test_HEAD(self):
@ -2920,7 +2930,7 @@ class TestTempurl(Base):
head_parms = {'temp_url_sig': sig, head_parms = {'temp_url_sig': sig,
'temp_url_expires': str(expires)} 'temp_url_expires': str(expires)}
self.assert_(self.env.obj.info(parms=head_parms, self.assertTrue(self.env.obj.info(parms=head_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
# HEAD tempurls don't allow PUT or GET requests, despite the fact that # HEAD tempurls don't allow PUT or GET requests, despite the fact that
# PUT and GET tempurls both allow HEAD requests # PUT and GET tempurls both allow HEAD requests
@ -3064,7 +3074,7 @@ class TestContainerTempurl(Base):
self.assertEqual(contents, "obj contents") self.assertEqual(contents, "obj contents")
# GET tempurls also allow HEAD requests # GET tempurls also allow HEAD requests
self.assert_(self.env.obj.info(parms=self.obj_tempurl_parms, self.assertTrue(self.env.obj.info(parms=self.obj_tempurl_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
def test_GET_with_key_2(self): def test_GET_with_key_2(self):
@ -3093,7 +3103,7 @@ class TestContainerTempurl(Base):
self.assertEqual(new_obj.read(), "new obj contents") self.assertEqual(new_obj.read(), "new obj contents")
# PUT tempurls also allow HEAD requests # PUT tempurls also allow HEAD requests
self.assert_(new_obj.info(parms=put_parms, self.assertTrue(new_obj.info(parms=put_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
def test_HEAD(self): def test_HEAD(self):
@ -3104,7 +3114,7 @@ class TestContainerTempurl(Base):
head_parms = {'temp_url_sig': sig, head_parms = {'temp_url_sig': sig,
'temp_url_expires': str(expires)} 'temp_url_expires': str(expires)}
self.assert_(self.env.obj.info(parms=head_parms, self.assertTrue(self.env.obj.info(parms=head_parms,
cfg={'no_auth_token': True})) cfg={'no_auth_token': True}))
# HEAD tempurls don't allow PUT or GET requests, despite the fact that # HEAD tempurls don't allow PUT or GET requests, despite the fact that
# PUT and GET tempurls both allow HEAD requests # PUT and GET tempurls both allow HEAD requests
@ -3272,7 +3282,7 @@ class TestSloTempurl(Base):
self.assertEqual(len(contents), 2 * 1024 * 1024) self.assertEqual(len(contents), 2 * 1024 * 1024)
# GET tempurls also allow HEAD requests # GET tempurls also allow HEAD requests
self.assert_(self.env.manifest.info( self.assertTrue(self.env.manifest.info(
parms=parms, cfg={'no_auth_token': True})) parms=parms, cfg={'no_auth_token': True}))
@ -3379,8 +3389,6 @@ class TestServiceToken(unittest.TestCase):
headers = {} headers = {}
if self.body: if self.body:
headers.update({'Content-Length': len(self.body)}) headers.update({'Content-Length': len(self.body)})
if self.headers:
headers.update(self.headers)
if self.x_auth_token == self.SET_TO_USERS_TOKEN: if self.x_auth_token == self.SET_TO_USERS_TOKEN:
headers.update({'X-Auth-Token': token}) headers.update({'X-Auth-Token': token})
elif self.x_auth_token == self.SET_TO_SERVICE_TOKEN: elif self.x_auth_token == self.SET_TO_SERVICE_TOKEN:
@ -3413,7 +3421,7 @@ class TestServiceToken(unittest.TestCase):
self.prepare_request('HEAD') self.prepare_request('HEAD')
resp = retry(self.do_request) resp = retry(self.do_request)
resp.read() resp.read()
self.assert_(resp.status in (200, 204), resp.status) self.assertTrue(resp.status in (200, 204), resp.status)
def test_user_cannot_access_service_account(self): def test_user_cannot_access_service_account(self):
for method, container, obj in self._scenario_generator(): for method, container, obj in self._scenario_generator():

View File

@ -49,8 +49,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 0) self.assertEquals(container['count'], 0)
self.assertEquals(container['bytes'], 0) self.assertEquals(container['bytes'], 0)
self.assert_(found1) self.assertTrue(found1)
self.assert_(found2) self.assertTrue(found2)
# Create container2/object1 # Create container2/object1
client.put_object(self.url, self.token, container2, 'object1', '1234') client.put_object(self.url, self.token, container2, 'object1', '1234')
@ -71,8 +71,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 0) self.assertEquals(container['count'], 0)
self.assertEquals(container['bytes'], 0) self.assertEquals(container['bytes'], 0)
self.assert_(found1) self.assertTrue(found1)
self.assert_(found2) self.assertTrue(found2)
# Get to final state # Get to final state
self.get_to_final_state() self.get_to_final_state()
@ -93,8 +93,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 1) self.assertEquals(container['count'], 1)
self.assertEquals(container['bytes'], 4) self.assertEquals(container['bytes'], 4)
self.assert_(found1) self.assertTrue(found1)
self.assert_(found2) self.assertTrue(found2)
apart, anodes = self.account_ring.get_nodes(self.account) apart, anodes = self.account_ring.get_nodes(self.account)
kill_nonprimary_server(anodes, self.ipport2server, self.pids) kill_nonprimary_server(anodes, self.ipport2server, self.pids)
@ -123,8 +123,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 1) self.assertEquals(container['count'], 1)
self.assertEquals(container['bytes'], 4) self.assertEquals(container['bytes'], 4)
self.assert_(not found1) self.assertTrue(not found1)
self.assert_(found2) self.assertTrue(found2)
# Run container updaters # Run container updaters
Manager(['container-updater']).once() Manager(['container-updater']).once()
@ -143,8 +143,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 2) self.assertEquals(container['count'], 2)
self.assertEquals(container['bytes'], 9) self.assertEquals(container['bytes'], 9)
self.assert_(not found1) self.assertTrue(not found1)
self.assert_(found2) self.assertTrue(found2)
# Restart other primary account server # Restart other primary account server
start_server((anodes[0]['ip'], anodes[0]['port']), start_server((anodes[0]['ip'], anodes[0]['port']),
@ -166,8 +166,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 1) self.assertEquals(container['count'], 1)
self.assertEquals(container['bytes'], 4) self.assertEquals(container['bytes'], 4)
self.assert_(found1) self.assertTrue(found1)
self.assert_(found2) self.assertTrue(found2)
# Get to final state # Get to final state
self.get_to_final_state() self.get_to_final_state()
@ -187,8 +187,8 @@ class TestAccountFailures(ReplProbeTest):
found2 = True found2 = True
self.assertEquals(container['count'], 2) self.assertEquals(container['count'], 2)
self.assertEquals(container['bytes'], 9) self.assertEquals(container['bytes'], 9)
self.assert_(not found1) self.assertTrue(not found1)
self.assert_(found2) self.assertTrue(found2)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -65,7 +65,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
found_policy_indexes = \ found_policy_indexes = \
set(metadata['X-Backend-Storage-Policy-Index'] for set(metadata['X-Backend-Storage-Policy-Index'] for
node, metadata in head_responses) node, metadata in head_responses)
self.assert_(len(found_policy_indexes) > 1, self.assertTrue(
len(found_policy_indexes) > 1,
'primary nodes did not disagree about policy index %r' % 'primary nodes did not disagree about policy index %r' %
head_responses) head_responses)
# find our object # find our object
@ -102,7 +103,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
found_policy_indexes = \ found_policy_indexes = \
set(metadata['X-Backend-Storage-Policy-Index'] for set(metadata['X-Backend-Storage-Policy-Index'] for
node, metadata in head_responses) node, metadata in head_responses)
self.assert_(len(found_policy_indexes) == 1, self.assertTrue(len(found_policy_indexes) == 1,
'primary nodes disagree about policy index %r' % 'primary nodes disagree about policy index %r' %
head_responses) head_responses)
@ -165,7 +166,8 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
found_policy_indexes = \ found_policy_indexes = \
set(metadata['X-Backend-Storage-Policy-Index'] for set(metadata['X-Backend-Storage-Policy-Index'] for
node, metadata in head_responses) node, metadata in head_responses)
self.assert_(len(found_policy_indexes) > 1, self.assertTrue(
len(found_policy_indexes) > 1,
'primary nodes did not disagree about policy index %r' % 'primary nodes did not disagree about policy index %r' %
head_responses) head_responses)
# find our object # find our object
@ -207,7 +209,7 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
new_found_policy_indexes = \ new_found_policy_indexes = \
set(metadata['X-Backend-Storage-Policy-Index'] for node, set(metadata['X-Backend-Storage-Policy-Index'] for node,
metadata in head_responses) metadata in head_responses)
self.assert_(len(new_found_policy_indexes) == 1, self.assertTrue(len(new_found_policy_indexes) == 1,
'primary nodes disagree about policy index %r' % 'primary nodes disagree about policy index %r' %
dict((node['port'], dict((node['port'],
metadata['X-Backend-Storage-Policy-Index']) metadata['X-Backend-Storage-Policy-Index'])

View File

@ -54,7 +54,7 @@ class TestObjectAsyncUpdate(ReplProbeTest):
self.ipport2server, self.pids) self.ipport2server, self.pids)
# Assert it does not know about container/obj # Assert it does not know about container/obj
self.assert_(not direct_client.direct_get_container( self.assertTrue(not direct_client.direct_get_container(
cnode, cpart, self.account, container)[1]) cnode, cpart, self.account, container)[1])
# Run the object-updaters # Run the object-updaters
@ -63,7 +63,7 @@ class TestObjectAsyncUpdate(ReplProbeTest):
# Assert the other primary server now knows about container/obj # Assert the other primary server now knows about container/obj
objs = [o['name'] for o in direct_client.direct_get_container( objs = [o['name'] for o in direct_client.direct_get_container(
cnode, cpart, self.account, container)[1]] cnode, cpart, self.account, container)[1]]
self.assert_(obj in objs) self.assertTrue(obj in objs)
class TestUpdateOverrides(ReplProbeTest): class TestUpdateOverrides(ReplProbeTest):

View File

@ -87,7 +87,7 @@ class TestObjectExpirer(ReplProbeTest):
self.account, self.container_name, self.object_name, self.account, self.container_name, self.object_name,
acceptable_statuses=(4,), acceptable_statuses=(4,),
headers={'X-Backend-Storage-Policy-Index': int(old_policy)}) headers={'X-Backend-Storage-Policy-Index': int(old_policy)})
self.assert_('x-backend-timestamp' in metadata) self.assertTrue('x-backend-timestamp' in metadata)
self.assertEqual(Timestamp(metadata['x-backend-timestamp']), self.assertEqual(Timestamp(metadata['x-backend-timestamp']),
create_timestamp) create_timestamp)
@ -122,8 +122,8 @@ class TestObjectExpirer(ReplProbeTest):
self.fail('found object in %s and also %s' % self.fail('found object in %s and also %s' %
(found_in_policy, policy)) (found_in_policy, policy))
found_in_policy = policy found_in_policy = policy
self.assert_('x-backend-timestamp' in metadata) self.assertTrue('x-backend-timestamp' in metadata)
self.assert_(Timestamp(metadata['x-backend-timestamp']) > self.assertTrue(Timestamp(metadata['x-backend-timestamp']) >
create_timestamp) create_timestamp)
if __name__ == "__main__": if __name__ == "__main__":