Fix order of arguments in assertEqual

Some tests used incorrect order assertEqual(observed, expected).
The correct order expected by testtools is
assertEqual(expected, observed).

This patch does not cover v1 api tests and vendor unit tets.

Change-Id: Icb0636143cfc48d5189bcb0faa6e643f68c32f5e
Partial-Bug: #1259292
This commit is contained in:
appsdesh 2015-07-27 21:23:36 -07:00 committed by apoorvad
parent 94e3098238
commit 4982812364
48 changed files with 941 additions and 952 deletions

View File

@ -130,9 +130,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'attach_status': 'attached'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['attach_status'], 'attached')
self.assertEqual('attached', volume['attach_status'])
def test_reset_attach_invalid_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -142,9 +142,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'attach_status': 'bogus-status'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['attach_status'], 'detached')
self.assertEqual('detached', volume['attach_status'])
def test_reset_migration_invalid_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -154,9 +154,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'migration_status': 'bogus-status'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['migration_status'], None)
self.assertEqual(None, volume['migration_status'])
def test_reset_migration_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -166,9 +166,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'migration_status': 'migrating'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['migration_status'], 'migrating')
self.assertEqual('migrating', volume['migration_status'])
def test_reset_status_as_admin(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -178,9 +178,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'status': 'error'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'error')
self.assertEqual('error', volume['status'])
def test_reset_status_as_non_admin(self):
ctx = context.RequestContext('fake', 'fake')
@ -192,10 +192,10 @@ class AdminActionsTest(test.TestCase):
{'status': 'error'})
# request is not authorized
self.assertEqual(resp.status_int, 403)
self.assertEqual(403, resp.status_int)
volume = db.volume_get(context.get_admin_context(), volume['id'])
# status is still 'error'
self.assertEqual(volume['status'], 'error')
self.assertEqual('error', volume['status'])
def test_backup_reset_status_as_admin(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -212,7 +212,7 @@ class AdminActionsTest(test.TestCase):
backup,
{'status': 'error'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
def test_backup_reset_status_as_non_admin(self):
ctx = context.RequestContext('fake', 'fake')
@ -223,7 +223,7 @@ class AdminActionsTest(test.TestCase):
backup,
{'status': 'error'})
# request is not authorized
self.assertEqual(resp.status_int, 403)
self.assertEqual(403, resp.status_int)
def test_backup_reset_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -238,7 +238,7 @@ class AdminActionsTest(test.TestCase):
backup,
{'status': 'error'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
def test_invalid_status_for_backup(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -249,7 +249,7 @@ class AdminActionsTest(test.TestCase):
resp = self._issue_backup_reset(ctx,
backup,
{'status': 'restoring'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
def test_backup_reset_status_with_invalid_backup(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -276,9 +276,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'x-status': 'bad'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'available')
self.assertEqual('available', volume['status'])
def test_invalid_status_for_volume(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -287,9 +287,9 @@ class AdminActionsTest(test.TestCase):
volume,
{'status': 'invalid'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'available')
self.assertEqual('available', volume['status'])
def test_reset_status_for_missing_volume(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -301,7 +301,7 @@ class AdminActionsTest(test.TestCase):
'available'}})
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
self.assertEqual(resp.status_int, 404)
self.assertEqual(404, resp.status_int)
self.assertRaises(exception.NotFound, db.volume_get, ctx,
'missing-volume-id')
@ -316,10 +316,10 @@ class AdminActionsTest(test.TestCase):
{'status': 'available',
'attach_status': 'detached'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['attach_status'], 'detached')
self.assertEqual(volume['status'], 'available')
self.assertEqual('detached', volume['attach_status'])
self.assertEqual('available', volume['status'])
def test_invalid_reset_attached_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -330,10 +330,10 @@ class AdminActionsTest(test.TestCase):
volume,
{'status': 'available',
'attach_status': 'invalid'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'available')
self.assertEqual(volume['attach_status'], 'detached')
self.assertEqual('available', volume['status'])
self.assertEqual('detached', volume['attach_status'])
def test_snapshot_reset_status(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -358,9 +358,9 @@ class AdminActionsTest(test.TestCase):
snapshot,
{'status': 'error'})
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
snapshot = objects.Snapshot.get_by_id(ctx, snapshot['id'])
self.assertEqual(snapshot.status, 'error')
self.assertEqual('error', snapshot.status)
def test_invalid_status_for_snapshot(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -373,9 +373,9 @@ class AdminActionsTest(test.TestCase):
snapshot,
{'status': 'attaching'})
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
snapshot = db.snapshot_get(ctx, snapshot['id'])
self.assertEqual(snapshot['status'], 'available')
self.assertEqual('available', snapshot['status'])
def test_force_delete(self):
# admin context
@ -390,7 +390,7 @@ class AdminActionsTest(test.TestCase):
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
# request is accepted
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
# volume is deleted
self.assertRaises(exception.NotFound, db.volume_get, ctx, volume['id'])
@ -416,7 +416,7 @@ class AdminActionsTest(test.TestCase):
# attach admin context to request
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
def test_force_detach_instance_attached_volume(self):
# admin context
@ -433,16 +433,16 @@ class AdminActionsTest(test.TestCase):
None, mountpoint, 'rw')
# volume is attached
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'in-use')
self.assertEqual(attachment['instance_uuid'], stubs.FAKE_UUID)
self.assertEqual('in-use', volume['status'])
self.assertEqual(stubs.FAKE_UUID, attachment['instance_uuid'])
self.assertEqual(attachment['mountpoint'], mountpoint)
self.assertEqual(attachment['attach_status'], 'attached')
self.assertEqual('attached', attachment['attach_status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 2)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(admin_metadata[1]['key'], 'attached_mode')
self.assertEqual(admin_metadata[1]['value'], 'rw')
self.assertEqual(2, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'])
self.assertEqual('False', admin_metadata[0]['value'])
self.assertEqual('attached_mode', admin_metadata[1]['key'])
self.assertEqual('rw', admin_metadata[1]['value'])
conn_info = self.volume_api.initialize_connection(ctx,
volume,
connector)
@ -459,18 +459,18 @@ class AdminActionsTest(test.TestCase):
# make request
resp = req.get_response(app())
# request is accepted
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertRaises(exception.VolumeAttachmentNotFound,
db.volume_attachment_get,
ctx, attachment['id'])
# status changed to 'available'
self.assertEqual(volume['status'], 'available')
self.assertEqual('available', volume['status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 1)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(1, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'], 'readonly')
self.assertEqual('False', admin_metadata[0]['value'])
# cleanup
svc.stop()
@ -490,20 +490,20 @@ class AdminActionsTest(test.TestCase):
mountpoint, 'ro')
# volume is attached
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'in-use')
self.assertEqual('in-use', volume['status'])
self.assertIsNone(attachment['instance_uuid'])
self.assertEqual(attachment['attached_host'], host_name)
self.assertEqual(attachment['mountpoint'], mountpoint)
self.assertEqual(attachment['attach_status'], 'attached')
self.assertEqual('attached', attachment['attach_status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 2)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(admin_metadata[1]['key'], 'attached_mode')
self.assertEqual(admin_metadata[1]['value'], 'ro')
self.assertEqual(2, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'])
self.assertEqual('False', admin_metadata[0]['value'])
self.assertEqual('attached_mode', admin_metadata[1]['key'])
self.assertEqual('ro', admin_metadata[1]['value'])
conn_info = self.volume_api.initialize_connection(ctx,
volume, connector)
self.assertEqual(conn_info['data']['access_mode'], 'ro')
self.assertEqual('ro', conn_info['data']['access_mode'])
# build request to force detach
req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
req.method = 'POST'
@ -516,17 +516,17 @@ class AdminActionsTest(test.TestCase):
# make request
resp = req.get_response(app())
# request is accepted
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
volume = db.volume_get(ctx, volume['id'])
self.assertRaises(exception.VolumeAttachmentNotFound,
db.volume_attachment_get,
ctx, attachment['id'])
# status changed to 'available'
self.assertEqual(volume['status'], 'available')
self.assertEqual('available', volume['status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 1)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(1, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'])
self.assertEqual('False', admin_metadata[0]['value'])
# cleanup
svc.stop()
@ -545,20 +545,20 @@ class AdminActionsTest(test.TestCase):
None, mountpoint, 'rw')
# volume is attached
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'in-use')
self.assertEqual(attachment['instance_uuid'], stubs.FAKE_UUID)
self.assertEqual('in-use', volume['status'])
self.assertEqual(stubs.FAKE_UUID, attachment['instance_uuid'])
self.assertEqual(attachment['mountpoint'], mountpoint)
self.assertEqual(attachment['attach_status'], 'attached')
self.assertEqual('attached', attachment['attach_status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 2)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(admin_metadata[1]['key'], 'attached_mode')
self.assertEqual(admin_metadata[1]['value'], 'rw')
self.assertEqual(2, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'])
self.assertEqual('False', admin_metadata[0]['value'])
self.assertEqual('attached_mode', admin_metadata[1]['key'])
self.assertEqual('rw', admin_metadata[1]['value'])
conn_info = self.volume_api.initialize_connection(ctx,
volume,
connector)
self.assertEqual(conn_info['data']['access_mode'], 'rw')
self.assertEqual('rw', conn_info['data']['access_mode'])
# build request to force detach
volume_remote_error = \
messaging.RemoteError(exc_type='VolumeAttachmentNotFound')
@ -574,7 +574,7 @@ class AdminActionsTest(test.TestCase):
req.environ['cinder.context'] = ctx
# make request
resp = req.get_response(app())
self.assertEqual(resp.status_int, 400)
self.assertEqual(400, resp.status_int)
# cleanup
svc.stop()
@ -594,20 +594,20 @@ class AdminActionsTest(test.TestCase):
None, mountpoint, 'rw')
# volume is attached
volume = db.volume_get(ctx, volume['id'])
self.assertEqual(volume['status'], 'in-use')
self.assertEqual(attachment['instance_uuid'], stubs.FAKE_UUID)
self.assertEqual('in-use', volume['status'])
self.assertEqual(stubs.FAKE_UUID, attachment['instance_uuid'])
self.assertEqual(attachment['mountpoint'], mountpoint)
self.assertEqual(attachment['attach_status'], 'attached')
self.assertEqual('attached', attachment['attach_status'])
admin_metadata = volume['volume_admin_metadata']
self.assertEqual(len(admin_metadata), 2)
self.assertEqual(admin_metadata[0]['key'], 'readonly')
self.assertEqual(admin_metadata[0]['value'], 'False')
self.assertEqual(admin_metadata[1]['key'], 'attached_mode')
self.assertEqual(admin_metadata[1]['value'], 'rw')
self.assertEqual(2, len(admin_metadata))
self.assertEqual('readonly', admin_metadata[0]['key'])
self.assertEqual('False', admin_metadata[0]['value'])
self.assertEqual('attached_mode', admin_metadata[1]['key'])
self.assertEqual('rw', admin_metadata[1]['value'])
conn_info = self.volume_api.initialize_connection(ctx,
volume,
connector)
self.assertEqual(conn_info['data']['access_mode'], 'rw')
self.assertEqual('rw', conn_info['data']['access_mode'])
# build request to force detach
volume_remote_error = \
messaging.RemoteError(exc_type='DBError')
@ -643,7 +643,7 @@ class AdminActionsTest(test.TestCase):
volume, connector)
self.volume_api.attach(ctx, volume, fakes.get_fake_uuid(), None,
'/dev/vbd0', 'rw')
self.assertEqual(conn_info['data']['access_mode'], 'rw')
self.assertEqual('rw', conn_info['data']['access_mode'])
self.assertRaises(exception.InvalidVolume,
self.volume_api.attach,
ctx,
@ -784,7 +784,7 @@ class AdminActionsTest(test.TestCase):
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
# verify status
self.assertEqual(resp.status_int, expected_status)
self.assertEqual(expected_status, resp.status_int)
volume = db.volume_get(admin_ctx, volume['id'])
return volume
@ -794,7 +794,7 @@ class AdminActionsTest(test.TestCase):
ctx = context.RequestContext('admin', 'fake', True)
volume = self._migrate_volume_prep()
volume = self._migrate_volume_exec(ctx, volume, host, expected_status)
self.assertEqual(volume['migration_status'], 'starting')
self.assertEqual('starting', volume['migration_status'])
def test_migrate_volume_fail_replication(self):
expected_status = 400
@ -832,7 +832,7 @@ class AdminActionsTest(test.TestCase):
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
# verify status
self.assertEqual(resp.status_int, expected_status)
self.assertEqual(expected_status, resp.status_int)
def test_migrate_volume_host_no_exist(self):
expected_status = 400
@ -887,9 +887,9 @@ class AdminActionsTest(test.TestCase):
resp = req.get_response(app())
resp_dict = ast.literal_eval(resp.body)
# verify status
self.assertEqual(resp.status_int, expected_status)
self.assertEqual(expected_status, resp.status_int)
if expected_id:
self.assertEqual(resp_dict['save_volume_id'], expected_id)
self.assertEqual(expected_id, resp_dict['save_volume_id'])
else:
self.assertNotIn('save_volume_id', resp_dict)

View File

@ -93,16 +93,16 @@ class BackupsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['backup']['availability_zone'], 'az1')
self.assertEqual(res_dict['backup']['container'], 'volumebackups')
self.assertEqual(res_dict['backup']['description'],
'this is a test backup')
self.assertEqual(res_dict['backup']['name'], 'test_backup')
self.assertEqual(200, res.status_int)
self.assertEqual('az1', res_dict['backup']['availability_zone'])
self.assertEqual('volumebackups', res_dict['backup']['container'])
self.assertEqual('this is a test backup',
res_dict['backup']['description'])
self.assertEqual('test_backup', res_dict['backup']['name'])
self.assertEqual(res_dict['backup']['id'], backup_id)
self.assertEqual(res_dict['backup']['object_count'], 0)
self.assertEqual(res_dict['backup']['size'], 0)
self.assertEqual(res_dict['backup']['status'], 'creating')
self.assertEqual(0, res_dict['backup']['object_count'])
self.assertEqual(0, res_dict['backup']['size'])
self.assertEqual('creating', res_dict['backup']['status'])
self.assertEqual(res_dict['backup']['volume_id'], volume_id)
db.backup_destroy(context.get_admin_context(), backup_id)
@ -117,13 +117,13 @@ class BackupsAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/xml'
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
backup = dom.getElementsByTagName('backup')
name = backup.item(0).getAttribute('name')
container_name = backup.item(0).getAttribute('container')
self.assertEqual(container_name.strip(), "volumebackups")
self.assertEqual(name.strip(), "test_backup")
self.assertEqual('volumebackups', container_name.strip())
self.assertEqual('test_backup', name.strip())
db.backup_destroy(context.get_admin_context(), backup_id)
db.volume_destroy(context.get_admin_context(), volume_id)
@ -134,8 +134,8 @@ class BackupsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual(res_dict['itemNotFound']['message'],
'Backup 9999 could not be found.')
@ -150,16 +150,16 @@ class BackupsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(len(res_dict['backups'][0]), 3)
self.assertEqual(200, res.status_int)
self.assertEqual(3, len(res_dict['backups'][0]))
self.assertEqual(res_dict['backups'][0]['id'], backup_id1)
self.assertEqual(res_dict['backups'][0]['name'], 'test_backup')
self.assertEqual(len(res_dict['backups'][1]), 3)
self.assertEqual('test_backup', res_dict['backups'][0]['name'])
self.assertEqual(3, len(res_dict['backups'][1]))
self.assertEqual(res_dict['backups'][1]['id'], backup_id2)
self.assertEqual(res_dict['backups'][1]['name'], 'test_backup')
self.assertEqual(len(res_dict['backups'][2]), 3)
self.assertEqual('test_backup', res_dict['backups'][1]['name'])
self.assertEqual(3, len(res_dict['backups'][2]))
self.assertEqual(res_dict['backups'][2]['id'], backup_id3)
self.assertEqual(res_dict['backups'][2]['name'], 'test_backup')
self.assertEqual('test_backup', res_dict['backups'][2]['name'])
db.backup_destroy(context.get_admin_context(), backup_id3)
db.backup_destroy(context.get_admin_context(), backup_id2)
@ -176,17 +176,17 @@ class BackupsAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
backup_list = dom.getElementsByTagName('backup')
self.assertEqual(backup_list.item(0).attributes.length, 2)
self.assertEqual(2, backup_list.item(0).attributes.length)
self.assertEqual(backup_list.item(0).getAttribute('id'),
backup_id1)
self.assertEqual(backup_list.item(1).attributes.length, 2)
self.assertEqual(2, backup_list.item(1).attributes.length)
self.assertEqual(backup_list.item(1).getAttribute('id'),
backup_id2)
self.assertEqual(backup_list.item(2).attributes.length, 2)
self.assertEqual(2, backup_list.item(2).attributes.length)
self.assertEqual(backup_list.item(2).getAttribute('id'),
backup_id3)
@ -206,9 +206,9 @@ class BackupsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(len(res_dict['backups'][0]), 12)
self.assertEqual(res_dict['backups'][0]['availability_zone'], 'az1')
self.assertEqual(200, res.status_int)
self.assertEqual(12, len(res_dict['backups'][0]))
self.assertEqual('az1', res_dict['backups'][0]['availability_zone'])
self.assertEqual(res_dict['backups'][0]['container'],
'volumebackups')
self.assertEqual(res_dict['backups'][0]['description'],

View File

@ -79,12 +79,13 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['cgsnapshot']['description'],
'this is a test cgsnapshot')
self.assertEqual(res_dict['cgsnapshot']['name'],
'test_cgsnapshot')
self.assertEqual(res_dict['cgsnapshot']['status'], 'creating')
self.assertEqual(200, res.status_int)
self.assertEqual('this is a test cgsnapshot',
res_dict['cgsnapshot']['description'])
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshot']['name'])
self.assertEqual('creating', res_dict['cgsnapshot']['status'])
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id)
@ -106,11 +107,11 @@ class CgsnapshotsAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/xml'
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
cgsnapshot = dom.getElementsByTagName('cgsnapshot')
name = cgsnapshot.item(0).getAttribute('name')
self.assertEqual(name.strip(), "test_cgsnapshot")
self.assertEqual('test_cgsnapshot', name.strip())
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id)
db.volume_destroy(context.get_admin_context(),
@ -125,10 +126,10 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'CgSnapshot 9999 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('CgSnapshot 9999 could not be found.',
res_dict['itemNotFound']['message'])
def test_list_cgsnapshots_json(self):
consistencygroup_id = utils.create_consistencygroup(self.context)['id']
@ -148,19 +149,19 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
self.assertEqual(res_dict['cgsnapshots'][0]['id'],
cgsnapshot_id1)
self.assertEqual(res_dict['cgsnapshots'][0]['name'],
'test_cgsnapshot')
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshots'][0]['name'])
self.assertEqual(res_dict['cgsnapshots'][1]['id'],
cgsnapshot_id2)
self.assertEqual(res_dict['cgsnapshots'][1]['name'],
'test_cgsnapshot')
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshots'][1]['name'])
self.assertEqual(res_dict['cgsnapshots'][2]['id'],
cgsnapshot_id3)
self.assertEqual(res_dict['cgsnapshots'][2]['name'],
'test_cgsnapshot')
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshots'][2]['name'])
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id3)
@ -191,7 +192,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
cgsnapshot_list = dom.getElementsByTagName('cgsnapshot')
@ -232,34 +233,33 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['cgsnapshots'][0]['description'],
'this is a test cgsnapshot')
self.assertEqual(res_dict['cgsnapshots'][0]['name'],
'test_cgsnapshot')
self.assertEqual(200, res.status_int)
self.assertEqual('this is a test cgsnapshot',
res_dict['cgsnapshots'][0]['description'])
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshots'][0]['name'])
self.assertEqual(res_dict['cgsnapshots'][0]['id'],
cgsnapshot_id1)
self.assertEqual(res_dict['cgsnapshots'][0]['status'],
'creating')
self.assertEqual('creating',
res_dict['cgsnapshots'][0]['status'])
self.assertEqual(res_dict['cgsnapshots'][1]['description'],
'this is a test cgsnapshot')
self.assertEqual(res_dict['cgsnapshots'][1]['name'],
'test_cgsnapshot')
self.assertEqual('this is a test cgsnapshot',
res_dict['cgsnapshots'][1]['description'])
self.assertEqual('test_cgsnapshot',
res_dict['cgsnapshots'][1]['name'])
self.assertEqual(res_dict['cgsnapshots'][1]['id'],
cgsnapshot_id2)
self.assertEqual(res_dict['cgsnapshots'][1]['status'],
'creating')
self.assertEqual('creating',
res_dict['cgsnapshots'][1]['status'])
self.assertEqual(res_dict['cgsnapshots'][2]['description'],
'this is a test cgsnapshot')
self.assertEqual('this is a test cgsnapshot',
res_dict['cgsnapshots'][2]['description'])
self.assertEqual(res_dict['cgsnapshots'][2]['name'],
'test_cgsnapshot')
self.assertEqual(res_dict['cgsnapshots'][2]['id'],
cgsnapshot_id3)
self.assertEqual(res_dict['cgsnapshots'][2]['status'],
'creating')
self.assertEqual('creating',
res_dict['cgsnapshots'][2]['status'])
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id3)
db.cgsnapshot_destroy(context.get_admin_context(),
@ -289,45 +289,36 @@ class CgsnapshotsAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
cgsnapshot_detail = dom.getElementsByTagName('cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(0).getAttribute('description'),
'this is a test cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(0).getAttribute('name'),
'test_cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(0).getAttribute('id'),
cgsnapshot_id1)
self.assertEqual(
cgsnapshot_detail.item(0).getAttribute('status'), 'creating')
self.assertEqual('this is a test cgsnapshot',
cgsnapshot_detail.item(0).getAttribute('description'))
self.assertEqual('test_cgsnapshot',
cgsnapshot_detail.item(0).getAttribute('name'))
self.assertEqual(cgsnapshot_detail.item(0).getAttribute('id'),
cgsnapshot_id1)
self.assertEqual('creating',
cgsnapshot_detail.item(0).getAttribute('status'))
self.assertEqual(
cgsnapshot_detail.item(1).getAttribute('description'),
'this is a test cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(1).getAttribute('name'),
'test_cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(1).getAttribute('id'),
cgsnapshot_id2)
self.assertEqual(
cgsnapshot_detail.item(1).getAttribute('status'), 'creating')
self.assertEqual(cgsnapshot_detail.item(1).getAttribute('description'),
'this is a test cgsnapshot')
self.assertEqual('test_cgsnapshot',
cgsnapshot_detail.item(1).getAttribute('name'))
self.assertEqual(cgsnapshot_detail.item(1).getAttribute('id'),
cgsnapshot_id2)
self.assertEqual('creating',
cgsnapshot_detail.item(1).getAttribute('status'))
self.assertEqual(
cgsnapshot_detail.item(2).getAttribute('description'),
'this is a test cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(2).getAttribute('name'),
'test_cgsnapshot')
self.assertEqual(
cgsnapshot_detail.item(2).getAttribute('id'),
cgsnapshot_id3)
self.assertEqual(
cgsnapshot_detail.item(2).getAttribute('status'), 'creating')
self.assertEqual(cgsnapshot_detail.item(2).getAttribute('description'),
'this is a test cgsnapshot')
self.assertEqual('test_cgsnapshot',
cgsnapshot_detail.item(2).getAttribute('name'))
self.assertEqual(cgsnapshot_detail.item(2).getAttribute('id'),
cgsnapshot_id3)
self.assertEqual('creating',
cgsnapshot_detail.item(2).getAttribute('status'))
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id3)
@ -360,7 +351,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
self.assertIn('id', res_dict['cgsnapshot'])
db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
@ -375,8 +366,8 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'cgsnapshot' in "
"request body.",
res_dict['badRequest']['message'])
@ -446,10 +437,9 @@ class CgsnapshotsAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id,
'status'),
'deleting')
self.assertEqual(202, res.status_int)
self.assertEqual('deleting', self._get_cgsnapshot_attrib(cgsnapshot_id,
'status'))
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id)
@ -465,10 +455,10 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'CgSnapshot 9999 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('CgSnapshot 9999 could not be found.',
res_dict['itemNotFound']['message'])
def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
consistencygroup_id = utils.create_consistencygroup(self.context)['id']
@ -485,10 +475,10 @@ class CgsnapshotsAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(res_dict['badRequest']['message'],
'Invalid cgsnapshot')
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual('Invalid cgsnapshot',
res_dict['badRequest']['message'])
db.cgsnapshot_destroy(context.get_admin_context(),
cgsnapshot_id)

