Browse Source

Wrong order of assertEquals args(Glance)

Args of assertEquals method in glance.tests are arranged
in wrong order. In result when test fails it shows incorrect
information about observed and actual data. It's found more
than 2000 times. Right order of arguments is "expected, actual".

Change-Id: Ifea4809f5a696b608a19e36a9ed9e5eec46c8a21
Co-Authored-By: Li Yingjun <liyingjun1988@gmail.com>
Closes-Bug: 1277104
changes/69/123769/22
Roman Vasilets 8 years ago
parent
commit
cb2456ea5e
  1. 234
      glance/tests/functional/db/base.py
  2. 10
      glance/tests/functional/db/base_metadef.py
  3. 10
      glance/tests/functional/test_api.py
  4. 8
      glance/tests/functional/test_bin_glance_cache_manage.py
  5. 26
      glance/tests/functional/test_cache_middleware.py
  6. 42
      glance/tests/functional/v1/test_api.py
  7. 14
      glance/tests/functional/v1/test_copy_to_file.py
  8. 8
      glance/tests/functional/v1/test_misc.py
  9. 66
      glance/tests/functional/v1/test_ssl.py
  10. 90
      glance/tests/functional/v2/test_images.py
  11. 10
      glance/tests/functional/v2/test_tasks.py
  12. 68
      glance/tests/integration/legacy_functional/test_v1_api.py
  13. 8
      glance/tests/integration/v2/test_tasks_api.py
  14. 76
      glance/tests/unit/api/test_cmd_cache_manage.py
  15. 2
      glance/tests/unit/api/test_common.py
  16. 4
      glance/tests/unit/common/test_client.py
  17. 2
      glance/tests/unit/common/test_property_utils.py
  18. 8
      glance/tests/unit/common/test_utils.py
  19. 6
      glance/tests/unit/common/test_wsgi.py
  20. 6
      glance/tests/unit/test_cache_middleware.py
  21. 2
      glance/tests/unit/test_context.py
  22. 38
      glance/tests/unit/test_db.py
  23. 60
      glance/tests/unit/test_db_metadef.py
  24. 12
      glance/tests/unit/test_domain_proxy.py
  25. 12
      glance/tests/unit/test_image_cache.py
  26. 8
      glance/tests/unit/test_store_image.py
  27. 4
      glance/tests/unit/test_store_location.py
  28. 60
      glance/tests/unit/v1/test_api.py
  29. 2
      glance/tests/unit/v1/test_registry_client.py
  30. 4
      glance/tests/unit/v1/test_upload_utils.py
  31. 162
      glance/tests/unit/v2/test_metadef_resources.py

234
glance/tests/functional/db/base.py