View File

@ -74,9 +74,9 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
return jsonutils.loads(body).get('snapshots')
def assertSnapshotAttributes(self, snapshot, project_id, progress):
self.assertEqual(snapshot.get('%sproject_id' % self.prefix),
project_id)
self.assertEqual(snapshot.get('%sprogress' % self.prefix), progress)
self.assertEqual(project_id,
snapshot.get('%sproject_id' % self.prefix))
self.assertEqual(progress, snapshot.get('%sprogress' % self.prefix))
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
@mock.patch('cinder.objects.Volume.get_by_id')
@ -93,7 +93,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
url = '/v2/fake/snapshots/%s' % UUID1
res = self._make_request(url)
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
self.assertSnapshotAttributes(self._get_snapshot(res.body),
project_id='fake',
progress='0%')
@ -102,7 +102,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
url = '/v2/fake/snapshots/detail'
res = self._make_request(url)
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
for snapshot in self._get_snapshots(res.body):
self.assertSnapshotAttributes(snapshot,
project_id='fake',

View File

@ -88,22 +88,22 @@ class HostTestCase(test.TestCase):
def _test_host_update(self, host, key, val, expected_value):
body = {key: val}
result = self.controller.update(self.req, host, body=body)
self.assertEqual(result[key], expected_value)
self.assertEqual(expected_value, result[key])
def test_list_hosts(self):
"""Verify that the volume hosts are returned."""
hosts = os_hosts._list_hosts(self.req)
self.assertEqual(hosts, LIST_RESPONSE)
self.assertEqual(LIST_RESPONSE, hosts)
cinder_hosts = os_hosts._list_hosts(self.req, 'cinder-volume')
expected = [host for host in LIST_RESPONSE
if host['service'] == 'cinder-volume']
self.assertEqual(cinder_hosts, expected)
self.assertEqual(expected, cinder_hosts)
def test_list_hosts_with_zone(self):
req = FakeRequestWithcinderZone()
hosts = os_hosts._list_hosts(req)
self.assertEqual(hosts, LIST_RESPONSE)
self.assertEqual(LIST_RESPONSE, hosts)
def test_bad_status_value(self):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,

View File

@ -151,7 +151,7 @@ class QuotaClassesSerializerTest(test.TestCase):
quota_class_set = make_body(root=False)
text = serializer.serialize({'quota_class_set': quota_class_set})
tree = etree.fromstring(text)
self.assertEqual(tree.tag, 'quota_class_set')
self.assertEqual('quota_class_set', tree.tag)
self.assertEqual(tree.get('id'), quota_class_set['id'])
body = make_body(root=False, tenant_id=None)
for node in tree:

View File

@ -66,7 +66,7 @@ class SchedulerHintsTestCase(test.TestCase):
@wsgi.response(202)
def fake_create(*args, **kwargs):
self.assertIn('scheduler_hints', kwargs['body'])
self.assertEqual(kwargs['body']['scheduler_hints'], {"a": "b"})
self.assertEqual({"a": "b"}, kwargs['body']['scheduler_hints'])
return self.fake_instance
self.stubs.Set(cinder.api.v2.volumes.VolumeController, 'create',

View File

@ -211,7 +211,7 @@ class ServicesTest(test.TestCase):
'status': 'enabled', 'state': 'down',
'updated_at': datetime.datetime(
2012, 9, 18, 8, 3, 38)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -259,7 +259,7 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(
2012, 9, 18, 8, 3, 38),
'disabled_reason': ''}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_list_with_host(self):
req = FakeRequestWithHost()
@ -278,7 +278,7 @@ class ServicesTest(test.TestCase):
'status': 'disabled', 'state': 'up',
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail_with_host(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -301,7 +301,7 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5),
'disabled_reason': 'test2'}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_list_with_service(self):
req = FakeRequestWithService()
@ -336,7 +336,7 @@ class ServicesTest(test.TestCase):
'state': 'down',
'updated_at': datetime.datetime(2012, 9, 18,
8, 3, 38)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail_with_service(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -377,7 +377,7 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(2012, 9, 18,
8, 3, 38),
'disabled_reason': ''}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_list_with_binary(self):
req = FakeRequestWithBinary()
@ -412,7 +412,7 @@ class ServicesTest(test.TestCase):
'state': 'down',
'updated_at': datetime.datetime(2012, 9, 18,
8, 3, 38)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail_with_binary(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -453,7 +453,7 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(2012, 9, 18,
8, 3, 38),
'disabled_reason': ''}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_list_with_host_service(self):
req = FakeRequestWithHostService()
@ -467,7 +467,7 @@ class ServicesTest(test.TestCase):
'state': 'up',
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail_with_host_service(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -484,7 +484,7 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5),
'disabled_reason': 'test2'}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_list_with_host_binary(self):
req = FakeRequestWithHostBinary()
@ -498,7 +498,7 @@ class ServicesTest(test.TestCase):
'state': 'up',
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5)}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_detail_with_host_binary(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -515,35 +515,35 @@ class ServicesTest(test.TestCase):
'updated_at': datetime.datetime(2012, 10, 29,
13, 42, 5),
'disabled_reason': 'test2'}]}
self.assertEqual(res_dict, response)
self.assertEqual(response, res_dict)
def test_services_enable_with_service_key(self):
body = {'host': 'host1', 'service': 'cinder-volume'}
req = fakes.HTTPRequest.blank('/v2/fake/os-services/enable')
res_dict = self.controller.update(req, "enable", body)
self.assertEqual(res_dict['status'], 'enabled')
self.assertEqual('enabled', res_dict['status'])
def test_services_enable_with_binary_key(self):
body = {'host': 'host1', 'binary': 'cinder-volume'}
req = fakes.HTTPRequest.blank('/v2/fake/os-services/enable')
res_dict = self.controller.update(req, "enable", body)
self.assertEqual(res_dict['status'], 'enabled')
self.assertEqual('enabled', res_dict['status'])
def test_services_disable_with_service_key(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-services/disable')
body = {'host': 'host1', 'service': 'cinder-volume'}
res_dict = self.controller.update(req, "disable", body)
self.assertEqual(res_dict['status'], 'disabled')
self.assertEqual('disabled', res_dict['status'])
def test_services_disable_with_binary_key(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-services/disable')
body = {'host': 'host1', 'binary': 'cinder-volume'}
res_dict = self.controller.update(req, "disable", body)
self.assertEqual(res_dict['status'], 'disabled')
self.assertEqual('disabled', res_dict['status'])
def test_services_disable_log_reason(self):
self.ext_mgr.extensions['os-extended-services'] = True
@ -556,8 +556,8 @@ class ServicesTest(test.TestCase):
}
res_dict = self.controller.update(req, "disable-log-reason", body)
self.assertEqual(res_dict['status'], 'disabled')
self.assertEqual(res_dict['disabled_reason'], 'test-reason')
self.assertEqual('disabled', res_dict['status'])
self.assertEqual('test-reason', res_dict['disabled_reason'])
def test_services_disable_log_reason_none(self):
self.ext_mgr.extensions['os-extended-services'] = True

View File

@ -39,7 +39,7 @@ class SnapshotActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
def test_update_snapshot_status_invalid_status(self, metadata_get):
@ -51,7 +51,7 @@ class SnapshotActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_update_snapshot_status_without_status(self):
self.stubs.Set(db, 'snapshot_get', stub_snapshot_get)
@ -62,7 +62,7 @@ class SnapshotActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def stub_snapshot_get(context, snapshot_id):

View File

@ -110,10 +110,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
delete_volume_type_extra_specs)
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
self.controller.delete(req, 1, 'key5')
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
def test_delete_not_found(self):
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
@ -129,10 +129,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
return_create_volume_type_extra_specs)
body = {"extra_specs": {"key1": "value1"}}
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.create(req, 1, body)
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
self.assertEqual('value1', res_dict['extra_specs']['key1'])
@ -149,11 +149,11 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
body = {"extra_specs": {"other_alphanum.-_:": "value1"}}
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.create(req, 1, body)
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
self.assertEqual('value1',
res_dict['extra_specs']['other_alphanum.-_:'])
@ -172,11 +172,11 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
"other2_alphanum.-_:": "value2",
"other3_alphanum.-_:": "value3"}}
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.create(req, 1, body)
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
self.assertEqual('value1',
res_dict['extra_specs']['other_alphanum.-_:'])
self.assertEqual('value2',
@ -190,10 +190,10 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
return_create_volume_type_extra_specs)
body = {"key1": "value1"}
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
req = fakes.HTTPRequest.blank(self.api_path + '/key1')
res_dict = self.controller.update(req, 1, 'key1', body)
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
self.assertEqual('value1', res_dict['key1'])
@ -274,7 +274,7 @@ class VolumeTypeExtraSpecsSerializerTest(test.TestCase):
self.assertIn(child.tag, seen)
self.assertEqual(extra_specs[child.tag], child.text)
seen.remove(child.tag)
self.assertEqual(len(seen), 0)
self.assertEqual(0, len(seen))
def test_update_show_serializer(self):
serializer = types_extra_specs.VolumeTypeExtraSpecTemplate()

View File

@ -74,7 +74,7 @@ class VolumeActionsTest(test.TestCase):
req.body = jsonutils.dumps({_action: None})
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_initialize_connection(self):
with mock.patch.object(volume_api.API,
@ -87,7 +87,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
def test_initialize_connection_without_connector(self):
with mock.patch.object(volume_api.API,
@ -100,7 +100,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_initialize_connection_exception(self):
with mock.patch.object(volume_api.API,
@ -114,7 +114,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 500)
self.assertEqual(500, res.status_int)
def test_terminate_connection(self):
with mock.patch.object(volume_api.API,
@ -127,7 +127,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_terminate_connection_without_connector(self):
with mock.patch.object(volume_api.API,
@ -140,7 +140,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_terminate_connection_with_exception(self):
with mock.patch.object(volume_api.API,
@ -154,7 +154,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 500)
self.assertEqual(500, res.status_int)
def test_attach_to_instance(self):
body = {'os-attach': {'instance_uuid': 'fake',
@ -166,7 +166,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_attach_to_host(self):
# using 'read-write' mode attach volume by default
@ -178,7 +178,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_volume_attach_to_instance_raises_remote_error(self):
volume_remote_error = \
@ -264,7 +264,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
# Invalid request to attach volume to an instance and a host
body = {'os-attach': {'instance_uuid': 'fake',
@ -275,7 +275,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
# Invalid request to attach volume with an invalid mode
body = {'os-attach': {'instance_uuid': 'fake',
@ -286,7 +286,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
body = {'os-attach': {'host_name': 'fake_host',
'mountpoint': '/dev/vdc',
'mode': 'ww'}}
@ -295,7 +295,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
req.body = jsonutils.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_begin_detaching(self):
def fake_begin_detaching(*args, **kwargs):
@ -310,7 +310,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_roll_detaching(self):
def fake_roll_detaching(*args, **kwargs):
@ -325,7 +325,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_extend_volume(self):
def fake_extend_volume(*args, **kwargs):
@ -340,7 +340,7 @@ class VolumeActionsTest(test.TestCase):
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
def test_update_readonly_flag(self):
def fake_update_readonly_flag(*args, **kwargs):
@ -357,7 +357,7 @@ class VolumeActionsTest(test.TestCase):
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, return_code)
self.assertEqual(return_code, res.status_int)
make_update_readonly_flag_test(self, True, 202)
make_update_readonly_flag_test(self, False, 202)
@ -380,7 +380,7 @@ class VolumeActionsTest(test.TestCase):
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, return_code)
self.assertEqual(return_code, res.status_int)
make_set_bootable_test(self, True, 200)
make_set_bootable_test(self, False, 200)
@ -427,7 +427,7 @@ class VolumeRetypeActionsTest(VolumeActionsTest):
retype_body = {'new_type': new_type, 'migration_policy': 'never'}
req.body = jsonutils.dumps({'os-retype': retype_body})
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, expected_status)
self.assertEqual(expected_status, res.status_int)
@mock.patch('cinder.volume.qos_specs.get_qos_specs')
def test_retype_volume_success(self, _mock_get_qspecs):
@ -446,7 +446,7 @@ class VolumeRetypeActionsTest(VolumeActionsTest):
req.headers['content-type'] = 'application/json'
req.body = jsonutils.dumps({'os-retype': None})
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_retype_volume_bad_policy(self):
# Request with invalid migration policy should fail
@ -456,7 +456,7 @@ class VolumeRetypeActionsTest(VolumeActionsTest):
retype_body = {'new_type': 'foo', 'migration_policy': 'invalid'}
req.body = jsonutils.dumps({'os-retype': retype_body})
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_retype_volume_bad_status(self):
# Should fail if volume does not have proper status
@ -691,7 +691,7 @@ class VolumeImageActionsTest(test.TestCase):
req.headers['Content-Type'] = 'application/json'
req.body = json.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_volume_upload_image_without_type(self):
id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
@ -705,7 +705,7 @@ class VolumeImageActionsTest(test.TestCase):
req.headers['Content-Type'] = 'application/json'
req.body = json.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_extend_volume_valueerror(self):
id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'

View File

@ -74,7 +74,7 @@ class VolumeHostAttributeTest(test.TestCase):
req.environ['cinder.context'] = ctx
res = req.get_response(app())
vol = json.loads(res.body)['volume']
self.assertEqual(vol['os-vol-host-attr:host'], 'host001')
self.assertEqual('host001', vol['os-vol-host-attr:host'])
def test_get_volume_unallowed(self):
ctx = context.RequestContext('non-admin', 'fake', False)
@ -92,7 +92,7 @@ class VolumeHostAttributeTest(test.TestCase):
req.environ['cinder.context'] = ctx
res = req.get_response(app())
vol = json.loads(res.body)['volumes']
self.assertEqual(vol[0]['os-vol-host-attr:host'], 'host001')
self.assertEqual('host001', vol[0]['os-vol-host-attr:host'])
def test_list_detail_volumes_unallowed(self):
ctx = context.RequestContext('non-admin', 'fake', False)
@ -122,7 +122,7 @@ class VolumeHostAttributeTest(test.TestCase):
vol = etree.XML(res.body)
host_key = ('{http://docs.openstack.org/volume/ext/'
'volume_host_attribute/api/v2}host')
self.assertEqual(vol.get(host_key), 'host001')
self.assertEqual('host001', vol.get(host_key))
def test_list_volumes_detail_xml(self):
ctx = context.RequestContext('admin', 'fake', True)
@ -134,4 +134,4 @@ class VolumeHostAttributeTest(test.TestCase):
vol = list(etree.XML(res.body))[0]
host_key = ('{http://docs.openstack.org/volume/ext/'
'volume_host_attribute/api/v2}host')
self.assertEqual(vol.get(host_key), 'host001')
self.assertEqual('host001', vol.get(host_key))

View File

@ -146,7 +146,7 @@ class VolumeManageTest(test.TestCase):
body = {'volume': {'host': 'host_ok',
'ref': 'fake_ref'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 202, res)
self.assertEqual(202, res.status_int, res)
# Check that the manage API was called with the correct arguments.
self.assertEqual(mock_api_manage.call_count, 1)
@ -158,13 +158,13 @@ class VolumeManageTest(test.TestCase):
"""Test correct failure when host is not specified."""
body = {'volume': {'ref': 'fake_ref'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
def test_manage_volume_missing_ref(self):
"""Test correct failure when the ref is not specified."""
body = {'volume': {'host': 'host_ok'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 400)
self.assertEqual(400, res.status_int)
pass
@mock.patch('cinder.volume.api.API.manage_existing', api_manage)
@ -179,7 +179,7 @@ class VolumeManageTest(test.TestCase):
'volume_type':
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 202, res)
self.assertEqual(202, res.status_int, res)
pass
@mock.patch('cinder.volume.api.API.manage_existing', api_manage)
@ -193,7 +193,7 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'volume_type': 'good_fakevt'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 202, res)
self.assertEqual(202, res.status_int, res)
pass
def test_manage_volume_bad_volume_type_by_uuid(self):
@ -212,5 +212,5 @@ class VolumeManageTest(test.TestCase):
'ref': 'fake_ref',
'volume_type': 'bad_fakevt'}}
res = self._get_resp(body)
self.assertEqual(res.status_int, 404, res)
self.assertEqual(404, res.status_int, res)
pass

View File

@ -73,10 +73,10 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(res_dict['transfer']['name'], 'test_transfer')
self.assertEqual(res_dict['transfer']['id'], transfer['id'])
self.assertEqual(res_dict['transfer']['volume_id'], volume_id)
self.assertEqual(200, res.status_int)
self.assertEqual('test_transfer', res_dict['transfer']['name'])
self.assertEqual(transfer['id'], res_dict['transfer']['id'])
self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
db.transfer_destroy(context.get_admin_context(), transfer['id'])
db.volume_destroy(context.get_admin_context(), volume_id)
@ -90,11 +90,11 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/xml'
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
transfer_xml = dom.getElementsByTagName('transfer')
name = transfer_xml.item(0).getAttribute('name')
self.assertEqual(name.strip(), "test_transfer")
self.assertEqual('test_transfer', name.strip())
db.transfer_destroy(context.get_admin_context(), transfer['id'])
db.volume_destroy(context.get_admin_context(), volume_id)
@ -106,10 +106,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'Transfer 1234 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('Transfer 1234 could not be found.',
res_dict['itemNotFound']['message'])
def test_list_transfers_json(self):
volume_id_1 = self._create_volume(size=5)
@ -123,12 +123,12 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(len(res_dict['transfers'][0]), 4)
self.assertEqual(res_dict['transfers'][0]['id'], transfer1['id'])
self.assertEqual(res_dict['transfers'][0]['name'], 'test_transfer')
self.assertEqual(len(res_dict['transfers'][1]), 4)
self.assertEqual(res_dict['transfers'][1]['name'], 'test_transfer')
self.assertEqual(200, res.status_int)
self.assertEqual(4, len(res_dict['transfers'][0]))
self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id'])
self.assertEqual('test_transfer', res_dict['transfers'][0]['name'])
self.assertEqual(4, len(res_dict['transfers'][1]))
self.assertEqual('test_transfer', res_dict['transfers'][1]['name'])
db.transfer_destroy(context.get_admin_context(), transfer2['id'])
db.transfer_destroy(context.get_admin_context(), transfer1['id'])
@ -147,15 +147,15 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
transfer_list = dom.getElementsByTagName('transfer')
self.assertEqual(transfer_list.item(0).attributes.length, 3)
self.assertEqual(transfer_list.item(0).getAttribute('id'),
transfer1['id'])
self.assertEqual(transfer_list.item(1).attributes.length, 3)
self.assertEqual(transfer_list.item(1).getAttribute('id'),
transfer2['id'])
self.assertEqual(3, transfer_list.item(0).attributes.length)
self.assertEqual(transfer1['id'],
transfer_list.item(0).getAttribute('id'))
self.assertEqual(3, transfer_list.item(1).attributes.length)
self.assertEqual(transfer2['id'],
transfer_list.item(1).getAttribute('id'))
db.transfer_destroy(context.get_admin_context(), transfer2['id'])
db.transfer_destroy(context.get_admin_context(), transfer1['id'])
@ -175,18 +175,18 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(len(res_dict['transfers'][0]), 5)
self.assertEqual(res_dict['transfers'][0]['name'],
'test_transfer')
self.assertEqual(res_dict['transfers'][0]['id'], transfer1['id'])
self.assertEqual(res_dict['transfers'][0]['volume_id'], volume_id_1)
self.assertEqual(200, res.status_int)
self.assertEqual(5, len(res_dict['transfers'][0]))
self.assertEqual('test_transfer',
res_dict['transfers'][0]['name'])
self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id'])
self.assertEqual(volume_id_1, res_dict['transfers'][0]['volume_id'])
self.assertEqual(len(res_dict['transfers'][1]), 5)
self.assertEqual(res_dict['transfers'][1]['name'],
'test_transfer')
self.assertEqual(res_dict['transfers'][1]['id'], transfer2['id'])
self.assertEqual(res_dict['transfers'][1]['volume_id'], volume_id_2)
self.assertEqual(5, len(res_dict['transfers'][1]))
self.assertEqual('test_transfer',
res_dict['transfers'][1]['name'])
self.assertEqual(transfer2['id'], res_dict['transfers'][1]['id'])
self.assertEqual(volume_id_2, res_dict['transfers'][1]['volume_id'])
db.transfer_destroy(context.get_admin_context(), transfer2['id'])
db.transfer_destroy(context.get_admin_context(), transfer1['id'])
@ -205,25 +205,25 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
dom = minidom.parseString(res.body)
transfer_detail = dom.getElementsByTagName('transfer')
self.assertEqual(transfer_detail.item(0).attributes.length, 4)
self.assertEqual(4, transfer_detail.item(0).attributes.length)
self.assertEqual(
transfer_detail.item(0).getAttribute('name'), 'test_transfer')
'test_transfer', transfer_detail.item(0).getAttribute('name'))
self.assertEqual(
transfer_detail.item(0).getAttribute('id'), transfer1['id'])
self.assertEqual(transfer_detail.item(0).getAttribute('volume_id'),
volume_id_1)
transfer1['id'], transfer_detail.item(0).getAttribute('id'))
self.assertEqual(volume_id_1,
transfer_detail.item(0).getAttribute('volume_id'))
self.assertEqual(transfer_detail.item(1).attributes.length, 4)
self.assertEqual(4, transfer_detail.item(1).attributes.length)
self.assertEqual(
transfer_detail.item(1).getAttribute('name'), 'test_transfer')
'test_transfer', transfer_detail.item(1).getAttribute('name'))
self.assertEqual(
transfer_detail.item(1).getAttribute('id'), transfer2['id'])
self.assertEqual(transfer_detail.item(1).getAttribute('volume_id'),
volume_id_2)
transfer2['id'], transfer_detail.item(1).getAttribute('id'))
self.assertEqual(
volume_id_2, transfer_detail.item(1).getAttribute('volume_id'))
db.transfer_destroy(context.get_admin_context(), transfer2['id'])
db.transfer_destroy(context.get_admin_context(), transfer1['id'])
@ -265,7 +265,7 @@ class VolumeTransferAPITestCase(test.TestCase):
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
self.assertIn('id', res_dict['transfer'])
self.assertIn('auth_key', res_dict['transfer'])
self.assertIn('created_at', res_dict['transfer'])
@ -286,7 +286,7 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
dom = minidom.parseString(res.body)
transfer = dom.getElementsByTagName('transfer')
self.assertTrue(transfer.item(0).hasAttribute('id'))
@ -305,8 +305,8 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'transfer' in "
"request body.",
res_dict['badRequest']['message'])
@ -320,10 +320,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(res_dict['badRequest']['message'],
'Incorrect request body format')
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual('Incorrect request body format',
res_dict['badRequest']['message'])
def test_create_transfer_with_VolumeNotFound(self):
body = {"transfer": {"display_name": "transfer1",
@ -336,10 +336,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'Volume 1234 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('Volume 1234 could not be found.',
res_dict['itemNotFound']['message'])
def test_create_transfer_with_InvalidVolume(self):
volume_id = self._create_volume(status='attached')
@ -352,10 +352,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(res_dict['badRequest']['message'],
'Invalid volume: status must be available')
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual('Invalid volume: status must be available',
res_dict['badRequest']['message'])
db.volume_destroy(context.get_admin_context(), volume_id)
@ -368,7 +368,7 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
# verify transfer has been deleted
req = webob.Request.blank('/v2/fake/os-volume-transfer/%s' %
@ -378,10 +378,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'Transfer %s could not be found.' % transfer['id'])
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('Transfer %s could not be found.' % transfer['id'],
res_dict['itemNotFound']['message'])
self.assertEqual(db.volume_get(context.get_admin_context(),
volume_id)['status'], 'available')
@ -394,10 +394,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'Transfer 9999 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('Transfer 9999 could not be found.',
res_dict['itemNotFound']['message'])
def test_accept_transfer_volume_id_specified_json(self):
volume_id = self._create_volume()
@ -414,9 +414,9 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 202)
self.assertEqual(res_dict['transfer']['id'], transfer['id'])
self.assertEqual(res_dict['transfer']['volume_id'], volume_id)
self.assertEqual(202, res.status_int)
self.assertEqual(transfer['id'], res_dict['transfer']['id'])
self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
# cleanup
svc.stop()
@ -433,12 +433,12 @@ class VolumeTransferAPITestCase(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
self.assertEqual(202, res.status_int)
dom = minidom.parseString(res.body)
accept = dom.getElementsByTagName('transfer')
self.assertEqual(accept.item(0).getAttribute('id'),
transfer['id'])
self.assertEqual(accept.item(0).getAttribute('volume_id'), volume_id)
self.assertEqual(transfer['id'],
accept.item(0).getAttribute('id'))
self.assertEqual(volume_id, accept.item(0).getAttribute('volume_id'))
db.volume_destroy(context.get_admin_context(), volume_id)
# cleanup
@ -457,8 +457,8 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'accept' in request body.",
res_dict['badRequest']['message'])
@ -479,8 +479,8 @@ class VolumeTransferAPITestCase(test.TestCase):
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual("Missing required element 'accept' in request body.",
res_dict['badRequest']['message'])
@ -498,8 +498,8 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 400)
self.assertEqual(res_dict['badRequest']['code'], 400)
self.assertEqual(400, res.status_int)
self.assertEqual(400, res_dict['badRequest']['code'])
self.assertEqual(res_dict['badRequest']['message'],
'Invalid auth key: Attempt to transfer %s with '
'invalid auth key.' % transfer['id'])
@ -520,10 +520,10 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
'TransferNotFound: Transfer 1 could not be found.')
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
self.assertEqual('TransferNotFound: Transfer 1 could not be found.',
res_dict['itemNotFound']['message'])
db.transfer_destroy(context.get_admin_context(), transfer['id'])
db.volume_destroy(context.get_admin_context(), volume_id)
@ -555,12 +555,12 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 413)
self.assertEqual(res_dict['overLimit']['code'], 413)
self.assertEqual(res_dict['overLimit']['message'],
'Requested volume or snapshot exceeds allowed '
self.assertEqual(413, res.status_int)
self.assertEqual(413, res_dict['overLimit']['code'])
self.assertEqual('Requested volume or snapshot exceeds allowed '
'gigabytes quota. Requested 2G, quota is 3G and '
'2G has been consumed.')
'2G has been consumed.',
res_dict['overLimit']['message'])
def test_accept_transfer_with_VolumeLimitExceeded(self):
@ -587,8 +587,8 @@ class VolumeTransferAPITestCase(test.TestCase):
res = req.get_response(fakes.wsgi_app())
res_dict = json.loads(res.body)
self.assertEqual(res.status_int, 413)
self.assertEqual(res_dict['overLimit']['code'], 413)
self.assertEqual(res_dict['overLimit']['message'],
'VolumeLimitExceeded: Maximum number of volumes '
'allowed (1) exceeded')
self.assertEqual(413, res.status_int)
self.assertEqual(413, res_dict['overLimit']['code'])
self.assertEqual('VolumeLimitExceeded: Maximum number of volumes '
'allowed (1) exceeded',
res_dict['overLimit']['message'])

View File

@ -162,7 +162,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
'provider': provider,
'volume_type_id': volume_type['id']}}
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
res = self._get_response(volume_type)
res_dict = json.loads(res.body)
self.assertEqual(200, res.status_code)
@ -177,7 +177,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
req_headers='application/json')
res_dict = json.loads(res.body)
self.assertEqual(len(self.notifier.notifications), 1)
self.assertEqual(1, len(self.notifier.notifications))
# check response
self.assertIn('encryption', res_dict)
@ -218,7 +218,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
req.headers['Accept'] = 'application/xml'
res = req.get_response(fakes.wsgi_app(fake_auth_context=ctxt))
self.assertEqual(res.status_int, 200)
self.assertEqual(200, res.status_int)
db.volume_type_destroy(context.get_admin_context(), volume_type['id'])
@ -232,7 +232,7 @@ class VolumeTypeEncryptionTest(test.TestCase):
req_headers='application/json')
res_dict = json.loads(res.body)
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
self.assertEqual(404, res.status_code)
expected = {

View File

@ -137,29 +137,29 @@ class VolumeUnmanageTest(test.TestCase):
res = self._get_resp(detached_vol_id)
# volume_update is (context, id, new_data)
self.assertEqual(mock_db.call_count, 1)
self.assertEqual(len(mock_db.call_args[0]), 3, mock_db.call_args)
self.assertEqual(1, mock_db.call_count)
self.assertEqual(3, len(mock_db.call_args[0]), mock_db.call_args)
self.assertEqual(mock_db.call_args[0][1], detached_vol_id)
# delete_volume is (context, status, unmanageOnly)
self.assertEqual(mock_rpcapi.call_count, 1)
self.assertEqual(len(mock_rpcapi.call_args[0]), 3)
self.assertEqual(mock_rpcapi.call_args[0][2], True)
self.assertEqual(1, mock_rpcapi.call_count)
self.assertEqual(3, len(mock_rpcapi.call_args[0]))
self.assertEqual(True, mock_rpcapi.call_args[0][2])
self.assertEqual(res.status_int, 202, res)
self.assertEqual(202, res.status_int, res)
def test_unmanage_volume_bad_volume_id(self):
"""Return 404 if the volume does not exist."""
res = self._get_resp(bad_vol_id)
self.assertEqual(res.status_int, 404, res)
self.assertEqual(404, res.status_int, res)
def test_unmanage_volume_attached_(self):
"""Return 400 if the volume exists but is attached."""
res = self._get_resp(attached_vol_id)
self.assertEqual(res.status_int, 400, res)
self.assertEqual(400, res.status_int, res)
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
def test_unmanage_volume_with_snapshots(self, metadata_get):
"""Return 400 if the volume exists but has snapshots."""
res = self._get_resp(snapshot_vol_id)
self.assertEqual(res.status_int, 400, res)
self.assertEqual(400, res.status_int, res)

View File

@ -38,34 +38,34 @@ class TestCinderKeystoneContextMiddleware(test.TestCase):
def test_no_user_or_user_id(self):
response = self.request.get_response(self.middleware)
self.assertEqual(response.status, '401 Unauthorized')
self.assertEqual('401 Unauthorized', response.status)
def test_user_only(self):
self.request.headers['X_USER'] = 'testuser'
response = self.request.get_response(self.middleware)
self.assertEqual(response.status, '200 OK')
self.assertEqual(self.context.user_id, 'testuser')
self.assertEqual('200 OK', response.status)
self.assertEqual('testuser', self.context.user_id)
def test_user_id_only(self):
self.request.headers['X_USER_ID'] = 'testuserid'
response = self.request.get_response(self.middleware)
self.assertEqual(response.status, '200 OK')
self.assertEqual(self.context.user_id, 'testuserid')
self.assertEqual('200 OK', response.status)
self.assertEqual('testuserid', self.context.user_id)
def test_user_id_trumps_user(self):
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_USER'] = 'testuser'
response = self.request.get_response(self.middleware)
self.assertEqual(response.status, '200 OK')
self.assertEqual(self.context.user_id, 'testuserid')
self.assertEqual('200 OK', response.status)
self.assertEqual('testuserid', self.context.user_id)
def test_tenant_id_name(self):
self.request.headers['X_USER_ID'] = 'testuserid'
self.request.headers['X_TENANT_NAME'] = 'testtenantname'
response = self.request.get_response(self.middleware)
self.assertEqual(response.status, '200 OK')
self.assertEqual(self.context.project_id, 'testtenantid')
self.assertEqual(self.context.project_name, 'testtenantname')
self.assertEqual('200 OK', response.status)
self.assertEqual('testtenantid', self.context.project_id)
self.assertEqual('testtenantname', self.context.project_name)
def test_request_id_extracted_from_env(self):
req_id = 'dummy-request-id'

View File

@ -59,7 +59,7 @@ class TestFaults(test.TestCase):
}
actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual("application/json", response.content_type)
self.assertEqual(expected, actual)
def test_413_fault_json(self):
@ -84,7 +84,7 @@ class TestFaults(test.TestCase):
}
actual = jsonutils.loads(response.body)
self.assertEqual(response.content_type, "application/json")
self.assertEqual("application/json", response.content_type)
self.assertEqual(expected, actual)
def test_raise(self):
@ -95,8 +95,8 @@ class TestFaults(test.TestCase):
req = webob.Request.blank('/.xml')
resp = req.get_response(raiser)
self.assertEqual(resp.content_type, "application/xml")
self.assertEqual(resp.status_int, 404)
self.assertEqual("application/xml", resp.content_type)
self.assertEqual(404, resp.status_int)
self.assertIn('whut?', resp.body)
def test_raise_403(self):
@ -107,8 +107,8 @@ class TestFaults(test.TestCase):
req = webob.Request.blank('/.xml')
resp = req.get_response(raiser)
self.assertEqual(resp.content_type, "application/xml")
self.assertEqual(resp.status_int, 403)
self.assertEqual("application/xml", resp.content_type)
self.assertEqual(403, resp.status_int)
self.assertNotIn('resizeNotAllowed', resp.body)
self.assertIn('forbidden', resp.body)
@ -128,15 +128,15 @@ class TestFaults(test.TestCase):
req = webob.Request.blank('/.xml')
resp = req.get_response(raiser)
self.assertEqual(resp.content_type, "application/xml")
self.assertEqual(resp.status_int, 404)
self.assertEqual("application/xml", resp.content_type)
self.assertEqual(404, resp.status_int)
self.assertIn(("Mensaje traducido"), resp.body)
self.stubs.UnsetAll()
def test_fault_has_status_int(self):
"""Ensure the status_int is set correctly on faults."""
fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?'))
self.assertEqual(fault.status_int, 400)
self.assertEqual(400, fault.status_int)
def test_xml_serializer(self):
"""Ensure that a v2 request responds with a v2 xmlns."""
@ -147,8 +147,8 @@ class TestFaults(test.TestCase):
response = request.get_response(fault)
self.assertIn(common.XML_NS_V2, response.body)
self.assertEqual(response.content_type, "application/xml")
self.assertEqual(response.status_int, 400)
self.assertEqual("application/xml", response.content_type)
self.assertEqual(400, response.status_int)
class FaultsXMLSerializationTestV11(test.TestCase):

View File

@ -65,9 +65,9 @@ class LimiterTest(test.TestCase):
def test_limiter_offset_over_max(self):
"""Test offset key works with a number over 1000 (max_limit)."""
req = webob.Request.blank('/?offset=1001')
self.assertEqual(common.limited(self.tiny, req), [])
self.assertEqual(common.limited(self.small, req), [])
self.assertEqual(common.limited(self.medium, req), [])
self.assertEqual([], common.limited(self.tiny, req))
self.assertEqual([], common.limited(self.small, req))
self.assertEqual([], common.limited(self.medium, req))
self.assertEqual(
common.limited(self.large, req), self.large[1001:2001])
@ -177,19 +177,19 @@ class PaginationParamsTest(test.TestCase):
def test_no_params(self):
"""Test no params."""
req = webob.Request.blank('/')
self.assertEqual(common.get_pagination_params(req), {})
self.assertEqual({}, common.get_pagination_params(req))
def test_valid_marker(self):
"""Test valid marker param."""
req = webob.Request.blank(
'/?marker=263abb28-1de6-412f-b00b-f0ee0c4333c2')
self.assertEqual(common.get_pagination_params(req),
{'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'})
self.assertEqual({'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'},
common.get_pagination_params(req))
def test_valid_limit(self):
"""Test valid limit param."""
req = webob.Request.blank('/?limit=10')
self.assertEqual(common.get_pagination_params(req), {'limit': 10})
self.assertEqual({'limit': 10}, common.get_pagination_params(req))
def test_invalid_limit(self):
"""Test invalid limit param."""
@ -201,8 +201,8 @@ class PaginationParamsTest(test.TestCase):
"""Test valid limit and marker parameters."""
marker = '263abb28-1de6-412f-b00b-f0ee0c4333c2'
req = webob.Request.blank('/?limit=20&marker=%s' % marker)
self.assertEqual(common.get_pagination_params(req),
{'marker': marker, 'limit': 20})
self.assertEqual({'marker': marker, 'limit': 20},
common.get_pagination_params(req))
class SortParamUtilsTest(test.TestCase):
@ -306,31 +306,31 @@ class MiscFunctionsTest(test.TestCase):
fixture = 'http://www.testsite.com/v1/images'
expected = 'http://www.testsite.com/images'
actual = common.remove_version_from_href(fixture)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
def test_remove_version_from_href(self):
fixture = 'http://www.testsite.com/v1.1/images'
expected = 'http://www.testsite.com/images'
actual = common.remove_version_from_href(fixture)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
def test_remove_version_from_href_2(self):
fixture = 'http://www.testsite.com/v1.1/'
expected = 'http://www.testsite.com/'
actual = common.remove_version_from_href(fixture)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
def test_remove_version_from_href_3(self):
fixture = 'http://www.testsite.com/v10.10'
expected = 'http://www.testsite.com'
actual = common.remove_version_from_href(fixture)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
def test_remove_version_from_href_4(self):
fixture = 'http://www.testsite.com/v1.1/images/v10.5'
expected = 'http://www.testsite.com/images/v10.5'
actual = common.remove_version_from_href(fixture)
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
def test_remove_version_from_href_bad_request(self):
fixture = 'http://www.testsite.com/1.1/images'

View File

@ -60,7 +60,7 @@ class ExtensionControllerTest(ExtensionTestCase):
names = [str(x['name']) for x in data['extensions']
if str(x['name']) in self.ext_list]
names.sort()
self.assertEqual(names, self.ext_list)
self.assertEqual(self.ext_list, names)
# Ensure all the timestamps are valid according to iso8601
for ext in data['extensions']:
@ -70,19 +70,21 @@ class ExtensionControllerTest(ExtensionTestCase):
(fox_ext, ) = [
x for x in data['extensions'] if x['alias'] == 'FOXNSOX']
self.assertEqual(
fox_ext, {'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
'name': 'Fox In Socks',
'updated': '2011-01-22T13:25:27-06:00',
'description': 'The Fox In Socks Extension.',
'alias': 'FOXNSOX',
'links': []}, )
{'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
'name': 'Fox In Socks',
'updated': '2011-01-22T13:25:27-06:00',
'description': 'The Fox In Socks Extension.',
'alias': 'FOXNSOX',
'links': []},
fox_ext)
for ext in data['extensions']:
url = '/fake/extensions/%s' % ext['alias']
request = webob.Request.blank(url)
response = request.get_response(app)
output = jsonutils.loads(response.body)
self.assertEqual(output['extension']['alias'], ext['alias'])
self.assertEqual(output['extension']['alias'],
ext['alias'])
def test_get_extension_json(self):
app = router.APIRouter()
@ -92,13 +94,12 @@ class ExtensionControllerTest(ExtensionTestCase):
data = jsonutils.loads(response.body)
self.assertEqual(
data['extension'],
{"namespace": "http://www.fox.in.socks/api/ext/pie/v1.0",
"name": "Fox In Socks",
"updated": "2011-01-22T13:25:27-06:00",
"description": "The Fox In Socks Extension.",
"alias": "FOXNSOX",
"links": []})
"links": []}, data['extension'])
def test_get_non_existing_extension_json(self):
app = router.APIRouter()
@ -122,14 +123,14 @@ class ExtensionControllerTest(ExtensionTestCase):
# Make sure that at least Fox in Sox is correct.
(fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
self.assertEqual('Fox In Socks', fox_ext.get('name'))
self.assertEqual(
fox_ext.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
'http://www.fox.in.socks/api/ext/pie/v1.0',
fox_ext.get('namespace'))
self.assertEqual('2011-01-22T13:25:27-06:00', fox_ext.get('updated'))
self.assertEqual(
fox_ext.findtext('{0}description'.format(NS)),
'The Fox In Socks Extension.')
'The Fox In Socks Extension.',
fox_ext.findtext('{0}description'.format(NS)))
xmlutil.validate_schema(root, 'extensions')
@ -143,15 +144,15 @@ class ExtensionControllerTest(ExtensionTestCase):
root = etree.XML(xml)
self.assertEqual(root.tag.split('extension')[0], NS)
self.assertEqual(root.get('alias'), 'FOXNSOX')
self.assertEqual(root.get('name'), 'Fox In Socks')
self.assertEqual('FOXNSOX', root.get('alias'))
self.assertEqual('Fox In Socks', root.get('name'))
self.assertEqual(
root.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
'http://www.fox.in.socks/api/ext/pie/v1.0',
root.get('namespace'))
self.assertEqual('2011-01-22T13:25:27-06:00', root.get('updated'))
self.assertEqual(
root.findtext('{0}description'.format(NS)),
'The Fox In Socks Extension.')
'The Fox In Socks Extension.',
root.findtext('{0}description'.format(NS)))
xmlutil.validate_schema(root, 'extension')
@ -200,12 +201,12 @@ class ExtensionControllerIdFormatTest(test.TestCase):
def test_id_with_xml_format(self):
result = self._bounce_id('foo.xml')
self.assertEqual(result, 'foo')
self.assertEqual('foo', result)
def test_id_with_json_format(self):
result = self._bounce_id('foo.json')
self.assertEqual(result, 'foo')
self.assertEqual('foo', result)
def test_id_with_bad_format(self):
result = self._bounce_id('foo.bad')
self.assertEqual(result, 'foo.bad')
self.assertEqual('foo.bad', result)