@ -154,8 +154,8 @@ class DriverTests(object):
self.assertFalse(image['deleted'])
self.assertIsNone(image['deleted_at'])
self.assertEqual([], image['properties'])
self.assertEqual(image['created_at'], create_time)
self.assertEqual(image['updated_at'], create_time)
self.assertEqual(create_time, image['created_at'])
self.assertEqual(create_time, image['updated_at'])
# Image IDs aren't predictable, but they should be populated
self.assertTrue(uuid.UUID(image['id']))
@ -263,13 +263,13 @@ class DriverTests(object):
# New properties are set
self.assertTrue('ping' in properties)
self.assertEqual(properties['ping']['value'], 'pong')
self.assertEqual('pong', properties['ping']['value'])
self.assertFalse(properties['ping']['deleted'])
# Original properties still show up, but with deleted=True
# TODO(markwash): db api should not return deleted properties
self.assertTrue('foo' in properties)
self.assertEqual(properties['foo']['value'], 'bar')
self.assertEqual('bar', properties['foo']['value'])
self.assertTrue(properties['foo']['deleted'])
def test_image_property_delete(self):
@ -282,7 +282,7 @@ class DriverTests(object):
def test_image_get(self):
image = self.db_api.image_get(self.context, UUID1)
self.assertEqual(image['id'], self.fixtures[0]['id'])
self.assertEqual(self.fixtures[0]['id'], image['id'])
def test_image_get_disallow_deleted(self):
self.db_api.image_destroy(self.adm_context, UUID1)
@ -292,14 +292,14 @@ class DriverTests(object):
def test_image_get_allow_deleted(self):
self.db_api.image_destroy(self.adm_context, UUID1)
image = self.db_api.image_get(self.adm_context, UUID1)
self.assertEqual(image['id'], self.fixtures[0]['id'])
self.assertEqual(self.fixtures[0]['id'], image['id'])
self.assertTrue(image['deleted'])
def test_image_get_force_allow_deleted(self):
self.db_api.image_destroy(self.adm_context, UUID1)
image = self.db_api.image_get(self.context, UUID1,
force_show_deleted=True)
self.assertEqual(image['id'], self.fixtures[0]['id'])
self.assertEqual(self.fixtures[0]['id'], image['id'])
def test_image_get_not_owned(self):
TENANT1 = str(uuid.uuid4())
@ -327,37 +327,37 @@ class DriverTests(object):
filters={
'id': self.fixtures[0]['id'],
})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['id'], self.fixtures[0]['id'])
self.assertEqual(1, len(images))
self.assertEqual(self.fixtures[0]['id'], images[0]['id'])
def test_image_get_all_with_filter_user_defined_property(self):
images = self.db_api.image_get_all(self.context,
filters={'foo': 'bar'})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['id'], self.fixtures[0]['id'])
self.assertEqual(1, len(images))
self.assertEqual(self.fixtures[0]['id'], images[0]['id'])
def test_image_get_all_with_filter_nonexistent_userdef_property(self):
images = self.db_api.image_get_all(self.context,
filters={'faz': 'boo'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_userdef_prop_nonexistent_value(self):
images = self.db_api.image_get_all(self.context,
filters={'foo': 'baz'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_multiple_user_defined_properties(self):
images = self.db_api.image_get_all(self.context,
filters={'foo': 'bar',
'far': 'boo'})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.assertEqual(images[0]['id'], self.fixtures[0]['id'])
def test_image_get_all_with_filter_nonexistent_user_defined_property(self):
images = self.db_api.image_get_all(self.context,
filters={'foo': 'bar',
'faz': 'boo'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_user_deleted_property(self):
fixture = {'name': 'poo', 'value': 'bear', 'image_id': UUID1}
@ -368,19 +368,19 @@ class DriverTests(object):
filters={
'properties': {'poo': 'bear'},
})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.db_api.image_property_delete(self.context,
prop['name'], images[0]['id'])
images = self.db_api.image_get_all(self.context,
filters={
'properties': {'poo': 'bear'},
})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_undefined_property(self):
images = self.db_api.image_get_all(self.context,
filters={'poo': 'bear'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_size_min_max(self):
images = self.db_api.image_get_all(self.context,
@ -388,27 +388,27 @@ class DriverTests(object):
'size_min': 10,
'size_max': 15,
})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['id'], self.fixtures[0]['id'])
self.assertEqual(1, len(images))
self.assertEqual(self.fixtures[0]['id'], images[0]['id'])
def test_image_get_all_size_min(self):
images = self.db_api.image_get_all(self.context,
filters={'size_min': 15})
self.assertEqual(len(images), 2)
self.assertEqual(images[0]['id'], self.fixtures[2]['id'])
self.assertEqual(images[1]['id'], self.fixtures[1]['id'])
self.assertEqual(2, len(images))
self.assertEqual(self.fixtures[2]['id'], images[0]['id'])
self.assertEqual(self.fixtures[1]['id'], images[1]['id'])
def test_image_get_all_size_range(self):
images = self.db_api.image_get_all(self.context,
filters={'size_max': 15,
'size_min': 20})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_size_max(self):
images = self.db_api.image_get_all(self.context,
filters={'size_max': 15})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['id'], self.fixtures[0]['id'])
self.assertEqual(1, len(images))
self.assertEqual(self.fixtures[0]['id'], images[0]['id'])
def test_image_get_all_with_filter_min_range_bad_value(self):
self.assertRaises(exception.InvalidFilterRangeValue,
@ -674,7 +674,7 @@ class DriverTests(object):
self.db_api.image_tag_create(self.context, UUID2, '64bit')
images = self.db_api.image_get_all(self.context,
filters={'tags': ['64bit']})
self.assertEqual(len(images), 2)
self.assertEqual(2, len(images))
image_ids = [image['id'] for image in images]
expected = [UUID1, UUID2]
self.assertEqual(sorted(expected), sorted(image_ids))
@ -687,7 +687,7 @@ class DriverTests(object):
images = self.db_api.image_get_all(self.context,
filters={'tags': ['64bit', 'power']
})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.assertEqual(UUID2, images[0]['id'])
def test_image_get_all_with_filter_tags_and_nonexistent(self):
@ -695,7 +695,7 @@ class DriverTests(object):
images = self.db_api.image_get_all(self.context,
filters={'tags': ['x86', 'fake']
})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_deleted_tags(self):
tag = self.db_api.image_tag_create(self.context, UUID1, 'AIX')
@ -703,18 +703,18 @@ class DriverTests(object):
filters={
'tags': [tag],
})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.db_api.image_tag_delete(self.context, UUID1, tag)
images = self.db_api.image_get_all(self.context,
filters={
'tags': [tag],
})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_get_all_with_filter_undefined_tags(self):
images = self.db_api.image_get_all(self.context,
filters={'tags': ['fake']})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_image_paginate(self):
"""Paginate through a list of images using limit and marker"""
@ -764,7 +764,7 @@ class DriverTests(object):
for image in images:
self.assertIn('tags', image)
self.assertEqual(image['tags'], expected_tags[image['id']])
self.assertEqual(expected_tags[image['id']], image['tags'])
self.db_api.image_tag_delete(self.context, UUID1,
expected_tags[UUID1][0])
@ -775,7 +775,7 @@ class DriverTests(object):
for image in images:
self.assertIn('tags', image)
self.assertEqual(image['tags'], expected_tags[image['id']])
self.assertEqual(expected_tags[image['id']], image['tags'])
def test_image_destroy(self):
location_data = [{'url': 'a', 'metadata': {'key': 'value'},
@ -861,7 +861,7 @@ class DriverTests(object):
self.assertFalse(active_image['deleted'])
self.assertFalse(active_image['deleted_at'])
self.assertEqual(len(active_image['locations']), 2)
self.assertEqual(2, len(active_image['locations']))
self.assertTrue('id' in active_image['locations'][0])
self.assertTrue('id' in active_image['locations'][1])
active_image['locations'][0].pop('id')
@ -1193,7 +1193,7 @@ class DriverTests(object):
actual = self.db_api.image_member_count(self.context, UUID1)
self.assertEqual(actual, 1)
self.assertEqual(1, actual)
def test_image_member_count_invalid_image_id(self):
TENANT1 = str(uuid.uuid4())
@ -1382,10 +1382,10 @@ class TaskTests(test_utils.BaseTestCase):
filters={'type': 'import'})
self.assertTrue(import_tasks)
self.assertEqual(len(import_tasks), 2)
self.assertEqual(2, len(import_tasks))
for task in import_tasks:
self.assertEqual(task['type'], 'import')
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual('import', task['type'])
self.assertEqual(self.context.owner, task['owner'])
def test_task_get_all_as_admin(self):
tasks = []
@ -1395,7 +1395,7 @@ class TaskTests(test_utils.BaseTestCase):
tasks.append(task)
import_tasks = self.db_api.task_get_all(self.adm_context)
self.assertTrue(import_tasks)
self.assertEqual(len(import_tasks), 3)
self.assertEqual(3, len(import_tasks))
def test_task_get_all_marker(self):
for fixture in self.fixtures:
@ -1405,7 +1405,7 @@ class TaskTests(test_utils.BaseTestCase):
task_ids = [t['id'] for t in tasks]
tasks = self.db_api.task_get_all(self.adm_context, sort_key='id',
marker=task_ids[0])
self.assertEqual(len(tasks), 2)
self.assertEqual(2, len(tasks))
def test_task_get_all_limit(self):
for fixture in self.fixtures:
@ -1470,14 +1470,14 @@ class TaskTests(test_utils.BaseTestCase):
task = self.db_api.task_get(self.adm_context, task_id)
self.assertIsNotNone(task)
self.assertEqual(task['id'], task_id)
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'import')
self.assertEqual(task['status'], 'pending')
self.assertEqual(task['input'], fixture['input'])
self.assertEqual(task['result'], fixture['result'])
self.assertEqual(task['message'], fixture['message'])
self.assertEqual(task['expires_at'], expires_at)
self.assertEqual(task_id, task['id'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual('import', task['type'])
self.assertEqual('pending', task['status'])
self.assertEqual(fixture['input'], task['input'])
self.assertEqual(fixture['result'], task['result'])
self.assertEqual(fixture['message'], task['message'])
self.assertEqual(expires_at, task['expires_at'])
def test_task_get_all(self):
now = timeutils.utcnow()
@ -1517,20 +1517,20 @@ class TaskTests(test_utils.BaseTestCase):
task_fixtures = {task1_id: fixture1, task2_id: fixture2}
tasks = self.db_api.task_get_all(self.adm_context)
self.assertEqual(len(tasks), 2)
self.assertEqual(2, len(tasks))
self.assertEqual(set((tasks[0]['id'], tasks[1]['id'])),
set((task1_id, task2_id)))
for task in tasks:
fixture = task_fixtures[task['id']]
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], fixture['type'])
self.assertEqual(task['status'], fixture['status'])
self.assertEqual(task['expires_at'], fixture['expires_at'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual(fixture['type'], task['type'])
self.assertEqual(fixture['status'], task['status'])
self.assertEqual(fixture['expires_at'], task['expires_at'])
self.assertFalse(task['deleted'])
self.assertIsNone(task['deleted_at'])
self.assertEqual(task['created_at'], fixture['created_at'])
self.assertEqual(task['updated_at'], fixture['updated_at'])
self.assertEqual(fixture['created_at'], task['created_at'])
self.assertEqual(fixture['updated_at'], task['updated_at'])
task_details_keys = ['input', 'message', 'result']
for key in task_details_keys:
self.assertFalse(key in task)
@ -1547,11 +1547,11 @@ class TaskTests(test_utils.BaseTestCase):
task_values = build_task_fixture(**values)
task = self.db_api.task_create(self.adm_context, task_values)
self.assertIsNotNone(task)
self.assertEqual(task['id'], task_id)
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'export')
self.assertEqual(task['status'], 'pending')
self.assertEqual(task['input'], {'ping': 'pong'})
self.assertEqual(task_id, task['id'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual('export', task['type'])
self.assertEqual('pending', task['status'])
self.assertEqual({'ping': 'pong'}, task['input'])
def test_task_create_with_all_task_info_null(self):
task_id = str(uuid.uuid4())
@ -1568,10 +1568,10 @@ class TaskTests(test_utils.BaseTestCase):
task_values = build_task_fixture(**values)
task = self.db_api.task_create(self.adm_context, task_values)
self.assertIsNotNone(task)
self.assertEqual(task['id'], task_id)
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'export')
self.assertEqual(task['status'], 'pending')
self.assertEqual(task_id, task['id'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual('export', task['type'])
self.assertEqual('pending', task['status'])
self.assertIsNone(task['input'])
self.assertIsNone(task['result'])
self.assertIsNone(task['message'])
@ -1590,17 +1590,17 @@ class TaskTests(test_utils.BaseTestCase):
}
task = self.db_api.task_update(self.adm_context, task_id, fixture)
self.assertEqual(task['id'], task_id)
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'import')
self.assertEqual(task['status'], 'processing')
self.assertEqual(task['input'], {'ping': 'pong'})
self.assertEqual(task['result'], result)
self.assertEqual(task['message'], 'This is a error string')
self.assertEqual(task_id, task['id'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual('import', task['type'])
self.assertEqual('processing', task['status'])
self.assertEqual({'ping': 'pong'}, task['input'])
self.assertEqual(result, task['result'])
self.assertEqual('This is a error string', task['message'])
self.assertFalse(task['deleted'])
self.assertIsNone(task['deleted_at'])
self.assertIsNone(task['expires_at'])
self.assertEqual(task['created_at'], task_values['created_at'])
self.assertEqual(task_values['created_at'], task['created_at'])
self.assertTrue(task['updated_at'] > task['created_at'])
def test_task_update_with_all_task_info_null(self):
@ -1615,17 +1615,17 @@ class TaskTests(test_utils.BaseTestCase):
fixture = {'status': 'processing'}
task = self.db_api.task_update(self.adm_context, task_id, fixture)
self.assertEqual(task['id'], task_id)
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'import')
self.assertEqual(task['status'], 'processing')
self.assertEqual(task_id, task['id'])
self.assertEqual(self.context.owner, task['owner'])
self.assertEqual('import', task['type'])
self.assertEqual('processing', task['status'])
self.assertIsNone(task['input'])
self.assertIsNone(task['result'])
self.assertIsNone(task['message'])
self.assertFalse(task['deleted'])
self.assertIsNone(task['deleted_at'])
self.assertIsNone(task['expires_at'])
self.assertEqual(task['created_at'], task_values['created_at'])
self.assertEqual(task_values['created_at'], task['created_at'])
self.assertTrue(task['updated_at'] > task['created_at'])
def test_task_delete(self):
@ -1712,119 +1712,119 @@ class VisibilityTests(object):
def test_unknown_admin_sees_all(self):
images = self.db_api.image_get_all(self.admin_none_context)
self.assertEqual(len(images), 8)
self.assertEqual(8, len(images))
def test_unknown_admin_is_public_true(self):
images = self.db_api.image_get_all(self.admin_none_context,
is_public=True)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_admin_is_public_false(self):
images = self.db_api.image_get_all(self.admin_none_context,
is_public=False)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertFalse(i['is_public'])
def test_unknown_admin_is_public_none(self):
images = self.db_api.image_get_all(self.admin_none_context)
self.assertEqual(len(images), 8)
self.assertEqual(8, len(images))
def test_unknown_admin_visibility_public(self):
images = self.db_api.image_get_all(self.admin_none_context,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_admin_visibility_private(self):
images = self.db_api.image_get_all(self.admin_none_context,
filters={'visibility': 'private'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertFalse(i['is_public'])
def test_known_admin_sees_all(self):
images = self.db_api.image_get_all(self.admin_context)
self.assertEqual(len(images), 8)
self.assertEqual(8, len(images))
def test_known_admin_is_public_true(self):
images = self.db_api.image_get_all(self.admin_context, is_public=True)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_known_admin_is_public_false(self):
images = self.db_api.image_get_all(self.admin_context,
is_public=False)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertFalse(i['is_public'])
def test_known_admin_is_public_none(self):
images = self.db_api.image_get_all(self.admin_context)
self.assertEqual(len(images), 8)
self.assertEqual(8, len(images))
def test_admin_as_user_true(self):
images = self.db_api.image_get_all(self.admin_context,
admin_as_user=True)
self.assertEqual(len(images), 5)
self.assertEqual(5, len(images))
for i in images:
self.assertTrue(i['is_public'] or i['owner'] == self.admin_tenant)
def test_known_admin_visibility_public(self):
images = self.db_api.image_get_all(self.admin_context,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_known_admin_visibility_private(self):
images = self.db_api.image_get_all(self.admin_context,
filters={'visibility': 'private'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertFalse(i['is_public'])
def test_what_unknown_user_sees(self):
images = self.db_api.image_get_all(self.none_context)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_user_is_public_true(self):
images = self.db_api.image_get_all(self.none_context, is_public=True)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_user_is_public_false(self):
images = self.db_api.image_get_all(self.none_context, is_public=False)
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_unknown_user_is_public_none(self):
images = self.db_api.image_get_all(self.none_context)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_user_visibility_public(self):
images = self.db_api.image_get_all(self.none_context,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_unknown_user_visibility_private(self):
images = self.db_api.image_get_all(self.none_context,
filters={'visibility': 'private'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_what_tenant1_sees(self):
images = self.db_api.image_get_all(self.tenant1_context)
self.assertEqual(len(images), 5)
self.assertEqual(5, len(images))
for i in images:
if not i['is_public']:
self.assertEqual(i['owner'], self.tenant1)
@ -1832,37 +1832,37 @@ class VisibilityTests(object):
def test_tenant1_is_public_true(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=True)
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_tenant1_is_public_false(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=False)
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.assertFalse(images[0]['is_public'])
self.assertEqual(images[0]['owner'], self.tenant1)
def test_tenant1_is_public_none(self):
images = self.db_api.image_get_all(self.tenant1_context)
self.assertEqual(len(images), 5)
self.assertEqual(5, len(images))
for i in images:
if not i['is_public']:
self.assertEqual(i['owner'], self.tenant1)
self.assertEqual(self.tenant1, i['owner'])
def test_tenant1_visibility_public(self):
images = self.db_api.image_get_all(self.tenant1_context,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
for i in images:
self.assertTrue(i['is_public'])
def test_tenant1_visibility_private(self):
images = self.db_api.image_get_all(self.tenant1_context,
filters={'visibility': 'private'})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
self.assertFalse(images[0]['is_public'])
self.assertEqual(images[0]['owner'], self.tenant1)
self.assertEqual(self.tenant1, images[0]['owner'])
def _setup_is_public_red_herring(self):
values = {
@ -1878,15 +1878,15 @@ class VisibilityTests(object):
self._setup_is_public_red_herring()
images = self.db_api.image_get_all(self.admin_context,
filters={'is_public': 'silly'})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['name'], 'Red Herring')
self.assertEqual(1, len(images))
self.assertEqual('Red Herring', images[0]['name'])
def test_is_public_is_a_normal_filter_for_user(self):
self._setup_is_public_red_herring()
images = self.db_api.image_get_all(self.tenant1_context,
filters={'is_public': 'silly'})
self.assertEqual(len(images), 1)
self.assertEqual(images[0]['name'], 'Red Herring')
self.assertEqual(1, len(images))
self.assertEqual('Red Herring', images[0]['name'])
# NOTE(markwash): the following tests are sanity checks to make sure
# visibility filtering and is_public=(True|False) do not interact in
@ -1896,46 +1896,46 @@ class VisibilityTests(object):
def test_admin_is_public_true_and_visibility_public(self):
images = self.db_api.image_get_all(self.admin_context, is_public=True,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
def test_admin_is_public_false_and_visibility_public(self):
images = self.db_api.image_get_all(self.admin_context, is_public=False,
filters={'visibility': 'public'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_admin_is_public_true_and_visibility_private(self):
images = self.db_api.image_get_all(self.admin_context, is_public=True,
filters={'visibility': 'private'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_admin_is_public_false_and_visibility_private(self):
images = self.db_api.image_get_all(self.admin_context, is_public=False,
filters={'visibility': 'private'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
def test_tenant1_is_public_true_and_visibility_public(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=True,
filters={'visibility': 'public'})
self.assertEqual(len(images), 4)
self.assertEqual(4, len(images))
def test_tenant1_is_public_false_and_visibility_public(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=False,
filters={'visibility': 'public'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_tenant1_is_public_true_and_visibility_private(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=True,
filters={'visibility': 'private'})
self.assertEqual(len(images), 0)
self.assertEqual(0, len(images))
def test_tenant1_is_public_false_and_visibility_private(self):
images = self.db_api.image_get_all(self.tenant1_context,
is_public=False,
filters={'visibility': 'private'})
self.assertEqual(len(images), 1)
self.assertEqual(1, len(images))
class TestMembershipVisibility(test_utils.BaseTestCase):

10
glance/tests/functional/db/base_metadef.py

@ -132,7 +132,7 @@ class MetadefNamespaceTests(object):
found = self.db_api.\
metadef_namespace_get_all(self.context, filters=rt_filters,
sort_key='created_at')
self.assertEqual(len(found), 1)
self.assertEqual(1, len(found))
for item in found:
self._assert_saved_fields(ns_fixture, item)
@ -142,7 +142,7 @@ class MetadefNamespaceTests(object):
created = self.db_api.metadef_namespace_create(self.context, fixture)
self.assertIsNotNone(created['namespace'])
self.assertEqual(created['namespace'], fixture['namespace'])
self.assertEqual(fixture['namespace'], created['namespace'])
delta_dict = copy.deepcopy(created)
delta_dict.update(delta.copy())
@ -241,7 +241,7 @@ class MetadefPropertyTests(object):
found = self.db_api.\
metadef_property_get_all(self.context, ns_created['namespace'])
self.assertEqual(len(found), 2)
self.assertEqual(2, len(found))
def test_property_update(self):
delta = {'name': u'New-name', 'json_schema': u'new-schema'}
@ -408,7 +408,7 @@ class MetadefResourceTypeTests(object):
self.context)
test_len = len(resource_types_orig) + 1
self.assertEqual(len(resource_types), test_len)
self.assertEqual(test_len, len(resource_types))
class MetadefResourceTypeAssociationTests(object):
@ -464,7 +464,7 @@ class MetadefResourceTypeAssociationTests(object):
found = self.db_api.\
metadef_resource_type_association_get_all_by_namespace(
self.context, ns_created['namespace'])
self.assertEqual(len(found), 1)
self.assertEqual(1, len(found))
for item in found:
self._assert_saved_fields(fixture, item)

10
glance/tests/functional/test_api.py

@ -192,8 +192,8 @@ class TestRootApi(functional.FunctionalTest):
path = 'http://%s:%d/v1/images' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(response.status, 200)
self.assertEqual(content, images_json)
self.assertEqual(200, response.status)
self.assertEqual(images_json, content)
# 3. GET / with Accept: unknown header
# Verify version choices returned. Verify message in API log about
@ -211,8 +211,8 @@ class TestRootApi(functional.FunctionalTest):
http = httplib2.Http()
headers = {'Accept': 'application/vnd.openstack.images-v1'}
response, content = http.request(path, 'GET', headers=headers)
self.assertEqual(response.status, 200)
self.assertEqual(content, images_json)
self.assertEqual(200, response.status)
self.assertEqual(images_json, content)
# 5. GET /images with a Accept: application/vnd.openstack.compute-v1
# header. Verify version choices returned. Verify message in API log
@ -268,7 +268,7 @@ class TestRootApi(functional.FunctionalTest):
path = 'http://%s:%d/v1/versions' % ('127.0.0.1', self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(response.status, 404)
self.assertEqual(404, response.status)
# Verify version choices returned
path = 'http://%s:%d/v10' % ('127.0.0.1', self.api_port)

8
glance/tests/functional/test_bin_glance_cache_manage.py

@ -62,10 +62,10 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], name)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual(name, data['image']['name'])
self.assertTrue(data['image']['is_public'])
return data['image']['id']

26
glance/tests/functional/test_cache_middleware.py

@ -62,10 +62,10 @@ class BaseCacheMiddlewareTest(object):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
image_id = data['image']['id']
@ -234,10 +234,10 @@ class BaseCacheMiddlewareTest(object):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
image_id = data['image']['id']
@ -359,10 +359,10 @@ class BaseCacheManageMiddlewareTest(object):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], name)
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual(name, data['image']['name'])
self.assertTrue(data['image']['is_public'])
return data['image']['id']
@ -541,7 +541,7 @@ class BaseCacheManageMiddlewareTest(object):
ids[x])
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(response.status, 200,
self.assertEqual(200, response.status,
"Failed to find image %s" % ids[x])
# Verify images now in cache

42
glance/tests/functional/v1/test_api.py

@ -139,10 +139,10 @@ class TestApi(functional.FunctionalTest):
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
# 3. HEAD image
@ -176,14 +176,14 @@ class TestApi(functional.FunctionalTest):
'content-type': 'application/octet-stream'}
for expected_key, expected_value in expected_image_headers.items():
self.assertEqual(response[expected_key], expected_value,
self.assertEqual(expected_value, response[expected_key],
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
response[expected_key]))
for expected_key, expected_value in expected_std_headers.items():
self.assertEqual(response[expected_key], expected_value,
self.assertEqual(expected_value, response[expected_key],
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
@ -402,14 +402,14 @@ class TestApi(functional.FunctionalTest):
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
image2_id = data['image']['id']
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image2")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image2", data['image']['name'])
self.assertTrue(data['image']['is_public'])
self.assertEqual(data['image']['properties']['distro'], 'Ubuntu')
self.assertEqual(data['image']['properties']['arch'], 'i386')
self.assertEqual(data['image']['properties']['foo'], 'bar')
self.assertEqual('Ubuntu', data['image']['properties']['distro'])
self.assertEqual('i386', data['image']['properties']['arch'])
self.assertEqual('bar', data['image']['properties']['foo'])
# 19. HEAD image2
# Verify image2 found now
@ -587,10 +587,10 @@ class TestApi(functional.FunctionalTest):
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
# 1. HEAD image
@ -666,10 +666,10 @@ class TestApi(functional.FunctionalTest):
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
image_id = data['image']['id']
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
# 1. HEAD image

14
glance/tests/functional/v1/test_copy_to_file.py

@ -65,7 +65,7 @@ class TestCopyToFile(functional.FunctionalTest):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers,
body=image_data)
self.assertEqual(response.status, 201, content)
self.assertEqual(201, response.status, content)
data = jsonutils.loads(content)
original_image_id = data['image']['id']
@ -81,7 +81,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201, content)
self.assertEqual(201, response.status, content)
data = jsonutils.loads(content)
copy_image_id = data['image']['id']
@ -177,11 +177,11 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201, content)
self.assertEqual(201, response.status, content)
data = jsonutils.loads(content)
copy_image_id = data['image']['id']
self.assertEqual(data['image']['status'], 'queued', content)
self.assertEqual('queued', data['image']['status'], content)
path = "http://%s:%d/v1/images/%s" % ("127.0.0.1", self.api_port,
copy_image_id)
@ -202,7 +202,7 @@ class TestCopyToFile(functional.FunctionalTest):
# GET image and make sure image content is as expected
http = httplib2.Http()
response, content = http.request(path, 'GET')
self.assertEqual(response.status, 200 if exists else 404)
self.assertEqual(200 if exists else 404, response.status)
if exists:
self.assertEqual(str(FIVE_KB), response['content-length'])
@ -248,7 +248,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 400, content)
self.assertEqual(400, response.status, content)
expected = 'External sourcing not supported for store \'file\''
msg = 'expected "%s" in "%s"' % (expected, content)
@ -274,7 +274,7 @@ class TestCopyToFile(functional.FunctionalTest):
path = "http://%s:%d/v1/images" % ("127.0.0.1", self.api_port)
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 400, content)
self.assertEqual(400, response.status, content)
expected = 'External sourcing not supported for store \'swift+config\''
msg = 'expected "%s" in "%s"' % (expected, content)

8
glance/tests/functional/v1/test_misc.py

@ -60,10 +60,10 @@ class TestMiscellaneous(functional.FunctionalTest):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
# 2. REMOVE the image from the filesystem

66
glance/tests/functional/v1/test_ssl.py

@ -156,10 +156,10 @@ class TestSSL(functional.FunctionalTest):
body=image_data)
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'],
hashlib.md5(image_data).hexdigest())
self.assertEqual(data['image']['size'], FIVE_KB)
self.assertEqual(data['image']['name'], "Image1")
self.assertEqual(hashlib.md5(image_data).hexdigest(),
data['image']['checksum'])
self.assertEqual(FIVE_KB, data['image']['size'])
self.assertEqual("Image1", data['image']['name'])
self.assertTrue(data['image']['is_public'])
image_id = data['image']['id']
@ -195,22 +195,22 @@ class TestSSL(functional.FunctionalTest):
'content-type': 'application/octet-stream'}
for expected_key, expected_value in expected_image_headers.items():
self.assertEqual(response[expected_key], expected_value,
self.assertEqual(expected_value, response[expected_key],
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
response[expected_key]))
for expected_key, expected_value in expected_std_headers.items():
self.assertEqual(response[expected_key], expected_value,
self.assertEqual(expected_value, response[expected_key],
"For key '%s' expected header value '%s'. "
"Got '%s'" % (expected_key,
expected_value,
response[expected_key]))
self.assertEqual("*" * FIVE_KB, content)
self.assertEqual(hashlib.md5(content).hexdigest(),
hashlib.md5("*" * FIVE_KB).hexdigest())
self.assertEqual(hashlib.md5("*" * FIVE_KB).hexdigest(),
hashlib.md5(content).hexdigest())
# 5. GET /images
# Verify no public images
@ -379,10 +379,10 @@ class TestSSL(functional.FunctionalTest):
self.assertEqual(201, response.status)
data = jsonutils.loads(content)
self.assertIsNone(data['image']['checksum'])
self.assertEqual(data['image']['size'], 0