View File

@ -63,13 +63,13 @@ class VolumeRouterTestCase(test.TestCase):
request_environment = {'PATH_INFO': '/'}
resource = versions.Versions()
result = resource.get_action_args(request_environment)
self.assertEqual(result['action'], 'index')
self.assertEqual('index', result['action'])
def test_versions_action_args_multi(self):
request_environment = {'PATH_INFO': '/fake/path'}
resource = versions.Versions()
result = resource.get_action_args(request_environment)
self.assertEqual(result['action'], 'multi')
self.assertEqual('multi', result['action'])
def test_versions_get_most_recent_update(self):
res = versions.AtomSerializer()
@ -115,7 +115,7 @@ class VolumeRouterTestCase(test.TestCase):
result[subElement.tag] = subElement.text
else:
result[subElement.tag] = subElement.attrib
self.assertEqual(result, fake_result)
self.assertEqual(fake_result, result)
def test_versions_create_feed(self):
res = versions.AtomSerializer()
@ -162,7 +162,7 @@ class VolumeRouterTestCase(test.TestCase):
for subElement in result:
if subElement.text:
data[subElement.tag] = subElement.text
self.assertEqual(data, fake_data)
self.assertEqual(fake_data, data)
def test_versions_multi(self):
req = fakes.HTTPRequest.blank('/')
@ -171,7 +171,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.multi, req, {})
ids = [v['id'] for v in result['choices']]
self.assertEqual(set(ids), set(['v1.0', 'v2.0']))
self.assertEqual(set(['v1.0', 'v2.0']), set(ids))
def test_versions_multi_disable_v1(self):
self.flags(enable_v1_api=False)
@ -181,7 +181,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.multi, req, {})
ids = [v['id'] for v in result['choices']]
self.assertEqual(set(ids), set(['v2.0']))
self.assertEqual(set(['v2.0']), set(ids))
def test_versions_multi_disable_v2(self):
self.flags(enable_v2_api=False)
@ -191,7 +191,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.multi, req, {})
ids = [v['id'] for v in result['choices']]
self.assertEqual(set(ids), set(['v1.0']))
self.assertEqual(set(['v1.0']), set(ids))
def test_versions_index(self):
req = fakes.HTTPRequest.blank('/')
@ -200,7 +200,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.index, req, {})
ids = [v['id'] for v in result['versions']]
self.assertEqual(set(ids), set(['v1.0', 'v2.0']))
self.assertEqual(set(['v1.0', 'v2.0']), set(ids))
def test_versions_index_disable_v1(self):
self.flags(enable_v1_api=False)
@ -210,7 +210,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.index, req, {})
ids = [v['id'] for v in result['versions']]
self.assertEqual(set(ids), set(['v2.0']))
self.assertEqual(set(['v2.0']), set(ids))
def test_versions_index_disable_v2(self):
self.flags(enable_v2_api=False)
@ -220,7 +220,7 @@ class VolumeRouterTestCase(test.TestCase):
resource = versions.Versions()
result = resource.dispatch(resource.index, req, {})
ids = [v['id'] for v in result['versions']]
self.assertEqual(set(ids), set(['v1.0']))
self.assertEqual(set(['v1.0']), set(ids))
def test_volumes(self):
req = fakes.HTTPRequest.blank('/fakeproject/volumes')

View File

@ -44,7 +44,7 @@ class Test(test.TestCase):
with mock.patch('sys.stdout', new=six.StringIO()):
application = wsgi.Debug(Application())
result = webob.Request.blank('/').get_response(application)
self.assertEqual(result.body, "Test result")
self.assertEqual("Test result", result.body)
def test_router(self):
@ -66,4 +66,4 @@ class Test(test.TestCase):
result = webob.Request.blank('/test').get_response(Router())
self.assertEqual(result.body, "Router result")
result = webob.Request.blank('/bad').get_response(Router())
self.assertNotEqual(result.body, "Router result")
self.assertNotEqual("Router result", result.body)

View File

@ -28,34 +28,34 @@ class SelectorTest(test.TestCase):
def test_empty_selector(self):
sel = xmlutil.Selector()
self.assertEqual(len(sel.chain), 0)
self.assertEqual(0, len(sel.chain))
self.assertEqual(sel(self.obj_for_test), self.obj_for_test)
def test_dict_selector(self):
sel = xmlutil.Selector('test')
self.assertEqual(len(sel.chain), 1)
self.assertEqual(sel.chain[0], 'test')
self.assertEqual(1, len(sel.chain))
self.assertEqual('test', sel.chain[0])
self.assertEqual(sel(self.obj_for_test),
self.obj_for_test['test'])
def test_datum_selector(self):
sel = xmlutil.Selector('test', 'name')
self.assertEqual(len(sel.chain), 2)
self.assertEqual(sel.chain[0], 'test')
self.assertEqual(sel.chain[1], 'name')
self.assertEqual(sel(self.obj_for_test), 'test')
self.assertEqual(2, len(sel.chain))
self.assertEqual('test', sel.chain[0])
self.assertEqual('name', sel.chain[1])
self.assertEqual('test', sel(self.obj_for_test))
def test_list_selector(self):
sel = xmlutil.Selector('test', 'values', 0)
self.assertEqual(len(sel.chain), 3)
self.assertEqual(sel.chain[0], 'test')
self.assertEqual(sel.chain[1], 'values')
self.assertEqual(sel.chain[2], 0)
self.assertEqual(sel(self.obj_for_test), 1)
self.assertEqual(3, len(sel.chain))
self.assertEqual('test', sel.chain[0])
self.assertEqual('values', sel.chain[1])
self.assertEqual(0, sel.chain[2])
self.assertEqual(1, sel(self.obj_for_test))
def test_items_selector(self):
sel = xmlutil.Selector('test', 'attrs', xmlutil.get_items)
self.assertEqual(len(sel.chain), 3)
self.assertEqual(3, len(sel.chain))
self.assertEqual(sel.chain[2], xmlutil.get_items)
for key, val in sel(self.obj_for_test):
self.assertEqual(self.obj_for_test['test']['attrs'][key], val)
@ -67,8 +67,8 @@ class SelectorTest(test.TestCase):
def test_constant_selector(self):
sel = xmlutil.ConstantSelector('Foobar')
self.assertEqual(sel.value, 'Foobar')
self.assertEqual(sel(self.obj_for_test), 'Foobar')
self.assertEqual('Foobar', sel.value)
self.assertEqual('Foobar', sel(self.obj_for_test))
class TemplateElementTest(test.TestCase):
@ -103,10 +103,10 @@ class TemplateElementTest(test.TestCase):
elem.set(k, v)
# Now verify what got set
self.assertEqual(len(elem.attrib['a'].chain), 1)
self.assertEqual(elem.attrib['a'].chain[0], 'a')
self.assertEqual(len(elem.attrib['b'].chain), 1)
self.assertEqual(elem.attrib['b'].chain[0], 'foo')
self.assertEqual(1, len(elem.attrib['a'].chain))
self.assertEqual('a', elem.attrib['a'].chain[0])
self.assertEqual(1, len(elem.attrib['b'].chain))
self.assertEqual('foo', elem.attrib['b'].chain[0])
self.assertEqual(elem.attrib['c'], attrs['c'])
def test_element_attribute_keys(self):
@ -117,7 +117,7 @@ class TemplateElementTest(test.TestCase):
elem = xmlutil.TemplateElement('test', attrib=attrs)
# Now verify keys
self.assertEqual(set(elem.keys()), expected)
self.assertEqual(expected, set(elem.keys()))
def test_element_attribute_items(self):
expected = dict(a=xmlutil.Selector(1),
@ -134,20 +134,20 @@ class TemplateElementTest(test.TestCase):
keys.remove(k)
# Did we visit all keys?
self.assertEqual(len(keys), 0)
self.assertEqual(0, len(keys))
def test_element_selector_none(self):
# Create a template element with no selector
elem = xmlutil.TemplateElement('test')
self.assertEqual(len(elem.selector.chain), 0)
self.assertEqual(0, len(elem.selector.chain))
def test_element_selector_string(self):
# Create a template element with a string selector
elem = xmlutil.TemplateElement('test', selector='test')
self.assertEqual(len(elem.selector.chain), 1)
self.assertEqual(elem.selector.chain[0], 'test')
self.assertEqual(1, len(elem.selector.chain))
self.assertEqual('test', elem.selector.chain[0])
def test_element_selector(self):
sel = xmlutil.Selector('a', 'b')
@ -167,8 +167,8 @@ class TemplateElementTest(test.TestCase):
# Create a template element with a string subselector
elem = xmlutil.TemplateElement('test', subselector='test')
self.assertEqual(len(elem.subselector.chain), 1)
self.assertEqual(elem.subselector.chain[0], 'test')
self.assertEqual(1, len(elem.subselector.chain))
self.assertEqual('test', elem.subselector.chain[0])
def test_element_subselector(self):
sel = xmlutil.Selector('a', 'b')
@ -183,7 +183,7 @@ class TemplateElementTest(test.TestCase):
elem = xmlutil.TemplateElement('test')
# Make sure the element starts off empty
self.assertEqual(len(elem), 0)
self.assertEqual(0, len(elem))
# Create a child element
child = xmlutil.TemplateElement('child')
@ -192,7 +192,7 @@ class TemplateElementTest(test.TestCase):
elem.append(child)
# Verify that the child was added
self.assertEqual(len(elem), 1)
self.assertEqual(1, len(elem))
self.assertEqual(elem[0], child)
self.assertIn('child', elem)
self.assertEqual(elem['child'], child)
@ -206,7 +206,7 @@ class TemplateElementTest(test.TestCase):
elem = xmlutil.TemplateElement('test')
# Make sure the element starts off empty
self.assertEqual(len(elem), 0)
self.assertEqual(0, len(elem))
# Create a few children
children = [xmlutil.TemplateElement('child1'),
@ -229,15 +229,15 @@ class TemplateElementTest(test.TestCase):
self.assertRaises(KeyError, elem.extend, children2)
# Also ensure that child4 was not added
self.assertEqual(len(elem), 3)
self.assertEqual(elem[-1].tag, 'child3')
self.assertEqual(3, len(elem))
self.assertEqual('child3', elem[-1].tag)
def test_element_insert_child(self):
# Create an element
elem = xmlutil.TemplateElement('test')
# Make sure the element starts off empty
self.assertEqual(len(elem), 0)
self.assertEqual(0, len(elem))
# Create a few children
children = [xmlutil.TemplateElement('child1'),
@ -254,7 +254,7 @@ class TemplateElementTest(test.TestCase):
elem.insert(1, child)
# Ensure the child was inserted in the right place
self.assertEqual(len(elem), 4)
self.assertEqual(4, len(elem))
children.insert(1, child)
for idx in range(len(elem)):
self.assertEqual(children[idx], elem[idx])
@ -270,7 +270,7 @@ class TemplateElementTest(test.TestCase):
elem = xmlutil.TemplateElement('test')
# Make sure the element starts off empty
self.assertEqual(len(elem), 0)
self.assertEqual(0, len(elem))
# Create a few children
children = [xmlutil.TemplateElement('child1'),
@ -287,15 +287,15 @@ class TemplateElementTest(test.TestCase):
self.assertRaises(ValueError, elem.remove, child)
# Ensure that no child was removed
self.assertEqual(len(elem), 3)
self.assertEqual(3, len(elem))
# Now remove a legitimate child
elem.remove(children[1])
# Ensure that the child was removed
self.assertEqual(len(elem), 2)
self.assertEqual(elem[0], children[0])
self.assertEqual(elem[1], children[2])
self.assertEqual(2, len(elem))
self.assertEqual(children[0], elem[0])
self.assertEqual(children[2], elem[1])
self.assertNotIn('child2', elem)
# Ensure the child cannot be retrieved by name
@ -312,9 +312,9 @@ class TemplateElementTest(test.TestCase):
# Try setting it to a string and ensure it becomes a selector
elem.text = 'test'
self.assertEqual(hasattr(elem.text, 'chain'), True)
self.assertEqual(len(elem.text.chain), 1)
self.assertEqual(elem.text.chain[0], 'test')
self.assertEqual(True, hasattr(elem.text, 'chain'))
self.assertEqual(1, len(elem.text.chain))
self.assertEqual('test', elem.text.chain[0])
# Try resetting the text to None
elem.text = None
@ -375,8 +375,8 @@ class TemplateElementTest(test.TestCase):
elem = master_elem._render(None, None, slave_elems, None)
# Verify the particulars of the render
self.assertEqual(elem.tag, 'test')
self.assertEqual(len(elem.nsmap), 0)
self.assertEqual('test', elem.tag)
self.assertEqual(0, len(elem.nsmap))
for k, v in elem.items():
self.assertEqual(str(attrs[k].value), v)
@ -387,10 +387,10 @@ class TemplateElementTest(test.TestCase):
elem = master_elem._render(parent, None, slave_elems, dict(a='foo'))
# Verify the particulars of the render
self.assertEqual(len(parent), 1)
self.assertEqual(1, len(parent))
self.assertEqual(parent[0], elem)
self.assertEqual(len(elem.nsmap), 1)
self.assertEqual(elem.nsmap['a'], 'foo')
self.assertEqual(1, len(elem.nsmap))
self.assertEqual('foo', elem.nsmap['a'])
def test_render(self):
# Create a template element
@ -402,18 +402,18 @@ class TemplateElementTest(test.TestCase):
# Try a render with no object
elems = tmpl_elem.render(None, None)
self.assertEqual(len(elems), 0)
self.assertEqual(0, len(elems))
# Try a render with one object
elems = tmpl_elem.render(None, 'foo')
self.assertEqual(len(elems), 1)
self.assertEqual(elems[0][0].text, 'foo')
self.assertEqual(elems[0][1], 'foo')
self.assertEqual(1, len(elems))
self.assertEqual('foo', elems[0][0].text)
self.assertEqual('foo', elems[0][1])
# Now, try rendering an object with multiple entries
parent = etree.Element('parent')
elems = tmpl_elem.render(parent, obj)
self.assertEqual(len(elems), 4)
self.assertEqual(4, len(elems))
# Check the results
for idx in range(len(obj)):
@ -423,13 +423,13 @@ class TemplateElementTest(test.TestCase):
def test_subelement(self):
# Try the SubTemplateElement constructor
parent = xmlutil.SubTemplateElement(None, 'parent')
self.assertEqual(parent.tag, 'parent')
self.assertEqual(len(parent), 0)
self.assertEqual('parent', parent.tag)
self.assertEqual(0, len(parent))
# Now try it with a parent element
child = xmlutil.SubTemplateElement(parent, 'child')
self.assertEqual(child.tag, 'child')
self.assertEqual(len(parent), 1)
self.assertEqual('child', child.tag)
self.assertEqual(1, len(parent))
self.assertEqual(parent[0], child)
def test_wrap(self):
@ -449,7 +449,7 @@ class TemplateElementTest(test.TestCase):
elems = tmpl_elem.render(parent, obj)
# Verify the particulars of the render
self.assertEqual(len(elems), len(obj))
self.assertEqual(len(obj), len(elems))
for idx in range(len(obj)):
self.assertEqual(elems[idx][0].tag, obj[idx])
@ -469,7 +469,7 @@ class TemplateTest(test.TestCase):
# Check that we get the right siblings
siblings = tmpl._siblings()
self.assertEqual(len(siblings), 1)
self.assertEqual(1, len(siblings))
self.assertEqual(siblings[0], elem)
def test__splitTagName(self):
@ -492,8 +492,8 @@ class TemplateTest(test.TestCase):
# Check out that we get the right namespace dictionary
nsmap = tmpl._nsmap()
self.assertNotEqual(id(nsmap), id(tmpl.nsmap))
self.assertEqual(len(nsmap), 1)
self.assertEqual(nsmap['a'], 'foo')
self.assertEqual(1, len(nsmap))
self.assertEqual('foo', nsmap['a'])
def test_master_attach(self):
# Set up a master template
@ -502,17 +502,17 @@ class TemplateTest(test.TestCase):
# Make sure it has a root but no slaves
self.assertEqual(tmpl.root, elem)
self.assertEqual(len(tmpl.slaves), 0)
self.assertEqual(0, len(tmpl.slaves))
# Try to attach an invalid slave
bad_elem = xmlutil.TemplateElement('test2')
self.assertRaises(ValueError, tmpl.attach, bad_elem)
self.assertEqual(len(tmpl.slaves), 0)
self.assertEqual(0, len(tmpl.slaves))
# Try to attach an invalid and a valid slave
good_elem = xmlutil.TemplateElement('test')
self.assertRaises(ValueError, tmpl.attach, good_elem, bad_elem)
self.assertEqual(len(tmpl.slaves), 0)
self.assertEqual(0, len(tmpl.slaves))
# Try to attach an inapplicable template
class InapplicableTemplate(xmlutil.Template):
@ -520,12 +520,12 @@ class TemplateTest(test.TestCase):
return False
inapp_tmpl = InapplicableTemplate(good_elem)
tmpl.attach(inapp_tmpl)
self.assertEqual(len(tmpl.slaves), 0)
self.assertEqual(0, len(tmpl.slaves))
# Now try attaching an applicable template
tmpl.attach(good_elem)
self.assertEqual(len(tmpl.slaves), 1)
self.assertEqual(tmpl.slaves[0].root, good_elem)
self.assertEqual(1, len(tmpl.slaves))
self.assertEqual(good_elem, tmpl.slaves[0].root)
def test_master_copy(self):
# Construct a master template
@ -555,31 +555,31 @@ class TemplateTest(test.TestCase):
# Construct a slave template with applicable minimum version
slave = xmlutil.SlaveTemplate(elem, 2)
self.assertEqual(slave.apply(master), True)
self.assertEqual(True, slave.apply(master))
# Construct a slave template with equal minimum version
slave = xmlutil.SlaveTemplate(elem, 3)
self.assertEqual(slave.apply(master), True)
self.assertEqual(True, slave.apply(master))
# Construct a slave template with inapplicable minimum version
slave = xmlutil.SlaveTemplate(elem, 4)
self.assertEqual(slave.apply(master), False)
self.assertEqual(False, slave.apply(master))
# Construct a slave template with applicable version range
slave = xmlutil.SlaveTemplate(elem, 2, 4)
self.assertEqual(slave.apply(master), True)
self.assertEqual(True, slave.apply(master))
# Construct a slave template with low version range
slave = xmlutil.SlaveTemplate(elem, 1, 2)
self.assertEqual(slave.apply(master), False)
self.assertEqual(False, slave.apply(master))
# Construct a slave template with high version range
slave = xmlutil.SlaveTemplate(elem, 4, 5)
self.assertEqual(slave.apply(master), False)
self.assertEqual(False, slave.apply(master))
# Construct a slave template with matching version range
slave = xmlutil.SlaveTemplate(elem, 3, 3)
self.assertEqual(slave.apply(master), True)
self.assertEqual(True, slave.apply(master))
def test__serialize(self):
# Our test object to serialize
@ -617,10 +617,10 @@ class TemplateTest(test.TestCase):
result = master._serialize(None, obj, siblings, nsmap)
# Now we get to manually walk the element tree...
self.assertEqual(result.tag, 'test')
self.assertEqual(len(result.nsmap), 2)
self.assertEqual(result.nsmap['f'], 'foo')
self.assertEqual(result.nsmap['b'], 'bar')
self.assertEqual('test', result.tag)
self.assertEqual(2, len(result.nsmap))
self.assertEqual('foo', result.nsmap['f'])
self.assertEqual('bar', result.nsmap['b'])
self.assertEqual(result.get('name'), obj['test']['name'])
for idx, val in enumerate(obj['test']['values']):
self.assertEqual(result[idx].tag, 'value')
@ -628,14 +628,14 @@ class TemplateTest(test.TestCase):
idx += 1
self.assertEqual(result[idx].tag, 'attrs')
for attr in result[idx]:
self.assertEqual(attr.tag, 'attr')
self.assertEqual(attr.get('value'),
str(obj['test']['attrs'][attr.get('key')]))
self.assertEqual('attr', attr.tag)
self.assertEqual(str(obj['test']['attrs'][attr.get('key')]),
attr.get('value'))
idx += 1
self.assertEqual(result[idx].tag, 'image')
self.assertEqual(result[idx].get('id'),
str(obj['test']['image']['id']))
self.assertEqual(result[idx].text, obj['test']['image']['name'])
self.assertEqual('image', result[idx].tag)
self.assertEqual(str(obj['test']['image']['id']),
result[idx].get('id'))
self.assertEqual(obj['test']['image']['name'], result[idx].text)
def test_serialize_with_delimiter(self):
# Our test object to serialize
@ -664,7 +664,7 @@ class TemplateTest(test.TestCase):
expected_xml = ''.join(xml_list)
result = serializer.serialize(obj)
result = result.replace('\n', '').replace(' ', '')
self.assertEqual(result, expected_xml)
self.assertEqual(expected_xml, result)
class MasterTemplateBuilder(xmlutil.TemplateBuilder):
@ -733,4 +733,4 @@ class MiscellaneousXMLUtilTests(test.TestCase):
root = xmlutil.make_flat_dict('wrapper')
tmpl = xmlutil.MasterTemplate(root, 1)
result = tmpl.serialize(dict(wrapper=dict(a='foo', b='bar')))
self.assertEqual(result, expected_xml)
self.assertEqual(expected_xml, result)

View File

@ -266,7 +266,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
request = webob.Request.blank("/")
response = request.get_response(self.app)
self.assertEqual(response.status_int, 413)
self.assertEqual(413, response.status_int)
self.assertIn('Retry-After', response.headers)
retry_after = int(response.headers['Retry-After'])
@ -275,7 +275,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
body = jsonutils.loads(response.body)
expected = "Only 1 GET request(s) can be made to * every minute."
value = body["overLimitFault"]["details"].strip()
self.assertEqual(value, expected)
self.assertEqual(expected, value)
def test_limited_request_xml(self):
"""Test a rate-limited (413) response as XML."""
@ -286,16 +286,16 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
request = webob.Request.blank("/")
request.accept = "application/xml"
response = request.get_response(self.app)
self.assertEqual(response.status_int, 413)
self.assertEqual(413, response.status_int)
root = minidom.parseString(response.body).childNodes[0]
expected = "Only 1 GET request(s) can be made to * every minute."
details = root.getElementsByTagName("details")
self.assertEqual(details.length, 1)
self.assertEqual(1, details.length)
value = details.item(0).firstChild.data.strip()
self.assertEqual(value, expected)
self.assertEqual(expected, value)
class LimitTest(BaseLimitTestSuite):
@ -369,28 +369,28 @@ class ParseLimitsTest(BaseLimitTestSuite):
assert False, six.text_type(e)
# Make sure the number of returned limits are correct
self.assertEqual(len(l), 4)
self.assertEqual(4, len(l))
# Check all the verbs...
expected = ['GET', 'PUT', 'POST', 'SAY']
self.assertEqual([t.verb for t in l], expected)
self.assertEqual(expected, [t.verb for t in l])
# ...the URIs...
expected = ['*', '/foo*', '/bar*', '/derp*']
self.assertEqual([t.uri for t in l], expected)
self.assertEqual(expected, [t.uri for t in l])
# ...the regexes...
expected = ['.*', '/foo.*', '/bar.*', '/derp.*']
self.assertEqual([t.regex for t in l], expected)
self.assertEqual(expected, [t.regex for t in l])
# ...the values...
expected = [20, 10, 5, 1]
self.assertEqual([t.value for t in l], expected)
self.assertEqual(expected, [t.value for t in l])
# ...and the units...
expected = [limits.PER_MINUTE, limits.PER_HOUR,
limits.PER_SECOND, limits.PER_DAY]
self.assertEqual([t.unit for t in l], expected)
self.assertEqual(expected, [t.unit for t in l])
class LimiterTest(BaseLimitTestSuite):
@ -418,12 +418,12 @@ class LimiterTest(BaseLimitTestSuite):
def test_no_delay_GET(self):
"""Ensure no delay on a single call for a limit verb we didn't set."""
delay = self.limiter.check_for_delay("GET", "/anything")
self.assertEqual(delay, (None, None))
self.assertEqual((None, None), delay)
def test_no_delay_PUT(self):
"""Ensure no delay on a single call for a known limit."""
delay = self.limiter.check_for_delay("PUT", "/anything")
self.assertEqual(delay, (None, None))
self.assertEqual((None, None), delay)
def test_delay_PUT(self):
"""Test delay on 11th PUT request.
@ -513,7 +513,7 @@ class LimiterTest(BaseLimitTestSuite):
def test_user_limit(self):
"""Test user-specific limits."""
self.assertEqual(self.limiter.levels['user3'], [])
self.assertEqual(len(self.limiter.levels['user0']), 2)
self.assertEqual(2, len(self.limiter.levels['user0']))
def test_multiple_users(self):
"""Tests involving multiple users."""
@ -592,17 +592,17 @@ class WsgiLimiterTest(BaseLimitTestSuite):
response = request.get_response(self.app)
if "X-Wait-Seconds" in response.headers:
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
return response.headers["X-Wait-Seconds"]
self.assertEqual(response.status_int, 204)
self.assertEqual(204, response.status_int)
def test_invalid_methods(self):
"""Only POSTs should work."""
for method in ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"]:
request = webob.Request.blank("/", method=method)
response = request.get_response(self.app)
self.assertEqual(response.status_int, 405)
self.assertEqual(405, response.status_int)
def test_good_url(self):
delay = self._request("GET", "/something")
@ -617,7 +617,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
self.assertIsNone(delay)
delay = self._request("GET", "/delayed")
self.assertEqual(delay, '60.00')
self.assertEqual('60.00', delay)
def test_response_to_delays_usernames(self):
delay = self._request("GET", "/delayed", "user1")
@ -627,10 +627,10 @@ class WsgiLimiterTest(BaseLimitTestSuite):
self.assertIsNone(delay)
delay = self._request("GET", "/delayed", "user1")
self.assertEqual(delay, '60.00')
self.assertEqual('60.00', delay)
delay = self._request("GET", "/delayed", "user2")
self.assertEqual(delay, '60.00')
self.assertEqual('60.00', delay)
class FakeHttplibSocket(object):
@ -745,12 +745,12 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
def test_200(self):
"""Successful request test."""
delay = self.proxy.check_for_delay("GET", "/anything")
self.assertEqual(delay, (None, None))
self.assertEqual((None, None), delay)
def test_403(self):
"""Forbidden request test."""
delay = self.proxy.check_for_delay("GET", "/delayed")
self.assertEqual(delay, (None, None))
self.assertEqual((None, None), delay)
delay, error = self.proxy.check_for_delay("GET", "/delayed")
error = error.strip()
@ -758,7 +758,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
"made to /delayed every minute.")
self.assertEqual((delay, error), expected)
self.assertEqual(expected, (delay, error))
class LimitsViewBuilderTest(test.TestCase):
@ -807,7 +807,7 @@ class LimitsViewBuilderTest(test.TestCase):
output = self.view_builder.build(self.rate_limits,
self.absolute_limits)
self.assertDictMatch(output, expected_limits)
self.assertDictMatch(expected_limits, output)
def test_build_limits_empty_limits(self):
expected_limits = {"limits": {"rate": [],
@ -816,7 +816,7 @@ class LimitsViewBuilderTest(test.TestCase):
abs_limits = {}
rate_limits = []
output = self.view_builder.build(rate_limits, abs_limits)
self.assertDictMatch(output, expected_limits)
self.assertDictMatch(expected_limits, output)
class LimitsXMLSerializationTest(test.TestCase):
@ -859,27 +859,27 @@ class LimitsXMLSerializationTest(test.TestCase):
# verify absolute limits
absolutes = root.xpath('ns:absolute/ns:limit', namespaces=NS)
self.assertEqual(len(absolutes), 4)
self.assertEqual(4, len(absolutes))
for limit in absolutes:
name = limit.get('name')
value = limit.get('value')
self.assertEqual(value, str(fixture['limits']['absolute'][name]))
self.assertEqual(str(fixture['limits']['absolute'][name]), value)
# verify rate limits
rates = root.xpath('ns:rates/ns:rate', namespaces=NS)
self.assertEqual(len(rates), 2)
self.assertEqual(2, len(rates))
for i, rate in enumerate(rates):
for key in ['uri', 'regex']:
self.assertEqual(rate.get(key),
str(fixture['limits']['rate'][i][key]))
self.assertEqual(str(fixture['limits']['rate'][i][key]),
rate.get(key))
rate_limits = rate.xpath('ns:limit', namespaces=NS)
self.assertEqual(len(rate_limits), 1)
self.assertEqual(1, len(rate_limits))
for j, limit in enumerate(rate_limits):
for key in ['verb', 'value', 'remaining', 'unit',
'next-available']:
self.assertEqual(
limit.get(key),
str(fixture['limits']['rate'][i]['limit'][j][key]))
str(fixture['limits']['rate'][i]['limit'][j][key]),
limit.get(key))
def test_index_no_limits(self):
serializer = limits.LimitsTemplate()
@ -894,8 +894,8 @@ class LimitsXMLSerializationTest(test.TestCase):
# verify absolute limits
absolutes = root.xpath('ns:absolute/ns:limit', namespaces=NS)
self.assertEqual(len(absolutes), 0)
self.assertEqual(0, len(absolutes))
# verify rate limits
rates = root.xpath('ns:rates/ns:rate', namespaces=NS)
self.assertEqual(len(rates), 0)
self.assertEqual(0, len(rates))

View File

@ -107,10 +107,10 @@ class SnapshotApiTest(test.TestCase):
resp_dict = self.controller.create(req, body)
self.assertIn('snapshot', resp_dict)
self.assertEqual(resp_dict['snapshot']['name'],
snapshot_name)
self.assertEqual(resp_dict['snapshot']['description'],
snapshot_description)
self.assertEqual(snapshot_name,
resp_dict['snapshot']['name'])
self.assertEqual(snapshot_description,
resp_dict['snapshot']['description'])
def test_snapshot_create_force(self):
self.stubs.Set(volume.api.API, "create_snapshot_force",
@ -129,10 +129,10 @@ class SnapshotApiTest(test.TestCase):
resp_dict = self.controller.create(req, body)
self.assertIn('snapshot', resp_dict)
self.assertEqual(resp_dict['snapshot']['name'],
snapshot_name)
self.assertEqual(resp_dict['snapshot']['description'],
snapshot_description)
self.assertEqual(snapshot_name,
resp_dict['snapshot']['name'])
self.assertEqual(snapshot_description,
resp_dict['snapshot']['description'])
snapshot = {
"volume_id": "12",
@ -251,7 +251,7 @@ class SnapshotApiTest(test.TestCase):
snapshot_id = UUID
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
resp = self.controller.delete(req, snapshot_id)
self.assertEqual(resp.status_int, 202)
self.assertEqual(202, resp.status_int)
def test_snapshot_delete_invalid_id(self):
self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete)
@ -283,7 +283,7 @@ class SnapshotApiTest(test.TestCase):
resp_dict = self.controller.show(req, UUID)
self.assertIn('snapshot', resp_dict)
self.assertEqual(resp_dict['snapshot']['id'], UUID)
self.assertEqual(UUID, resp_dict['snapshot']['id'])
def test_snapshot_show_invalid_id(self):
snapshot_id = INVALID_UUID
@ -319,10 +319,10 @@ class SnapshotApiTest(test.TestCase):
self.assertIn('snapshots', resp_dict)
resp_snapshots = resp_dict['snapshots']
self.assertEqual(len(resp_snapshots), 1)
self.assertEqual(1, len(resp_snapshots))
resp_snapshot = resp_snapshots.pop()
self.assertEqual(resp_snapshot['id'], UUID)
self.assertEqual(UUID, resp_snapshot['id'])
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
def test_admin_list_snapshots_limited_to_project(self,
@ -407,7 +407,7 @@ class SnapshotApiTest(test.TestCase):
class SnapshotSerializerTest(test.TestCase):
def _verify_snapshot(self, snap, tree):
self.assertEqual(tree.tag, 'snapshot')
self.assertEqual('snapshot', tree.tag)
for attr in ('id', 'status', 'size', 'created_at',
'name', 'description', 'volume_id'):

View File

@ -92,7 +92,7 @@ class VolumeTypesApiTest(test.TestCase):
expected_names = ['vol_type_1', 'vol_type_2', 'vol_type_3']
actual_names = map(lambda e: e['name'], res_dict['volume_types'])
self.assertEqual(set(actual_names), set(expected_names))
self.assertEqual(set(expected_names), set(actual_names))
for entry in res_dict['volume_types']:
self.assertEqual('value1', entry['extra_specs']['key1'])
@ -221,7 +221,7 @@ class VolumeTypesSerializerTest(test.TestCase):
self.assertIn(child.tag, seen)
self.assertEqual(vtype['extra_specs'][child.tag], child.text)
seen.remove(child.tag)
self.assertEqual(len(seen), 0)
self.assertEqual(0, len(seen))
def test_index_serializer(self):
serializer = types.VolumeTypesTemplate()

View File

@ -111,7 +111,7 @@ class VolumeApiTest(test.TestCase):
'user_id': 'fakeuser',
'volume_type': 'vol_type_name',
'encrypted': False}}
self.assertEqual(res_dict, ex)
self.assertEqual(ex, res_dict)
def test_volume_create_with_consistencygroup_invalid_type(self):
ctxt = context.RequestContext('fake', 'fake', auth_token=True)
@ -170,14 +170,14 @@ class VolumeApiTest(test.TestCase):
body.update(dict(volume=vol))
res_dict = self.controller.create(req, body)
volume_id = res_dict['volume']['id']
self.assertEqual(len(res_dict), 1)
self.assertEqual(1, len(res_dict))
# Use correct volume type id
vol.update(dict(volume_type=db_vol_type['id']))
body.update(dict(volume=vol))
res_dict = self.controller.create(req, body)
volume_id = res_dict['volume']['id']
self.assertEqual(len(res_dict), 1)
self.assertEqual(1, len(res_dict))
self.stubs.Set(volume_api.API, 'get_all',
lambda *args, **kwargs:
@ -476,7 +476,7 @@ class VolumeApiTest(test.TestCase):
}
body = {"volume": updates}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
res_dict = self.controller.update(req, '1', body)
expected = {
'volume': {
@ -510,8 +510,8 @@ class VolumeApiTest(test.TestCase):
],
}
}
self.assertEqual(res_dict, expected)
self.assertEqual(len(self.notifier.notifications), 2)
self.assertEqual(expected, res_dict)
self.assertEqual(2, len(self.notifier.notifications))
def test_volume_update_deprecation(self):
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
@ -523,7 +523,7 @@ class VolumeApiTest(test.TestCase):
}
body = {"volume": updates}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
res_dict = self.controller.update(req, '1', body)
expected = {
'volume': {
@ -557,8 +557,8 @@ class VolumeApiTest(test.TestCase):
],
}
}
self.assertEqual(res_dict, expected)
self.assertEqual(len(self.notifier.notifications), 2)
self.assertEqual(expected, res_dict)
self.assertEqual(2, len(self.notifier.notifications))
def test_volume_update_deprecation_key_priority(self):
"""Test current update keys have priority over deprecated keys."""
@ -573,7 +573,7 @@ class VolumeApiTest(test.TestCase):
}
body = {"volume": updates}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
res_dict = self.controller.update(req, '1', body)
expected = {
'volume': {
@ -607,8 +607,8 @@ class VolumeApiTest(test.TestCase):
],
}
}
self.assertEqual(res_dict, expected)
self.assertEqual(len(self.notifier.notifications), 2)
self.assertEqual(expected, res_dict)
self.assertEqual(2, len(self.notifier.notifications))
def test_volume_update_metadata(self):
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
@ -619,7 +619,7 @@ class VolumeApiTest(test.TestCase):
}
body = {"volume": updates}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
res_dict = self.controller.update(req, '1', body)
expected = {'volume': {
'status': 'fakestatus',
@ -653,8 +653,8 @@ class VolumeApiTest(test.TestCase):
}
],
}}
self.assertEqual(res_dict, expected)
self.assertEqual(len(self.notifier.notifications), 2)
self.assertEqual(expected, res_dict)
self.assertEqual(2, len(self.notifier.notifications))
def test_volume_update_with_admin_metadata(self):
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
@ -679,7 +679,7 @@ class VolumeApiTest(test.TestCase):
}
body = {"volume": updates}
req = fakes.HTTPRequest.blank('/v2/volumes/1')
self.assertEqual(len(self.notifier.notifications), 0)
self.assertEqual(0, len(self.notifier.notifications))
admin_ctx = context.RequestContext('admin', 'fake', True)
req.environ['cinder.context'] = admin_ctx
res_dict = self.controller.update(req, '1', body)
@ -777,7 +777,7 @@ class VolumeApiTest(test.TestCase):
}
]
}
self.assertEqual(res_dict, expected)
self.assertEqual(expected, res_dict)
# Finally test that we cached the returned volumes
self.assertEqual(1, len(req.cached_resource()))
@ -823,7 +823,7 @@ class VolumeApiTest(test.TestCase):
}
]
}
self.assertEqual(res_dict, expected)
self.assertEqual(expected, res_dict)
# Finally test that we cached the returned volumes
self.assertEqual(1, len(req.cached_resource()))
@ -891,7 +891,7 @@ class VolumeApiTest(test.TestCase):
}
]
}
self.assertEqual(res_dict, expected)
self.assertEqual(expected, res_dict)
def test_volume_index_with_marker(self):
def stub_volume_get_all_by_project(context, project_id, marker, limit,
@ -910,8 +910,8 @@ class VolumeApiTest(test.TestCase):
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 2)
self.assertEqual(volumes[0]['id'], 1)
self.assertEqual(volumes[1]['id'], 2)
self.assertEqual(1, volumes[0]['id'])
self.assertEqual(2, volumes[1]['id'])
def test_volume_index_limit(self):
self.stubs.Set(db, 'volume_get_all_by_project',
@ -923,7 +923,7 @@ class VolumeApiTest(test.TestCase):
'&sort=id1:asc')
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(1, len(volumes))
# Ensure that the next link is correctly formatted, it should
# contain the same limit, filter, and sort information as the
@ -931,7 +931,7 @@ class VolumeApiTest(test.TestCase):
# caller can simply use the "next" link and that they do not
# need to manually insert the limit and sort information.
links = res_dict['volumes_links']
self.assertEqual(links[0]['rel'], 'next')
self.assertEqual('next', links[0]['rel'])
href_parts = urllib.parse.urlparse(links[0]['href'])
self.assertEqual('/v2/fakeproject/volumes', href_parts.path)
params = urllib.parse.parse_qs(href_parts.query)
@ -960,8 +960,8 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes?marker=1&limit=1')
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['id'], '1')
self.assertEqual(1, len(volumes))
self.assertEqual('1', volumes[0]['id'])
def test_volume_index_limit_offset(self):
def stub_volume_get_all_by_project(context, project_id, marker, limit,
@ -979,8 +979,8 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes?limit=2&offset=1')
res_dict = self.controller.index(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['id'], 2)
self.assertEqual(1, len(volumes))
self.assertEqual(2, volumes[0]['id'])
req = fakes.HTTPRequest.blank('/v2/volumes?limit=-1&offset=1')
self.assertRaises(exception.InvalidInput,
@ -1008,9 +1008,9 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes/detail?marker=1')
res_dict = self.controller.detail(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 2)
self.assertEqual(volumes[0]['id'], 1)
self.assertEqual(volumes[1]['id'], 2)
self.assertEqual(2, len(volumes))
self.assertEqual(1, volumes[0]['id'])
self.assertEqual(2, volumes[1]['id'])
def test_volume_detail_limit(self):
self.stubs.Set(db, 'volume_get_all_by_project',
@ -1020,11 +1020,11 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=1')
res_dict = self.controller.detail(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(1, len(volumes))
# Ensure that the next link is correctly formatted
links = res_dict['volumes_links']
self.assertEqual(links[0]['rel'], 'next')
self.assertEqual('next', links[0]['rel'])
href_parts = urllib.parse.urlparse(links[0]['href'])
self.assertEqual('/v2/fakeproject/volumes/detail', href_parts.path)
params = urllib.parse.parse_qs(href_parts.query)
@ -1051,8 +1051,8 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes/detail?marker=1&limit=1')
res_dict = self.controller.detail(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['id'], '1')
self.assertEqual(1, len(volumes))
self.assertEqual('1', volumes[0]['id'])
def test_volume_detail_limit_offset(self):
def stub_volume_get_all_by_project(context, project_id, marker, limit,
@ -1070,15 +1070,15 @@ class VolumeApiTest(test.TestCase):
req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=2&offset=1')
res_dict = self.controller.detail(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['id'], 2)
self.assertEqual(1, len(volumes))
self.assertEqual(2, volumes[0]['id'])
req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=2&offset=1',
use_admin_context=True)
res_dict = self.controller.detail(req)
volumes = res_dict['volumes']
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['id'], 2)
self.assertEqual(1, len(volumes))
self.assertEqual(2, volumes[0]['id'])
req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=-1&offset=1')
self.assertRaises(exception.InvalidInput,

View File

@ -38,7 +38,7 @@ class NameIDsTestCase(test.TestCase):
vol_ref = testutils.create_volume(self.ctxt, size=1)
self.assertEqual(vol_ref['name_id'], vol_ref['id'])
expected_name = CONF.volume_name_template % vol_ref['id']
self.assertEqual(vol_ref['name'], expected_name)
self.assertEqual(expected_name, vol_ref['name'])
def test_name_id_diff(self):
"""Change name ID to mimic volume after migration."""
@ -46,7 +46,7 @@ class NameIDsTestCase(test.TestCase):
db.volume_update(self.ctxt, vol_ref['id'], {'name_id': 'fake'})
vol_ref = db.volume_get(self.ctxt, vol_ref['id'])
expected_name = CONF.volume_name_template % 'fake'
self.assertEqual(vol_ref['name'], expected_name)
self.assertEqual(expected_name, vol_ref['name'])
def test_name_id_snapshot_volume_name(self):
"""Make sure snapshot['volume_name'] is updated."""
@ -54,4 +54,4 @@ class NameIDsTestCase(test.TestCase):
db.volume_update(self.ctxt, vol_ref['id'], {'name_id': 'fake'})
snap_ref = testutils.create_snapshot(self.ctxt, vol_ref['id'])
expected_name = CONF.volume_name_template % 'fake'
self.assertEqual(snap_ref['volume_name'], expected_name)
self.assertEqual(expected_name, snap_ref['volume_name'])

View File

@ -92,7 +92,7 @@ class QualityOfServiceSpecsTableTestCase(test.TestCase):
spec_id3 = self._create_qos_specs('Name3', value3)
specs = db.qos_specs_get_all(self.ctxt)
self.assertEqual(len(specs), 3,
self.assertEqual(3, len(specs),
"Unexpected number of qos specs records")
expected1 = dict(name='Name1', id=spec_id1, consumer='front-end')
@ -153,9 +153,9 @@ class QualityOfServiceSpecsTableTestCase(test.TestCase):
specs_id = self._create_qos_specs('FakeQos')
db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['id'], type_id)
self.assertEqual(res[0]['qos_specs_id'], specs_id)
self.assertEqual(1, len(res))
self.assertEqual(type_id, res[0]['id'])
self.assertEqual(specs_id, res[0]['qos_specs_id'])
def test_qos_associations_get(self):
self.assertRaises(exception.QoSSpecsNotFound,
@ -165,32 +165,32 @@ class QualityOfServiceSpecsTableTestCase(test.TestCase):
type_id = volume_types.create(self.ctxt, 'TypeName')['id']
specs_id = self._create_qos_specs('FakeQos')
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 0)
self.assertEqual(0, len(res))
db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['id'], type_id)
self.assertEqual(res[0]['qos_specs_id'], specs_id)
self.assertEqual(1, len(res))
self.assertEqual(type_id, res[0]['id'])
self.assertEqual(specs_id, res[0]['qos_specs_id'])
type0_id = volume_types.create(self.ctxt, 'Type0Name')['id']
db.volume_type_qos_associate(self.ctxt, type0_id, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 2)
self.assertEqual(res[0]['qos_specs_id'], specs_id)
self.assertEqual(res[1]['qos_specs_id'], specs_id)
self.assertEqual(2, len(res))
self.assertEqual(specs_id, res[0]['qos_specs_id'])
self.assertEqual(specs_id, res[1]['qos_specs_id'])
def test_qos_specs_disassociate(self):
type_id = volume_types.create(self.ctxt, 'TypeName')['id']
specs_id = self._create_qos_specs('FakeQos')
db.volume_type_qos_associate(self.ctxt, type_id, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(res[0]['id'], type_id)
self.assertEqual(res[0]['qos_specs_id'], specs_id)
self.assertEqual(type_id, res[0]['id'])
self.assertEqual(specs_id, res[0]['qos_specs_id'])
db.qos_specs_disassociate(self.ctxt, specs_id, type_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 0)
self.assertEqual(0, len(res))
res = db.volume_type_get(self.ctxt, type_id)
self.assertIsNone(res['qos_specs_id'])
@ -204,11 +204,11 @@ class QualityOfServiceSpecsTableTestCase(test.TestCase):
db.volume_type_qos_associate(self.ctxt, type3_id, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 3)
self.assertEqual(3, len(res))
db.qos_specs_disassociate_all(self.ctxt, specs_id)
res = db.qos_specs_associations_get(self.ctxt, specs_id)
self.assertEqual(len(res), 0)
self.assertEqual(0, len(res))
def test_qos_specs_update(self):
name = 'FakeName'
@ -219,5 +219,5 @@ class QualityOfServiceSpecsTableTestCase(test.TestCase):
self.ctxt, 'Fake-UUID', value)
db.qos_specs_update(self.ctxt, specs_id, value)
specs = db.qos_specs_get(self.ctxt, specs_id)
self.assertEqual(specs['specs']['key2'], 'new_value2')
self.assertEqual(specs['specs']['key3'], 'value3')
self.assertEqual('new_value2', specs['specs']['key2'])
self.assertEqual('value3', specs['specs']['key3'])

View File

@ -59,7 +59,7 @@ class TransfersTableTestCase(test.TestCase):
xfer_id1 = self._create_transfer(volume_id1)
xfer = db.transfer_get(self.ctxt, xfer_id1)
self.assertEqual(xfer.volume_id, volume_id1, "Unexpected volume_id")
self.assertEqual(volume_id1, xfer.volume_id, "Unexpected volume_id")
nctxt = context.RequestContext(user_id='new_user_id',
project_id='new_project_id')
@ -67,7 +67,7 @@ class TransfersTableTestCase(test.TestCase):
db.transfer_get, nctxt, xfer_id1)
xfer = db.transfer_get(nctxt.elevated(), xfer_id1)
self.assertEqual(xfer.volume_id, volume_id1, "Unexpected volume_id")
self.assertEqual(volume_id1, xfer.volume_id, "Unexpected volume_id")
def test_transfer_get_all(self):
volume_id1 = utils.create_volume(self.ctxt)['id']
@ -79,10 +79,10 @@ class TransfersTableTestCase(test.TestCase):
db.transfer_get_all,
self.ctxt)
xfer = db.transfer_get_all(context.get_admin_context())
self.assertEqual(len(xfer), 2, "Unexpected number of transfer records")
self.assertEqual(2, len(xfer), "Unexpected number of transfer records")
xfer = db.transfer_get_all_by_project(self.ctxt, self.ctxt.project_id)
self.assertEqual(len(xfer), 2, "Unexpected number of transfer records")
self.assertEqual(2, len(xfer), "Unexpected number of transfer records")
nctxt = context.RequestContext(user_id='new_user_id',
project_id='new_project_id')
@ -91,7 +91,7 @@ class TransfersTableTestCase(test.TestCase):
nctxt, self.ctxt.project_id)
xfer = db.transfer_get_all_by_project(nctxt.elevated(),
self.ctxt.project_id)
self.assertEqual(len(xfer), 2, "Unexpected number of transfer records")
self.assertEqual(2, len(xfer), "Unexpected number of transfer records")
def test_transfer_destroy(self):
volume_id = utils.create_volume(self.ctxt)['id']
@ -100,12 +100,12 @@ class TransfersTableTestCase(test.TestCase):
xfer_id2 = self._create_transfer(volume_id2)
xfer = db.transfer_get_all(context.get_admin_context())
self.assertEqual(len(xfer), 2, "Unexpected number of transfer records")
self.assertEqual(2, len(xfer), "Unexpected number of transfer records")
self.assertFalse(xfer[0]['deleted'], "Deleted flag is set")
db.transfer_destroy(self.ctxt, xfer_id1)
xfer = db.transfer_get_all(context.get_admin_context())
self.assertEqual(len(xfer), 1, "Unexpected number of transfer records")
self.assertEqual(1, len(xfer), "Unexpected number of transfer records")
self.assertEqual(xfer[0]['id'], xfer_id2,
"Unexpected value for Transfer id")
@ -116,4 +116,4 @@ class TransfersTableTestCase(test.TestCase):
db.transfer_destroy(nctxt.elevated(), xfer_id2)
xfer = db.transfer_get_all(context.get_admin_context())
self.assertEqual(len(xfer), 0, "Unexpected number of transfer records")
self.assertEqual(0, len(xfer), "Unexpected number of transfer records")

View File

@ -64,8 +64,8 @@ class TestGlanceSerializer(test.TestCase):
'[{"device_name": "/dev/fake"}, '
'{"device_name": "/dev/fake0"}]'}}
converted = glance._convert_to_string(metadata)
self.assertEqual(converted, converted_expected)
self.assertEqual(glance._convert_from_string(converted), metadata)
self.assertEqual(converted_expected, converted)
self.assertEqual(metadata, glance._convert_from_string(converted))
class TestGlanceImageService(test.TestCase):
@ -220,8 +220,8 @@ class TestGlanceImageService(test.TestCase):
self.context.project_id = proj
self.assertEqual(1, len(image_metas))
self.assertEqual(image_metas[0]['name'], 'test image')
self.assertEqual(image_metas[0]['is_public'], False)
self.assertEqual('test image', image_metas[0]['name'])
self.assertEqual(False, image_metas[0]['is_public'])
def test_detail_marker(self):
fixtures = []
@ -232,7 +232,7 @@ class TestGlanceImageService(test.TestCase):
ids.append(self.service.create(self.context, fixture)['id'])
image_metas = self.service.detail(self.context, marker=ids[1])
self.assertEqual(len(image_metas), 8)
self.assertEqual(8, len(image_metas))
i = 2
for meta in image_metas:
expected = {
@ -266,7 +266,7 @@ class TestGlanceImageService(test.TestCase):
ids.append(self.service.create(self.context, fixture)['id'])
image_metas = self.service.detail(self.context, limit=5)
self.assertEqual(len(image_metas), 5)
self.assertEqual(5, len(image_metas))
def test_detail_default_limit(self):
fixtures = []
@ -289,7 +289,7 @@ class TestGlanceImageService(test.TestCase):
ids.append(self.service.create(self.context, fixture)['id'])
image_metas = self.service.detail(self.context, marker=ids[3], limit=5)
self.assertEqual(len(image_metas), 5)
self.assertEqual(5, len(image_metas))
i = 4
for meta in image_metas:
expected = {
@ -378,7 +378,7 @@ class TestGlanceImageService(test.TestCase):
'properties': {},
'owner': None,
}
self.assertEqual(image_meta, expected)
self.assertEqual(expected, image_meta)
def test_show_raises_when_no_authtoken_in_the_context(self):
fixture = self._make_fixture(name='image1',
@ -415,21 +415,21 @@ class TestGlanceImageService(test.TestCase):
'owner': None,
},
]
self.assertEqual(image_metas, expected)
self.assertEqual(expected, image_metas)
def test_show_makes_datetimes(self):
fixture = self._make_datetime_fixture()
image_id = self.service.create(self.context, fixture)['id']
image_meta = self.service.show(self.context, image_id)
self.assertEqual(image_meta['created_at'], self.NOW_DATETIME)
self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME)
self.assertEqual(self.NOW_DATETIME, image_meta['created_at'])
self.assertEqual(self.NOW_DATETIME, image_meta['updated_at'])
def test_detail_makes_datetimes(self):
fixture = self._make_datetime_fixture()
self.service.create(self.context, fixture)
image_meta = self.service.detail(self.context)[0]
self.assertEqual(image_meta['created_at'], self.NOW_DATETIME)
self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME)
self.assertEqual(self.NOW_DATETIME, image_meta['created_at'])
self.assertEqual(self.NOW_DATETIME, image_meta['updated_at'])
def test_download_with_retries(self):
tries = [0]
@ -552,13 +552,13 @@ class TestGlanceImageService(test.TestCase):
(service, same_id) = glance.get_remote_image_service(self.context,
image_url)
self.assertEqual(same_id, image_id)
self.assertEqual(service._client.netloc, 'something-less-likely')
self.assertEqual('something-less-likely', service._client.netloc)
for ipv6_url in ('[::1]', '::1', '[::1]:444'):
image_url = 'http://%s/%s' % (ipv6_url, image_id)
(service, same_id) = glance.get_remote_image_service(self.context,
image_url)
self.assertEqual(same_id, image_id)
self.assertEqual(service._client.netloc, ipv6_url)
self.assertEqual(ipv6_url, service._client.netloc)
def test_extracting_missing_attributes(self):
"""Verify behavior from glance objects that are missing attributes
@ -602,7 +602,7 @@ class TestGlanceImageService(test.TestCase):
'properties': {},
'owner': None,
}
self.assertEqual(actual, expected)
self.assertEqual(expected, actual)
@mock.patch('cinder.image.glance.CONF')
def test_extracting_v2_boot_properties(self, config):

View File

@ -124,8 +124,8 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
self.assertEqual(1, len(create_actions))
create_action = create_actions[0]
self.assertEqual(create_action['id'], created_volume_id)
self.assertEqual(create_action['availability_zone'], 'nova')
self.assertEqual(create_action['size'], 1)
self.assertEqual('nova', create_action['availability_zone'])
self.assertEqual(1, create_action['size'])
export_actions = fake_driver.LoggingVolumeDriver.logs_like(
'create_export',
@ -133,7 +133,7 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
self.assertEqual(1, len(export_actions))
export_action = export_actions[0]
self.assertEqual(export_action['id'], created_volume_id)
self.assertEqual(export_action['availability_zone'], 'nova')
self.assertEqual('nova', export_action['availability_zone'])
delete_actions = fake_driver.LoggingVolumeDriver.logs_like(
'delete_volume',
@ -181,15 +181,15 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
# Create vol1
created_volume = self.api.post_volume({'volume': {
'size': 1, 'name': 'vol1'}})
self.assertEqual(created_volume['name'], 'vol1')
self.assertEqual('vol1', created_volume['name'])
created_volume_id = created_volume['id']
# update volume
body = {'volume': {'name': 'vol-one'}}
updated_volume = self.api.put_volume(created_volume_id, body)
self.assertEqual(updated_volume['name'], 'vol-one')
self.assertEqual('vol-one', updated_volume['name'])
# check for update
found_volume = self.api.get_volume(created_volume_id)
self.assertEqual(created_volume_id, found_volume['id'])
self.assertEqual(found_volume['name'], 'vol-one')
self.assertEqual('vol-one', found_volume['name'])

View File

@ -46,13 +46,13 @@ class SymmetricKeyTestCase(KeyTestCase):
super(SymmetricKeyTestCase, self).setUp()
def test_get_algorithm(self):
self.assertEqual(self.key.get_algorithm(), self.algorithm)
self.assertEqual(self.algorithm, self.key.get_algorithm())
def test_get_format(self):
self.assertEqual(self.key.get_format(), 'RAW')
self.assertEqual('RAW', self.key.get_format())
def test_get_encoded(self):
self.assertEqual(self.key.get_encoded(), self.encoded)
self.assertEqual(self.encoded, self.key.get_encoded())
def test___eq__(self):
self.assertTrue(self.key == self.key)

View File

@ -64,9 +64,9 @@ class AllocatedCapacityWeigherTestCase(test.TestCase):
# so, host1 should win:
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, 0)
self.assertEqual(0, weighed_host.weight)
self.assertEqual(
utils.extract_host(weighed_host.obj.host), 'host1')
'host1', utils.extract_host(weighed_host.obj.host))
def test_capacity_weight_multiplier1(self):
self.flags(allocated_capacity_weight_multiplier=1.0)
@ -79,9 +79,9 @@ class AllocatedCapacityWeigherTestCase(test.TestCase):
# so, host4 should win:
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, 1848.0)
self.assertEqual(1848.0, weighed_host.weight)
self.assertEqual(
utils.extract_host(weighed_host.obj.host), 'host4')
'host4', utils.extract_host(weighed_host.obj.host))
def test_capacity_weight_multiplier2(self):
self.flags(allocated_capacity_weight_multiplier=-2.0)
@ -96,4 +96,4 @@ class AllocatedCapacityWeigherTestCase(test.TestCase):
weighed_host = self._get_weighed_host(hostinfo_list)
self.assertEqual(weighed_host.weight, 0)
self.assertEqual(
utils.extract_host(weighed_host.obj.host), 'host1')
'host1', utils.extract_host(weighed_host.obj.host))

View File

@ -62,8 +62,8 @@ class HostManagerTestCase(test.TestCase):
# Test 'volume' returns 1 correct function
filter_classes = self.host_manager._choose_host_filters(None)
self.assertEqual(len(filter_classes), 1)
self.assertEqual(filter_classes[0].__name__, 'FakeFilterClass2')
self.assertEqual(1, len(filter_classes))
self.assertEqual('FakeFilterClass2', filter_classes[0].__name__)
@mock.patch('cinder.scheduler.host_manager.HostManager.'
'_choose_host_filters')
@ -82,7 +82,7 @@ class HostManagerTestCase(test.TestCase):
result = self.host_manager.get_filtered_hosts(self.fake_hosts,
fake_properties)
self.assertEqual(expected, mock_func.call_args_list)
self.assertEqual(set(result), set(self.fake_hosts))
self.assertEqual(set(self.fake_hosts), set(result))
@mock.patch('oslo_utils.timeutils.utcnow')
def test_update_service_capabilities(self, _mock_utcnow):
@ -105,7 +105,7 @@ class HostManagerTestCase(test.TestCase):
# Make sure dictionary isn't re-assigned
self.assertEqual(self.host_manager.service_states, service_states)
# Make sure original dictionary wasn't copied
self.assertEqual(host1_volume_capabs['timestamp'], 1)
self.assertEqual(1, host1_volume_capabs['timestamp'])
host1_volume_capabs['timestamp'] = 31337
host2_volume_capabs['timestamp'] = 31338
@ -253,7 +253,7 @@ class HostManagerTestCase(test.TestCase):
# Get host_state_map and make sure we have the first 4 hosts
host_state_map = self.host_manager.host_state_map
self.assertEqual(len(host_state_map), 3)
self.assertEqual(3, len(host_state_map))
for i in range(3):
volume_node = services[i]
host = volume_node['host']
@ -279,7 +279,7 @@ class HostManagerTestCase(test.TestCase):
# Get host_state_map and make sure we have the first 2 hosts (host3 is
# down, host4 is missing capabilities)
host_state_map = self.host_manager.host_state_map
self.assertEqual(len(host_state_map), 2)
self.assertEqual(2, len(host_state_map))
for i in range(2):
volume_node = services[i]
host = volume_node['host']
@ -450,16 +450,16 @@ class HostStateTestCase(test.TestCase):
fake_host.update_from_volume_capability(capability)
self.assertEqual(fake_host.volume_backend_name, 'Local iSCSI')
self.assertEqual(fake_host.storage_protocol, 'iSCSI')
self.assertEqual(fake_host.vendor_name, 'OpenStack')
self.assertEqual(fake_host.driver_version, '1.0.1')
self.assertEqual('Local iSCSI', fake_host.volume_backend_name)
self.assertEqual('iSCSI', fake_host.storage_protocol)
self.assertEqual('OpenStack', fake_host.vendor_name)
self.assertEqual('1.0.1', fake_host.driver_version)
# Backend level stats remain uninitialized
self.assertEqual(fake_host.total_capacity_gb, 0)
self.assertEqual(fake_host.free_capacity_gb, None)
self.assertEqual(0, fake_host.total_capacity_gb)
self.assertEqual(None, fake_host.free_capacity_gb)
# Pool stats has been updated
self.assertEqual(len(fake_host.pools), 2)
self.assertEqual(2, len(fake_host.pools))
self.assertEqual(500, fake_host.pools['1st pool'].total_capacity_gb)
self.assertEqual(230, fake_host.pools['1st pool'].free_capacity_gb)
@ -491,10 +491,10 @@ class HostStateTestCase(test.TestCase):
# test update HostState Record
fake_host.update_from_volume_capability(capability)
self.assertEqual(fake_host.driver_version, '1.0.2')
self.assertEqual('1.0.2', fake_host.driver_version)
# Non-active pool stats has been removed
self.assertEqual(len(fake_host.pools), 1)
self.assertEqual(1, len(fake_host.pools))
self.assertRaises(KeyError, lambda: fake_host.pools['1st pool'])
self.assertRaises(KeyError, lambda: fake_host.pools['2nd pool'])
@ -515,13 +515,15 @@ class HostStateTestCase(test.TestCase):
fake_host.update_from_volume_capability(volume_capability)
# Backend level stats remain uninitialized
self.assertEqual(fake_host.total_capacity_gb, 0)
self.assertEqual(fake_host.free_capacity_gb, None)
self.assertEqual(0, fake_host.total_capacity_gb)
self.assertEqual(None, fake_host.free_capacity_gb)
# Pool stats has been updated
self.assertEqual(fake_host.pools['_pool0'].total_capacity_gb,
'infinite')
self.assertEqual(fake_host.pools['_pool0'].free_capacity_gb,
'infinite')
self.assertEqual(
'infinite',
fake_host.pools['_pool0'].total_capacity_gb)
self.assertEqual(
'infinite',
fake_host.pools['_pool0'].free_capacity_gb)
def test_update_from_volume_unknown_capability(self):
fake_host = host_manager.HostState('host1')
@ -534,13 +536,15 @@ class HostStateTestCase(test.TestCase):
fake_host.update_from_volume_capability(volume_capability)
# Backend level stats remain uninitialized
self.assertEqual(fake_host.total_capacity_gb, 0)
self.assertEqual(fake_host.free_capacity_gb, None)
self.assertEqual(0, fake_host.total_capacity_gb)
self.assertEqual(None, fake_host.free_capacity_gb)
# Pool stats has been updated
self.assertEqual(fake_host.pools['_pool0'].total_capacity_gb,
'infinite')
self.assertEqual(fake_host.pools['_pool0'].free_capacity_gb,
'unknown')
self.assertEqual(
'infinite',
fake_host.pools['_pool0'].total_capacity_gb)
self.assertEqual(
'unknown',
fake_host.pools['_pool0'].free_capacity_gb)
def test_update_from_empty_volume_capability(self):
fake_host = host_manager.HostState('host1')

View File

@ -65,7 +65,7 @@ class TestCinderApiCmd(test.TestCase):
cinder_api.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
monkey_patch.assert_called_once_with()
@ -98,7 +98,7 @@ class TestCinderBackupCmd(test.TestCase):
cinder_backup.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
monkey_patch.assert_called_once_with()
@ -132,7 +132,7 @@ class TestCinderAllCmd(test.TestCase):
cinder_all.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder.all')
@ -169,7 +169,7 @@ class TestCinderAllCmd(test.TestCase):
cinder_all.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder.all')
@ -211,7 +211,7 @@ class TestCinderAllCmd(test.TestCase):
cinder_all.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder.all')
@ -247,7 +247,7 @@ class TestCinderSchedulerCmd(test.TestCase):
cinder_scheduler.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
monkey_patch.assert_called_once_with()
@ -278,7 +278,7 @@ class TestCinderVolumeCmd(test.TestCase):
cinder_volume.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
monkey_patch.assert_called_once_with()
@ -299,7 +299,7 @@ class TestCinderVolumeCmd(test.TestCase):
cinder_volume.main()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
monkey_patch.assert_called_once_with()
@ -1052,7 +1052,7 @@ class TestCinderRtstoolCmd(test.TestCase):
exit = self.assertRaises(SystemExit, cinder_rtstool.usage)
self.assertTrue(usage.called)
self.assertEqual(exit.code, 1)
self.assertEqual(1, exit.code)
def test_main_create_argv_lt_6(self):
sys.argv = ['cinder-rtstool', 'create']
@ -1083,7 +1083,7 @@ class TestCinderRtstoolCmd(test.TestCase):
exit = self.assertRaises(SystemExit, cinder_rtstool.main)
self.assertTrue(usage.called)
self.assertEqual(exit.code, 1)
self.assertEqual(1, exit.code)
@mock.patch('cinder.cmd.rtstool.save_to_file')
def test_main_save(self, mock_save):
@ -1225,7 +1225,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder')
self.assertEqual(exit.code, -1)
self.assertEqual(-1, exit.code)
rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with()
@ -1277,7 +1277,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume_usage_audit.main()
get_admin_context.assert_called_once_with()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder')
@ -1343,7 +1343,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume_usage_audit.main()
get_admin_context.assert_called_once_with()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder')
@ -1421,7 +1421,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume_usage_audit.main()
get_admin_context.assert_called_once_with()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder')
@ -1498,7 +1498,7 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
volume_usage_audit.main()
get_admin_context.assert_called_once_with()
self.assertEqual(CONF.project, 'cinder')
self.assertEqual('cinder', CONF.project)
self.assertEqual(CONF.version, version.version_string())
log_setup.assert_called_once_with(CONF, "cinder")
get_logger.assert_called_once_with('cinder')

View File

@ -37,19 +37,19 @@ class ConfigTestCase(test.TestCase):
self.assertNotIn('answer', CONF)
CONF.import_opt('answer', 'cinder.tests.unit.declare_conf')
self.assertIn('answer', CONF)
self.assertEqual(CONF.answer, 42)
self.assertEqual(42, CONF.answer)
# Make sure we don't overwrite anything
CONF.set_override('answer', 256)
self.assertEqual(CONF.answer, 256)
self.assertEqual(256, CONF.answer)
CONF.import_opt('answer', 'cinder.tests.unit.declare_conf')
self.assertEqual(CONF.answer, 256)
self.assertEqual(256, CONF.answer)
def test_runtime_and_unknown_conf(self):
self.assertNotIn('runtime_answer', CONF)
import cinder.tests.unit.runtime_conf # noqa
self.assertIn('runtime_answer', CONF)
self.assertEqual(CONF.runtime_answer, 54)
self.assertEqual(54, CONF.runtime_answer)
def test_long_vs_short_conf(self):
CONF.clear()
@ -62,22 +62,22 @@ class ConfigTestCase(test.TestCase):
argv = ['--duplicate_answer=60']
CONF(argv, default_config_files=[])
self.assertEqual(CONF.duplicate_answer, 60)
self.assertEqual(CONF.duplicate_answer_long, 'val')
self.assertEqual(60, CONF.duplicate_answer)
self.assertEqual('val', CONF.duplicate_answer_long)
def test_conf_leak_left(self):
self.assertEqual(CONF.conf_unittest, 'foo')
self.assertEqual('foo', CONF.conf_unittest)
self.flags(conf_unittest='bar')
self.assertEqual(CONF.conf_unittest, 'bar')
self.assertEqual('bar', CONF.conf_unittest)
def test_conf_leak_right(self):
self.assertEqual(CONF.conf_unittest, 'foo')
self.assertEqual('foo', CONF.conf_unittest)
self.flags(conf_unittest='bar')
self.assertEqual(CONF.conf_unittest, 'bar')
self.assertEqual('bar', CONF.conf_unittest)
def test_conf_overrides(self):
self.assertEqual(CONF.conf_unittest, 'foo')
self.assertEqual('foo', CONF.conf_unittest)
self.flags(conf_unittest='bar')
self.assertEqual(CONF.conf_unittest, 'bar')
self.assertEqual('bar', CONF.conf_unittest)
CONF.reset()
self.assertEqual(CONF.conf_unittest, 'foo')
self.assertEqual('foo', CONF.conf_unittest)

View File

@ -233,7 +233,7 @@ class DBAPIVolumeTestCase(BaseTest):
def test_volume_create(self):
volume = db.volume_create(self.ctxt, {'host': 'host1'})
self.assertTrue(uuidutils.is_uuid_like(volume['id']))
self.assertEqual(volume.host, 'host1')
self.assertEqual('host1', volume.host)
def test_volume_attached_invalid_uuid(self):
self.assertRaises(exception.InvalidUUID, db.volume_attached, self.ctxt,
@ -485,16 +485,16 @@ class DBAPIVolumeTestCase(BaseTest):
# no name filter
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'])
self.assertEqual(len(volumes), 3)
self.assertEqual(3, len(volumes))
# filter on name
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'display_name': 'vol2'})
self.assertEqual(len(volumes), 1)
self.assertEqual(1, len(volumes))
self.assertEqual(volumes[0]['display_name'], 'vol2')
# filter no match
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'display_name': 'vol4'})
self.assertEqual(len(volumes), 0)
self.assertEqual(0, len(volumes))
def test_volume_list_by_status(self):
db.volume_create(self.ctxt, {'display_name': 'vol1',
@ -507,30 +507,30 @@ class DBAPIVolumeTestCase(BaseTest):
# no status filter
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'])
self.assertEqual(len(volumes), 3)
self.assertEqual(3, len(volumes))
# single match
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'status': 'in-use'})
self.assertEqual(len(volumes), 1)
self.assertEqual(volumes[0]['status'], 'in-use')
self.assertEqual(1, len(volumes))
self.assertEqual('in-use', volumes[0]['status'])
# multiple match
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'status': 'available'})
self.assertEqual(len(volumes), 2)
self.assertEqual(2, len(volumes))
for volume in volumes:
self.assertEqual(volume['status'], 'available')
self.assertEqual('available', volume['status'])
# multiple filters
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'status': 'available',
'display_name': 'vol1'})
self.assertEqual(len(volumes), 1)
self.assertEqual(1, len(volumes))
self.assertEqual(volumes[0]['display_name'], 'vol1')
self.assertEqual(volumes[0]['status'], 'available')
self.assertEqual('available', volumes[0]['status'])
# no match
volumes = db.volume_get_all(self.ctxt, None, None, ['created_at'],
['asc'], {'status': 'in-use',
'display_name': 'vol1'})
self.assertEqual(len(volumes), 0)
self.assertEqual(0, len(volumes))
def _assertEqualsVolumeOrderResult(self, correct_order, limit=None,
sort_keys=None, sort_dirs=None,
@ -1045,7 +1045,7 @@ class DBAPISnapshotTestCase(BaseTest):
'project_id': 'project1',
'volume_size': 42})
actual = db.snapshot_data_get_for_project(self.ctxt, 'project1')
self.assertEqual(actual, (1, 42))
self.assertEqual((1, 42), actual)
def test_snapshot_get_all_by_filter(self):
db.volume_create(self.ctxt, {'id': 1})
@ -1479,8 +1479,8 @@ class DBAPIQuotaTestCase(BaseTest):
def test_quota_create(self):
quota = db.quota_create(self.ctxt, 'project1', 'resource', 99)
self.assertEqual(quota.resource, 'resource')
self.assertEqual(quota.hard_limit, 99)
self.assertEqual(quota.project_id, 'project1')
self.assertEqual(99, quota.hard_limit)
self.assertEqual('project1', quota.project_id)
def test_quota_get(self):
quota = db.quota_create(self.ctxt, 'project1', 'resource', 99)
@ -1502,9 +1502,9 @@ class DBAPIQuotaTestCase(BaseTest):
db.quota_create(self.ctxt, 'project1', 'resource1', 41)
db.quota_update(self.ctxt, 'project1', 'resource1', 42)
quota = db.quota_get(self.ctxt, 'project1', 'resource1')
self.assertEqual(quota.hard_limit, 42)
self.assertEqual(quota.resource, 'resource1')
self.assertEqual(quota.project_id, 'project1')
self.assertEqual(42, quota.hard_limit)
self.assertEqual('resource1', quota.resource)
self.assertEqual('project1', quota.project_id)
def test_quota_update_nonexistent(self):
self.assertRaises(exception.ProjectQuotaNotFound,

View File

@ -567,7 +567,7 @@ class NfsDriverTestCase(test.TestCase):
drv._load_shares_config(drv.configuration.nfs_shares_config)
self.assertIn(self.TEST_NFS_EXPORT1, drv.shares)
self.assertEqual(len(drv.shares), 1)
self.assertEqual(1, len(drv.shares))
mox.VerifyAll()
@ -1193,7 +1193,7 @@ class NfsDriverDoSetupTestCase(test.TestCase):
[mock.call(self.configuration.nfs_shares_config)])
self.assertEqual(1, mock_execute.call_count)
self.assertEqual(1, mock_set_security.call_count)
self.assertEqual(self.configuration.nfs_oversub_ratio, 1.0)
self.assertEqual(1.0, self.configuration.nfs_oversub_ratio)
def test_setup_should_throw_error_if_used_ratio_less_than_zero(self):
"""do_setup should throw error if nfs_used_ratio is less than 0."""
@ -1245,7 +1245,7 @@ class NfsDriverDoSetupTestCase(test.TestCase):
[mock.call(self.configuration.nfs_shares_config)])
self.assertEqual(1, mock_execute.call_count)
self.assertEqual(1, mock_set_security.call_count)
self.assertEqual(self.configuration.nfs_used_ratio, 0.95)
self.assertEqual(0.95, self.configuration.nfs_used_ratio)
def test_setup_should_throw_exception_if_nfs_client_is_not_installed(self):
"""do_setup should throw error if nfs client is not installed."""

View File

@ -198,7 +198,7 @@ class QuotaIntegrationTestCase(test.TestCase):
self.context, vol_ref, '', '')
usages = db.quota_usage_get_all_by_project(self.context,
self.project_id)
self.assertEqual(usages['gigabytes']['in_use'], 20)
self.assertEqual(20, usages['gigabytes']['in_use'])
db.snapshot_destroy(self.context, snap_ref['id'])
db.volume_destroy(self.context, vol_ref['id'])
@ -234,8 +234,8 @@ class QuotaIntegrationTestCase(test.TestCase):
vol_ref2 = volume.API().create(self.context, 10, '', '')
usages = db.quota_usage_get_all_by_project(self.context,
self.project_id)
self.assertEqual(usages['gigabytes']['in_use'], 20)
self.assertEqual(usages['gigabytes']['reserved'], 0)
self.assertEqual(20, usages['gigabytes']['in_use'])
self.assertEqual(0, usages['gigabytes']['reserved'])
db.snapshot_destroy(self.context, snap_ref['id'])
db.snapshot_destroy(self.context, snap_ref2['id'])
@ -265,8 +265,8 @@ class QuotaIntegrationTestCase(test.TestCase):
vol_ref2 = volume.API().create(self.context, 10, '', '')
usages = db.quota_usage_get_all_by_project(self.context,
self.project_id)
self.assertEqual(usages['gigabytes']['in_use'], 20)
self.assertEqual(usages['gigabytes']['reserved'], 0)
self.assertEqual(20, usages['gigabytes']['in_use'])
self.assertEqual(0, usages['gigabytes']['reserved'])
db.backup_destroy(self.context, backup_ref['id'])
db.backup_destroy(self.context, backup_ref2['id'])
@ -375,27 +375,25 @@ class FakeDriver(object):
class BaseResourceTestCase(test.TestCase):
def test_no_flag(self):
resource = quota.BaseResource('test_resource')
self.assertEqual(resource.name, 'test_resource')
self.assertEqual('test_resource', resource.name)
self.assertIsNone(resource.flag)
self.assertEqual(resource.default, -1)
self.assertEqual(-1, resource.default)
def test_with_flag(self):
# We know this flag exists, so use it...
self.flags(quota_volumes=10)
resource = quota.BaseResource('test_resource', 'quota_volumes')
self.assertEqual(resource.name, 'test_resource')
self.assertEqual(resource.flag, 'quota_volumes')
self.assertEqual(resource.default, 10)
self.assertEqual('test_resource', resource.name)
self.assertEqual('quota_volumes', resource.flag)
self.assertEqual(10, resource.default)
def test_with_flag_no_quota(self):
self.flags(quota_volumes=-1)
resource = quota.BaseResource('test_resource', 'quota_volumes')
self.assertEqual(resource.name, 'test_resource')
self.assertEqual(resource.flag, 'quota_volumes')
self.assertEqual(resource.default, -1)
self.assertEqual('test_resource', resource.name)
self.assertEqual('quota_volumes', resource.flag)
self.assertEqual(-1, resource.default)
def test_quota_no_project_no_class(self):
self.flags(quota_volumes=10)
@ -404,7 +402,7 @@ class BaseResourceTestCase(test.TestCase):
context = FakeContext(None, None)
quota_value = resource.quota(driver, context)
self.assertEqual(quota_value, 10)
self.assertEqual(10, quota_value)
def test_quota_with_project_no_class(self):
self.flags(quota_volumes=10)
@ -415,7 +413,7 @@ class BaseResourceTestCase(test.TestCase):
context = FakeContext('test_project', None)
quota_value = resource.quota(driver, context)
self.assertEqual(quota_value, 15)
self.assertEqual(15, quota_value)
def test_quota_no_project_with_class(self):
self.flags(quota_volumes=10)
@ -426,7 +424,7 @@ class BaseResourceTestCase(test.TestCase):
context = FakeContext(None, 'test_class')
quota_value = resource.quota(driver, context)
self.assertEqual(quota_value, 20)
self.assertEqual(20, quota_value)
def test_quota_with_project_with_class(self):
self.flags(quota_volumes=10)
@ -437,7 +435,7 @@ class BaseResourceTestCase(test.TestCase):
context = FakeContext('test_project', 'test_class')
quota_value = resource.quota(driver, context)
self.assertEqual(quota_value, 15)
self.assertEqual(15, quota_value)
def test_quota_override_project_with_class(self):
self.flags(quota_volumes=10)
@ -449,7 +447,7 @@ class BaseResourceTestCase(test.TestCase):
quota_value = resource.quota(driver, context,
project_id='override_project')
self.assertEqual(quota_value, 20)
self.assertEqual(20, quota_value)
def test_quota_override_subproject_no_class(self):
self.flags(quota_volumes=10)
@ -459,7 +457,7 @@ class BaseResourceTestCase(test.TestCase):
context = FakeContext('test_project', None)
quota_value = resource.quota(driver, context)
self.assertEqual(quota_value, 0)
self.assertEqual(0, quota_value)
def test_quota_with_project_override_class(self):
self.flags(quota_volumes=10)
@ -471,7 +469,7 @@ class BaseResourceTestCase(test.TestCase):
quota_value = resource.quota(driver, context,
quota_class='override_class')
self.assertEqual(quota_value, 20)
self.assertEqual(20, quota_value)
class VolumeTypeResourceTestCase(test.TestCase):
@ -482,35 +480,35 @@ class VolumeTypeResourceTestCase(test.TestCase):
self.assertEqual(resource.name, 'volumes_%s' % volume_type_name)
self.assertIsNone(resource.flag)
self.assertEqual(resource.default, -1)
self.assertEqual(-1, resource.default)
class QuotaEngineTestCase(test.TestCase):
def test_init(self):
quota_obj = quota.QuotaEngine()
self.assertEqual(quota_obj.resources, {})
self.assertEqual({}, quota_obj.resources)
self.assertIsInstance(quota_obj._driver, quota.DbQuotaDriver)
def test_init_override_string(self):
quota_obj = quota.QuotaEngine(
quota_driver_class='cinder.tests.unit.test_quota.FakeDriver')
self.assertEqual(quota_obj.resources, {})
self.assertEqual({}, quota_obj.resources)
self.assertIsInstance(quota_obj._driver, FakeDriver)
def test_init_override_obj(self):
quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver)
self.assertEqual(quota_obj.resources, {})
self.assertEqual(quota_obj._driver, FakeDriver)
self.assertEqual({}, quota_obj.resources)
self.assertEqual(FakeDriver, quota_obj._driver)
def test_register_resource(self):
quota_obj = quota.QuotaEngine()
resource = quota.AbsoluteResource('test_resource')
quota_obj.register_resource(resource)
self.assertEqual(quota_obj.resources, dict(test_resource=resource))
self.assertEqual(dict(test_resource=resource), quota_obj.resources)
def test_register_resources(self):
quota_obj = quota.QuotaEngine()
@ -520,10 +518,10 @@ class QuotaEngineTestCase(test.TestCase):
quota.AbsoluteResource('test_resource3'), ]
quota_obj.register_resources(resources)
self.assertEqual(quota_obj.resources,
dict(test_resource1=resources[0],
self.assertEqual(dict(test_resource1=resources[0],
test_resource2=resources[1],
test_resource3=resources[2], ))
test_resource3=resources[2], ),
quota_obj.resources)
def test_get_by_project(self):
context = FakeContext('test_project', 'test_class')
@ -534,12 +532,11 @@ class QuotaEngineTestCase(test.TestCase):
result = quota_obj.get_by_project(context, 'test_project',
'test_resource')
self.assertEqual(driver.called,
[('get_by_project',
self.assertEqual([('get_by_project',
context,
'test_project',
'test_resource'), ])
self.assertEqual(result, 42)
'test_resource'), ], driver.called)
self.assertEqual(42, result)
def test_get_by_class(self):
context = FakeContext('test_project', 'test_class')
@ -549,11 +546,11 @@ class QuotaEngineTestCase(test.TestCase):
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
result = quota_obj.get_by_class(context, 'test_class', 'test_resource')
self.assertEqual(driver.called, [('get_by_class',
context,
'test_class',
'test_resource'), ])
self.assertEqual(result, 42)
self.assertEqual([('get_by_class',
context,
'test_class',
'test_resource'), ], driver.called)
self.assertEqual(42, result)
def _make_quota_obj(self, driver):
quota_obj = quota.QuotaEngine(quota_driver_class=driver)
@ -573,10 +570,10 @@ class QuotaEngineTestCase(test.TestCase):
quota_obj = self._make_quota_obj(driver)
result = quota_obj.get_defaults(context)
self.assertEqual(driver.called, [('get_defaults',
context,
quota_obj.resources,
parent_project_id), ])
self.assertEqual([('get_defaults',
context,
quota_obj.resources,
parent_project_id), ], driver.called)
self.assertEqual(result, quota_obj.resources)
def test_get_class_quotas(self):
@ -586,14 +583,14 @@ class QuotaEngineTestCase(test.TestCase):
result1 = quota_obj.get_class_quotas(context, 'test_class')
result2 = quota_obj.get_class_quotas(context, 'test_class', False)
self.assertEqual(driver.called, [
self.assertEqual([
('get_class_quotas',
context,
quota_obj.resources,
'test_class', True),
('get_class_quotas',
context, quota_obj.resources,
'test_class', False), ])
'test_class', False), ], driver.called)
self.assertEqual(result1, quota_obj.resources)
self.assertEqual(result2, quota_obj.resources)
@ -608,7 +605,7 @@ class QuotaEngineTestCase(test.TestCase):
defaults=False,
usages=False)
self.assertEqual(driver.called, [
self.assertEqual([
('get_project_quotas',
context,
quota_obj.resources,
@ -624,7 +621,7 @@ class QuotaEngineTestCase(test.TestCase):
'test_class',
False,
False,
parent_project_id), ])
parent_project_id), ], driver.called)
self.assertEqual(result1, quota_obj.resources)
self.assertEqual(result2, quota_obj.resources)
@ -643,7 +640,7 @@ class QuotaEngineTestCase(test.TestCase):
parent_project_id=
parent_project_id)
self.assertEqual(driver.called, [
self.assertEqual([
('get_project_quotas',
context,
quota_obj.resources,
@ -659,7 +656,7 @@ class QuotaEngineTestCase(test.TestCase):
'test_class',
False,
False,
parent_project_id), ])
parent_project_id), ], driver.called)
self.assertEqual(result1, quota_obj.resources)
self.assertEqual(result2, quota_obj.resources)
@ -681,8 +678,8 @@ class QuotaEngineTestCase(test.TestCase):
def test_count(self):
def fake_count(context, *args, **kwargs):
self.assertEqual(args, (True,))
self.assertEqual(kwargs, dict(foo='bar'))
self.assertEqual((True,), args)
self.assertEqual(dict(foo='bar'), kwargs)
return 5
context = FakeContext(None, None)
@ -692,7 +689,7 @@ class QuotaEngineTestCase(test.TestCase):
fake_count))
result = quota_obj.count(context, 'test_resource5', True, foo='bar')
self.assertEqual(result, 5)
self.assertEqual(5, result)
def test_limit_check(self):
context = FakeContext(None, None)
@ -729,7 +726,7 @@ class QuotaEngineTestCase(test.TestCase):
test_resource1=1, test_resource2=2,
test_resource3=3, test_resource4=4)
self.assertEqual(driver.called, [
self.assertEqual([
('reserve',
context,
quota_obj.resources,
@ -759,19 +756,20 @@ class QuotaEngineTestCase(test.TestCase):
test_resource3=3,
test_resource4=4, ),
None,
'fake_project'), ])
self.assertEqual(result1, ['resv-01',
'resv-02',
'resv-03',
'resv-04', ])
self.assertEqual(result2, ['resv-01',
'resv-02',
'resv-03',
'resv-04', ])
self.assertEqual(result3, ['resv-01',
'resv-02',
'resv-03',
'resv-04', ])
'fake_project'), ],
driver.called)
self.assertEqual(['resv-01',
'resv-02',
'resv-03',
'resv-04', ], result1)
self.assertEqual(['resv-01',
'resv-02',
'resv-03',
'resv-04', ], result2)
self.assertEqual(['resv-01',
'resv-02',
'resv-03',
'resv-04', ], result3)
def test_commit(self):
context = FakeContext(None, None)
@ -861,13 +859,12 @@ class VolumeTypeQuotaEngineTestCase(test.TestCase):
self.stubs.Set(db, 'volume_type_get_all', fake_vtga)
engine = quota.VolumeTypeQuotaEngine()
self.assertEqual(engine.resource_names,
['backup_gigabytes', 'backups',
self.assertEqual(['backup_gigabytes', 'backups',
'gigabytes', 'gigabytes_type1', 'gigabytes_type_2',
'per_volume_gigabytes', 'snapshots',
'snapshots_type1', 'snapshots_type_2', 'volumes',
'volumes_type1', 'volumes_type_2',
])
], engine.resource_names)
db.volume_type_destroy(ctx, vtype['id'])
db.volume_type_destroy(ctx, vtype2['id'])
@ -902,14 +899,13 @@ class DbQuotaDriverTestCase(test.TestCase):
result = self.driver.get_defaults(None, quota.QUOTAS.resources)
self.assertEqual(
result,
dict(
volumes=10,
snapshots=10,
gigabytes=1000,
backups=10,
backup_gigabytes=1000,
per_volume_gigabytes=-1))
per_volume_gigabytes=-1), result)
def test_subproject_get_defaults(self):
# Test subproject default values.
@ -921,14 +917,13 @@ class DbQuotaDriverTestCase(test.TestCase):
parent_project_id)
self.assertEqual(
result,
dict(
volumes=0,
snapshots=0,
gigabytes=0,
backups=0,
backup_gigabytes=0,
per_volume_gigabytes=0))
per_volume_gigabytes=0), result)
def _stub_quota_class_get_default(self):
# Stub out quota_class_get_default
@ -958,7 +953,7 @@ class DbQuotaDriverTestCase(test.TestCase):
# Stub out quota_class_get_all_by_name
def fake_qcgabn(context, quota_class):
self.calls.append('quota_class_get_all_by_name')
self.assertEqual(quota_class, 'test_class')
self.assertEqual('test_class', quota_class)
return dict(gigabytes=500, volumes=10, snapshots=10, backups=10,
backup_gigabytes=500)
self.stubs.Set(db, 'quota_class_get_all_by_name', fake_qcgabn)
@ -969,13 +964,13 @@ class DbQuotaDriverTestCase(test.TestCase):
result = self.driver.get_class_quotas(None, quota.QUOTAS.resources,
'test_class')
self.assertEqual(self.calls, ['quota_class_get_all_by_name'])
self.assertEqual(result, dict(volumes=10,
gigabytes=500,
snapshots=10,
backups=10,
backup_gigabytes=500,
per_volume_gigabytes=-1))
self.assertEqual(['quota_class_get_all_by_name'], self.calls)
self.assertEqual(dict(volumes=10,
gigabytes=500,
snapshots=10,
backups=10,
backup_gigabytes=500,
per_volume_gigabytes=-1), result)
def test_get_class_quotas_no_defaults(self):
self._stub_quota_class_get_all_by_name()
@ -992,14 +987,14 @@ class DbQuotaDriverTestCase(test.TestCase):
def _stub_get_by_project(self):
def fake_qgabp(context, project_id):
self.calls.append('quota_get_all_by_project')
self.assertEqual(project_id, 'test_project')
self.assertEqual('test_project', project_id)
return dict(volumes=10, gigabytes=50, reserved=0,
snapshots=10, backups=10,
backup_gigabytes=50)
def fake_qugabp(context, project_id):
self.calls.append('quota_usage_get_all_by_project')
self.assertEqual(project_id, 'test_project')
self.assertEqual('test_project', project_id)
return dict(volumes=dict(in_use=2, reserved=0),
snapshots=dict(in_use=2, reserved=0),
gigabytes=dict(in_use=10, reserved=0),
@ -1016,12 +1011,12 @@ class DbQuotaDriverTestCase(test.TestCase):
def _stub_get_by_subproject(self):
def fake_qgabp(context, project_id):
self.calls.append('quota_get_all_by_project')
self.assertEqual(project_id, 'test_project')
self.assertEqual('test_project', project_id)
return dict(volumes=10, gigabytes=50, reserved=0)
def fake_qugabp(context, project_id):
self.calls.append('quota_usage_get_all_by_project')
self.assertEqual(project_id, 'test_project')
self.assertEqual('test_project', project_id)
return dict(volumes=dict(in_use=2, reserved=0),
gigabytes=dict(in_use=10, reserved=0))

View File

@ -266,13 +266,12 @@ class TestWSGIService(test.TestCase):
# Stopping the service, which in turn sets pool size to 0
test_service.stop()
self.assertEqual(test_service.server._pool.size, 0)
self.assertEqual(0, test_service.server._pool.size)
# Resetting pool size to default
test_service.reset()
test_service.start()
self.assertEqual(test_service.server._pool.size,
1000)
self.assertEqual(1000, test_service.server._pool.size)
self.assertTrue(mock_load_app.called)
@mock.patch('cinder.wsgi.Server')

View File

@ -51,9 +51,9 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
'value': 'value1'}
metadata = db.volume_glance_metadata_get(ctxt, 1)
self.assertEqual(len(metadata), 1)
self.assertEqual(1, len(metadata))
for key, value in expected_metadata_1.items():
self.assertEqual(metadata[0][key], value)
self.assertEqual(value, metadata[0][key])
expected_metadata_2 = ({'volume_id': '2',
'key': 'key1',
@ -66,19 +66,19 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
'value': '123'})
metadata = db.volume_glance_metadata_get(ctxt, 2)
self.assertEqual(len(metadata), 3)
self.assertEqual(3, len(metadata))
for expected, meta in zip(expected_metadata_2, metadata):
for key, value in expected.items():
self.assertEqual(meta[key], value)
self.assertEqual(value, meta[key])
self.assertRaises(exception.GlanceMetadataExists,
db.volume_glance_metadata_create,
ctxt, 1, 'key1', 'value1a')
metadata = db.volume_glance_metadata_get(ctxt, 1)
self.assertEqual(len(metadata), 1)
self.assertEqual(1, len(metadata))
for key, value in expected_metadata_1.items():
self.assertEqual(metadata[0][key], value)
self.assertEqual(value, metadata[0][key])
def test_vols_get_glance_metadata(self):
ctxt = context.get_admin_context()
@ -90,7 +90,7 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
db.volume_glance_metadata_create(ctxt, '2', 'key22', 'value22')
metadata = db.volume_glance_metadata_get_all(ctxt)
self.assertEqual(len(metadata), 3)
self.assertEqual(3, len(metadata))
self._assert_metadata_equals('1', 'key1', 'value1', metadata[0])
self._assert_metadata_equals('2', 'key2', 'value2', metadata[1])
self._assert_metadata_equals('2', 'key22', 'value22', metadata[2])
@ -122,7 +122,7 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
for meta in db.volume_snapshot_glance_metadata_get(ctxt, 100):
for (key, value) in expected_meta.items():
self.assertEqual(meta[key], value)
self.assertEqual(value, meta[key])
def test_vol_glance_metadata_copy_from_volume_to_volume(self):
ctxt = context.get_admin_context()
@ -136,7 +136,7 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
for meta in db.volume_glance_metadata_get(ctxt, 100):
for (key, value) in expected_meta.items():
self.assertEqual(meta[key], value)
self.assertEqual(value, meta[key])
def test_volume_glance_metadata_copy_to_volume(self):
vol1 = db.volume_create(self.ctxt, {})
@ -149,7 +149,7 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
snapshot['id'])
metadata = db.volume_glance_metadata_get(self.ctxt, vol2['id'])
metadata = {m['key']: m['value'] for m in metadata}
self.assertEqual(metadata, {'m1': 'v1'})
self.assertEqual({'m1': 'v1'}, metadata)
def test_volume_snapshot_glance_metadata_get_nonexistent(self):
vol = db.volume_create(self.ctxt, {})

View File

@ -132,11 +132,11 @@ class VolumeRpcAPITestCase(test.TestCase):
retval = getattr(rpcapi, method)(ctxt, **kwargs)
self.assertEqual(retval, expected_retval)
self.assertEqual(expected_retval, retval)
expected_args = [ctxt, method]
for arg, expected_arg in zip(self.fake_args, expected_args):
self.assertEqual(arg, expected_arg)
self.assertEqual(expected_arg, arg)
for kwarg, value in self.fake_kwargs.items():
if isinstance(value, objects.Snapshot):

View File

@ -132,7 +132,7 @@ class VolumeTransferTestCase(test.TestCase):
self.assertEqual(t['id'], transfer['id'], 'Unexpected transfer id')
ts = tx_api.get_all(self.ctxt)
self.assertEqual(len(ts), 1, 'Unexpected number of transfers.')
self.assertEqual(1, len(ts), 'Unexpected number of transfers.')
nctxt = context.RequestContext(user_id='new_user_id',
project_id='new_project_id')
@ -143,7 +143,7 @@ class VolumeTransferTestCase(test.TestCase):
transfer['id'])
ts = tx_api.get_all(nctxt)
self.assertEqual(len(ts), 0, 'Unexpected transfers listed.')
self.assertEqual(0, len(ts), 'Unexpected transfers listed.')
@mock.patch('cinder.volume.utils.notify_about_volume_usage')
def test_delete_transfer_with_deleted_volume(self, mock_notify):

View File

@ -179,7 +179,7 @@ class VolumeTypeTestCase(test.TestCase):
vol_types = volume_types.get_all_types(
self.ctxt,
search_opts={'extra_specs': {"key1": "val1"}})
self.assertEqual(len(vol_types), 1)
self.assertEqual(1, len(vol_types))
self.assertIn("type1", vol_types.keys())
self.assertEqual(vol_types['type1']['extra_specs'],
{"key1": "val1", "key2": "val2"})
@ -187,14 +187,14 @@ class VolumeTypeTestCase(test.TestCase):
vol_types = volume_types.get_all_types(
self.ctxt,
search_opts={'extra_specs': {"key2": "val2"}})
self.assertEqual(len(vol_types), 2)
self.assertEqual(2, len(vol_types))
self.assertIn("type1", vol_types.keys())
self.assertIn("type2", vol_types.keys())
vol_types = volume_types.get_all_types(
self.ctxt,
search_opts={'extra_specs': {"key3": "val3"}})
self.assertEqual(len(vol_types), 1)
self.assertEqual(1, len(vol_types))
self.assertIn("type2", vol_types.keys())
def test_volume_type_search_by_extra_spec_multiple(self):
@ -345,20 +345,19 @@ class VolumeTypeTestCase(test.TestCase):
diff, same = volume_types.volume_types_diff(self.ctxt, None,
type_ref1['id'])
self.assertFalse(same)
self.assertEqual(diff['extra_specs'],
{'key1': (None, 'val1'), 'key2': (None, 'val2')})
self.assertEqual(diff['qos_specs'],
{'consumer': (None, 'back-end'),
self.assertEqual({'key1': (None, 'val1'), 'key2': (None, 'val2')},
diff['extra_specs'])
self.assertEqual({'consumer': (None, 'back-end'),
'k1': (None, 'v1'),
'k2': (None, 'v2'),
'k3': (None, 'v3')})
self.assertEqual(diff['encryption'],
{'cipher': (None, 'c1'),
'k3': (None, 'v3')}, diff['qos_specs'])
self.assertEqual({'cipher': (None, 'c1'),
'control_location': (None, 'front-end'),
'deleted': (None, False),
'key_size': (None, 256),
'provider': (None, 'p1'),
'encryption_id': (None, 'uuid1')})
'encryption_id': (None, 'uuid1')},
diff['encryption'])
def test_encryption_create(self):
volume_type = volume_types.create(self.ctxt, "type1")

View File

@ -92,31 +92,31 @@ class VolumeTypeExtraSpecsTestCase(test.TestCase):
volume_type = db.volume_type_get(
context.get_admin_context(),
self.volume_type1_id)
self.assertEqual(volume_type['extra_specs'], self.vol_type1_specs)
self.assertEqual(self.vol_type1_specs, volume_type['extra_specs'])
volume_type = db.volume_type_get(
context.get_admin_context(),
self.vol_type2_id)
self.assertEqual(volume_type['extra_specs'], {})
self.assertEqual({}, volume_type['extra_specs'])
def test_volume_type_get_by_name_with_extra_specs(self):
volume_type = db.volume_type_get_by_name(
context.get_admin_context(),
self.vol_type1['name'])
self.assertEqual(volume_type['extra_specs'], self.vol_type1_specs)
self.assertEqual(self.vol_type1_specs, volume_type['extra_specs'])
volume_type = db.volume_type_get_by_name(
context.get_admin_context(),
self.vol_type2_noextra['name'])
self.assertEqual(volume_type['extra_specs'], {})
self.assertEqual({}, volume_type['extra_specs'])
def test_volume_type_get_all(self):
expected_specs = self.vol_type1_specs.copy()
types = db.volume_type_get_all(context.get_admin_context())
self.assertEqual(
types[self.vol_type1['name']]['extra_specs'], expected_specs)
self.assertEqual(expected_specs,
types[self.vol_type1['name']]['extra_specs'])
self.assertEqual(
types[self.vol_type2_noextra['name']]['extra_specs'], {})
self.assertEqual({},
types[self.vol_type2_noextra['name']]['extra_specs'])

View File

@ -353,32 +353,32 @@ class LVMVolumeDriverTestCase(test.TestCase):
def test_convert_blocksize_option(self):
# Test valid volume_dd_blocksize
bs, count = volume_utils._calculate_count(1024, '10M')
self.assertEqual(bs, '10M')
self.assertEqual(count, 103)
self.assertEqual('10M', bs)
self.assertEqual(103, count)
bs, count = volume_utils._calculate_count(1024, '1xBBB')
self.assertEqual(bs, '1M')
self.assertEqual(count, 1024)
self.assertEqual('1M', bs)
self.assertEqual(1024, count)
# Test 'volume_dd_blocksize' with fraction
bs, count = volume_utils._calculate_count(1024, '1.3M')
self.assertEqual(bs, '1M')
self.assertEqual(count, 1024)
self.assertEqual('1M', bs)
self.assertEqual(1024, count)
# Test zero-size 'volume_dd_blocksize'
bs, count = volume_utils._calculate_count(1024, '0M')
self.assertEqual(bs, '1M')
self.assertEqual(count, 1024)
self.assertEqual('1M', bs)
self.assertEqual(1024, count)
# Test negative 'volume_dd_blocksize'
bs, count = volume_utils._calculate_count(1024, '-1M')
self.assertEqual(bs, '1M')
self.assertEqual(count, 1024)
self.assertEqual('1M', bs)
self.assertEqual(1024, count)
# Test non-digital 'volume_dd_blocksize'
bs, count = volume_utils._calculate_count(1024, 'ABM')
self.assertEqual(bs, '1M')
self.assertEqual(count, 1024)
self.assertEqual('1M', bs)
self.assertEqual(1024, count)
class OdirectSupportTestCase(test.TestCase):
@ -648,61 +648,62 @@ class VolumeUtilsTestCase(test.TestCase):
def test_extract_host(self):
host = 'Host'
# default level is 'backend'
self.assertEqual(
volume_utils.extract_host(host), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'host'), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend'), 'Host')
self.assertEqual(host,
volume_utils.extract_host(host))
self.assertEqual(host,
volume_utils.extract_host(host, 'host'))
self.assertEqual(host,
volume_utils.extract_host(host, 'backend'))
# default_pool_name doesn't work for level other than 'pool'
self.assertEqual(
volume_utils.extract_host(host, 'host', True), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'host', False), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend', True), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend', False), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'pool'), None)
self.assertEqual(
volume_utils.extract_host(host, 'pool', True), '_pool0')
self.assertEqual(host,
volume_utils.extract_host(host, 'host', True))
self.assertEqual(host,
volume_utils.extract_host(host, 'host', False))
self.assertEqual(host,
volume_utils.extract_host(host, 'backend', True))
self.assertEqual(host,
volume_utils.extract_host(host, 'backend', False))
self.assertEqual(None,
volume_utils.extract_host(host, 'pool'))
self.assertEqual('_pool0',
volume_utils.extract_host(host, 'pool', True))
host = 'Host@Backend'
self.assertEqual(
volume_utils.extract_host(host), 'Host@Backend')
self.assertEqual(
volume_utils.extract_host(host, 'host'), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend'), 'Host@Backend')
self.assertEqual(
volume_utils.extract_host(host, 'pool'), None)
self.assertEqual(
volume_utils.extract_host(host, 'pool', True), '_pool0')
self.assertEqual('Host@Backend',
volume_utils.extract_host(host))
self.assertEqual('Host',
volume_utils.extract_host(host, 'host'))
self.assertEqual(host,
volume_utils.extract_host(host, 'backend'))
self.assertEqual(None,
volume_utils.extract_host(host, 'pool'))
self.assertEqual('_pool0',
volume_utils.extract_host(host, 'pool', True))
host = 'Host@Backend#Pool'
self.assertEqual(
volume_utils.extract_host(host), 'Host@Backend')
self.assertEqual(
volume_utils.extract_host(host, 'host'), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend'), 'Host@Backend')
self.assertEqual(
volume_utils.extract_host(host, 'pool'), 'Pool')
self.assertEqual(
volume_utils.extract_host(host, 'pool', True), 'Pool')
pool = 'Pool'
self.assertEqual('Host@Backend',
volume_utils.extract_host(host))
self.assertEqual('Host',
volume_utils.extract_host(host, 'host'))
self.assertEqual('Host@Backend',
volume_utils.extract_host(host, 'backend'))
self.assertEqual(pool,
volume_utils.extract_host(host, 'pool'))
self.assertEqual(pool,
volume_utils.extract_host(host, 'pool', True))
host = 'Host#Pool'
self.assertEqual(
volume_utils.extract_host(host), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'host'), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'backend'), 'Host')
self.assertEqual(
volume_utils.extract_host(host, 'pool'), 'Pool')
self.assertEqual(
volume_utils.extract_host(host, 'pool', True), 'Pool')
self.assertEqual('Host',
volume_utils.extract_host(host))
self.assertEqual('Host',
volume_utils.extract_host(host, 'host'))
self.assertEqual('Host',
volume_utils.extract_host(host, 'backend'))
self.assertEqual(pool,
volume_utils.extract_host(host, 'pool'))
self.assertEqual(pool,
volume_utils.extract_host(host, 'pool', True))
def test_append_host(self):
host = 'Host'

View File

@ -256,12 +256,12 @@ class TestWSGIServer(test.TestCase):
# Stopping the server, which in turn sets pool size to 0
server.stop()
self.assertEqual(server._pool.size, 0)
self.assertEqual(0, server._pool.size)
# Resetting pool size to default
server.reset()
server.start()
self.assertEqual(server._pool.size, 1000)
self.assertEqual(1000, server._pool.size)
class ExceptionTest(test.TestCase):
@ -294,7 +294,7 @@ class ExceptionTest(test.TestCase):
'The server has either erred or is incapable '
'of performing the requested operation.')
self.assertIn(expected, resp.body)
self.assertEqual(resp.status_int, 500, resp.body)
self.assertEqual(500, resp.status_int, resp.body)
def test_safe_exceptions_are_described_in_faults(self):
self._do_test_exception_safety_reflected_in_faults(True)
@ -310,7 +310,7 @@ class ExceptionTest(test.TestCase):
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertIn(msg, resp.body)
self.assertEqual(resp.status_int, exception_type.code, resp.body)
self.assertEqual(exception_type.code, resp.status_int, resp.body)
if hasattr(exception_type, 'headers'):
for (key, value) in exception_type.headers.items():