Ensure parameter order of assertEqual correct

As part of patch a2c3e9d7d8 it
was identified that the parameter order to assertEqual in
test_{port,chassis,node}.py was often not following what is
considered standard practice and inconsistently applied.
This patch updates all instances to follow the same approach.

Change-Id: Ied28371d5152bbd3ebd2bb8353f72ed82ddd6861
This commit is contained in:
Michael Davies 2014-02-06 18:44:30 +10:30 committed by Gerrit Code Review
parent 1b15e6aafc
commit 7f072ff8ce
3 changed files with 184 additions and 185 deletions

View File

@ -53,7 +53,7 @@ class TestListChassis(base.FunctionalTest):
chassis = self.dbapi.create_chassis(cdict)
response = self.get_json('/chassis/%s/detail' % chassis['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(404, response.status_int)
def test_many(self):
ch_list = []
@ -63,10 +63,9 @@ class TestListChassis(base.FunctionalTest):
chassis = self.dbapi.create_chassis(ndict)
ch_list.append(chassis['uuid'])
data = self.get_json('/chassis')
self.assertEqual(len(ch_list), len(data['chassis']))
self.assertEqual(len(data['chassis']), len(ch_list))
uuids = [n['uuid'] for n in data['chassis']]
self.assertEqual(ch_list.sort(), uuids.sort())
self.assertEqual(uuids.sort(), ch_list.sort())
def test_links(self):
uuid = utils.generate_uuid()
@ -74,7 +73,7 @@ class TestListChassis(base.FunctionalTest):
self.dbapi.create_chassis(ndict)
data = self.get_json('/chassis/%s' % uuid)
self.assertIn('links', data.keys())
self.assertEqual(len(data['links']), 2)
self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href'])
self.assertTrue(self.validate_link(data['links'][0]['href']))
self.assertTrue(self.validate_link(data['links'][1]['href']))
@ -87,7 +86,7 @@ class TestListChassis(base.FunctionalTest):
ch = self.dbapi.create_chassis(ndict)
chassis.append(ch['uuid'])
data = self.get_json('/chassis/?limit=3')
self.assertEqual(len(data['chassis']), 3)
self.assertEqual(3, len(data['chassis']))
next_marker = data['chassis'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -101,7 +100,7 @@ class TestListChassis(base.FunctionalTest):
ch = self.dbapi.create_chassis(ndict)
chassis.append(ch['uuid'])
data = self.get_json('/chassis')
self.assertEqual(len(data['chassis']), 3)
self.assertEqual(3, len(data['chassis']))
next_marker = data['chassis'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -123,23 +122,23 @@ class TestListChassis(base.FunctionalTest):
self.dbapi.create_node(ndict)
data = self.get_json('/chassis/%s/nodes' % cdict['uuid'])
self.assertEqual(len(data['nodes']), 2)
self.assertEqual(2, len(data['nodes']))
self.assertNotIn('next', data.keys())
# Test collection pagination
data = self.get_json('/chassis/%s/nodes?limit=1' % cdict['uuid'])
self.assertEqual(len(data['nodes']), 1)
self.assertEqual(1, len(data['nodes']))
self.assertIn('next', data.keys())
def test_nodes_subresource_no_uuid(self):
response = self.get_json('/chassis/nodes', expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(400, response.status_int)
def test_nodes_subresource_chassis_not_found(self):
non_existent_uuid = 'eeeeeeee-cccc-aaaa-bbbb-cccccccccccc'
response = self.get_json('/chassis/%s/nodes' % non_existent_uuid,
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(404, response.status_int)
class TestPatch(base.FunctionalTest):
@ -156,8 +155,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/extra/a', 'value': 'b',
'op': 'add'}],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_replace_singular(self):
@ -168,10 +167,10 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/description',
'value': description, 'op': 'replace'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
self.assertEqual(result['description'], description)
self.assertEqual(description, result['description'])
return_updated_at = timeutils.parse_isotime(
result['updated_at']).replace(tzinfo=None)
self.assertEqual(t1, return_updated_at)
@ -185,12 +184,12 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/extra/foo2',
'value': new_value, 'op': 'replace'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
extra["foo2"] = new_value
self.assertEqual(result['extra'], extra)
self.assertEqual(extra, result['extra'])
def test_remove_singular(self):
cdict = dbutils.get_test_chassis(extra={'a': 'b'},
@ -198,14 +197,14 @@ class TestPatch(base.FunctionalTest):
self.post_json('/chassis', cdict)
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/description', 'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
self.assertEqual(result['description'], None)
self.assertEqual(None, result['description'])
# Assert nothing else was changed
self.assertEqual(result['uuid'], cdict['uuid'])
self.assertEqual(result['extra'], cdict['extra'])
self.assertEqual(cdict['uuid'], result['uuid'])
self.assertEqual(cdict['extra'], result['extra'])
def test_remove_multi(self):
extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
@ -216,31 +215,31 @@ class TestPatch(base.FunctionalTest):
# Removing one item from the collection
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/extra/foo2', 'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
extra.pop("foo2")
self.assertEqual(result['extra'], extra)
self.assertEqual(extra, result['extra'])
# Removing the collection
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/extra', 'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
self.assertEqual(result['extra'], {})
self.assertEqual({}, result['extra'])
# Assert nothing else was changed
self.assertEqual(result['uuid'], cdict['uuid'])
self.assertEqual(result['description'], cdict['description'])
self.assertEqual(cdict['uuid'], result['uuid'])
self.assertEqual(cdict['description'], result['description'])
def test_remove_non_existent_property_fail(self):
cdict = dbutils.get_test_chassis()
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/extra/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_add_singular(self):
@ -249,8 +248,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/foo', 'value': 'bar',
'op': 'add'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_add_multi(self):
@ -260,26 +259,26 @@ class TestPatch(base.FunctionalTest):
'op': 'add'},
{'path': '/extra/foo2', 'value': 'bar2',
'op': 'add'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/chassis/%s' % cdict['uuid'])
expected = {"foo1": "bar1", "foo2": "bar2"}
self.assertEqual(result['extra'], expected)
self.assertEqual(expected, result['extra'])
def test_patch_nodes_subresource(self):
cdict = dbutils.get_test_chassis()
response = self.patch_json('/chassis/%s/nodes' % cdict['uuid'],
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_remove_uuid(self):
cdict = dbutils.get_test_chassis()
response = self.patch_json('/chassis/%s' % cdict['uuid'],
[{'path': '/uuid', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
@ -318,7 +317,7 @@ class TestPost(base.FunctionalTest):
ndict['chassis_uuid'] = cdict['uuid']
response = self.post_json('/chassis/nodes', ndict,
expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_create_chassis_valid_extra(self):
cdict = dbutils.get_test_chassis(extra={'foo': 123})
@ -329,8 +328,8 @@ class TestPost(base.FunctionalTest):
def test_create_chassis_invalid_extra(self):
cdict = dbutils.get_test_chassis(extra={'foo': 0.123})
response = self.post_json('/chassis', cdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_chassis_unicode_description(self):
@ -349,8 +348,8 @@ class TestDelete(base.FunctionalTest):
self.delete('/chassis/%s' % cdict['uuid'])
response = self.get_json('/chassis/%s' % cdict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_delete_chassis_with_node(self):
@ -360,15 +359,15 @@ class TestDelete(base.FunctionalTest):
self.dbapi.create_node(ndict)
response = self.delete('/chassis/%s' % cdict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_delete_chassis_not_found(self):
uuid = utils.generate_uuid()
response = self.delete('/chassis/%s' % uuid, expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_delete_nodes_subresource(self):
@ -376,4 +375,4 @@ class TestDelete(base.FunctionalTest):
self.post_json('/chassis', cdict)
response = self.delete('/chassis/%s/nodes' % cdict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)

View File

@ -105,7 +105,7 @@ class TestListNodes(base.FunctionalTest):
node = self.dbapi.create_node(ndict)
response = self.get_json('/nodes/%s/detail' % node['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(404, response.status_int)
def test_many(self):
nodes = []
@ -126,7 +126,7 @@ class TestListNodes(base.FunctionalTest):
self.dbapi.create_node(ndict)
data = self.get_json('/nodes/%s' % uuid)
self.assertIn('links', data.keys())
self.assertEqual(len(data['links']), 2)
self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href'])
self.assertTrue(self.validate_link(data['links'][0]['href']))
self.assertTrue(self.validate_link(data['links'][1]['href']))
@ -139,7 +139,7 @@ class TestListNodes(base.FunctionalTest):
node = self.dbapi.create_node(ndict)
nodes.append(node['uuid'])
data = self.get_json('/nodes/?limit=3')
self.assertEqual(len(data['nodes']), 3)
self.assertEqual(3, len(data['nodes']))
next_marker = data['nodes'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -153,7 +153,7 @@ class TestListNodes(base.FunctionalTest):
node = self.dbapi.create_node(ndict)
nodes.append(node['uuid'])
data = self.get_json('/nodes')
self.assertEqual(len(data['nodes']), 3)
self.assertEqual(3, len(data['nodes']))
next_marker = data['nodes'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -176,12 +176,12 @@ class TestListNodes(base.FunctionalTest):
self.dbapi.create_port(pdict)
data = self.get_json('/nodes/%s/ports' % ndict['uuid'])
self.assertEqual(len(data['ports']), 2)
self.assertEqual(2, len(data['ports']))
self.assertNotIn('next', data.keys())
# Test collection pagination
data = self.get_json('/nodes/%s/ports?limit=1' % ndict['uuid'])
self.assertEqual(len(data['ports']), 1)
self.assertEqual(1, len(data['ports']))
self.assertIn('next', data.keys())
def test_ports_subresource_noid(self):
@ -191,13 +191,13 @@ class TestListNodes(base.FunctionalTest):
self.dbapi.create_port(pdict)
# No node id specified
response = self.get_json('/nodes/ports', expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(400, response.status_int)
def test_ports_subresource_node_not_found(self):
non_existent_uuid = 'eeeeeeee-cccc-aaaa-bbbb-cccccccccccc'
response = self.get_json('/nodes/%s/ports' % non_existent_uuid,
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(404, response.status_int)
def test_node_states(self):
fake_state = 'fake-state'
@ -259,8 +259,8 @@ class TestListNodes(base.FunctionalTest):
def test_associated_nodes_error(self):
self._create_association_test_nodes()
response = self.get_json('/nodes?associated=blah', expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_unassociated_nodes_insensitive(self):
@ -350,8 +350,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/instance_uuid',
'value': 'aaaaaaaa-1111-bbbb-2222-cccccccccccc',
'op': 'replace'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_update_node.return_value.updated_at,
timeutils.parse_isotime(response.json['updated_at']))
self.mock_update_node.assert_called_once_with(
@ -361,8 +361,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'power_state': 'new state'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_update_fails_bad_driver_info(self):
@ -378,8 +378,8 @@ class TestPatch(base.FunctionalTest):
'value': 'bar',
'op': 'add'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -394,8 +394,8 @@ class TestPatch(base.FunctionalTest):
'value': 'aaaaaaaa-1111-bbbb-2222-cccccccccccc',
'op': 'replace'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 409)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -407,8 +407,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/extra/foo',
'value': 'bar',
'op': 'add'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -417,8 +417,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'path': '/foo', 'value': 'bar', 'op': 'add'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_ok(self):
@ -427,8 +427,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'path': '/extra',
'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
self.mock_update_node.assert_called_once_with(
mock.ANY, mock.ANY, 'test-topic')
@ -437,8 +437,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'path': '/extra/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_update_state_in_progress(self):
@ -448,31 +448,31 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/nodes/%s' % node['uuid'],
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 409)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertTrue(response.json['error_message'])
def test_patch_ports_subresource(self):
response = self.patch_json('/nodes/%s/ports' % self.node['uuid'],
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_remove_uuid(self):
ndict = dbutils.get_test_node()
response = self.patch_json('/nodes/%s' % ndict['uuid'],
[{'path': '/uuid', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_mandatory_field(self):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'path': '/driver', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_non_existent_chassis_uuid(self):
@ -480,16 +480,16 @@ class TestPatch(base.FunctionalTest):
[{'path': '/chassis_uuid',
'value': 'eeeeeeee-dddd-cccc-bbbb-aaaaaaaaaaaa',
'op': 'replace'}], expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_internal_field(self):
response = self.patch_json('/nodes/%s' % self.node['uuid'],
[{'path': '/last_error', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_internal_field(self):
@ -497,8 +497,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/power_state', 'op': 'replace',
'value': 'fake-state'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_maintenance(self):
@ -506,8 +506,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/maintenance', 'op': 'replace',
'value': 'fake'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
@ -545,8 +545,8 @@ class TestPost(base.FunctionalTest):
def test_create_node_invalid_extra(self):
ndict = post_get_test_node(extra={'foo': 0.123})
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_vendor_passthru_ok(self):
@ -562,8 +562,8 @@ class TestPost(base.FunctionalTest):
info, expect_errors=False)
mock_vendor.assert_called_once_with(
mock.ANY, uuid, 'test', info, 'test-topic')
self.assertEqual(response.body, '"OK"')
self.assertEqual(response.status_code, 202)
self.assertEqual('"OK"', response.body)
self.assertEqual(202, response.status_code)
def test_vendor_passthru_no_such_method(self):
ndict = post_get_test_node()
@ -581,15 +581,15 @@ class TestPost(base.FunctionalTest):
info, expect_errors=True)
mock_vendor.assert_called_once_with(
mock.ANY, uuid, 'test', info, 'test-topic')
self.assertEqual(response.status_code, 400)
self.assertEqual(400, response.status_code)
def test_vendor_passthru_without_method(self):
ndict = post_get_test_node()
self.post_json('/nodes', ndict)
response = self.post_json('/nodes/%s/vendor_passthru' % ndict['uuid'],
{'foo': 'bar'}, expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type, )
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_post_ports_subresource(self):
@ -599,29 +599,29 @@ class TestPost(base.FunctionalTest):
pdict['node_uuid'] = ndict['uuid']
response = self.post_json('/nodes/ports', pdict,
expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_create_node_no_mandatory_field_driver(self):
ndict = post_get_test_node()
del ndict['driver']
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_node_no_chassis_uuid(self):
ndict = post_get_test_node()
del ndict['chassis_uuid']
response = self.post_json('/nodes', ndict)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 201)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
def test_create_node_chassis_uuid_not_found(self):
ndict = post_get_test_node(
chassis_uuid='1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e')
response = self.post_json('/nodes', ndict, expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
@ -638,8 +638,8 @@ class TestDelete(base.FunctionalTest):
self.delete('/nodes/%s' % ndict['uuid'])
response = self.get_json('/nodes/%s' % ndict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_delete_ports_subresource(self):
@ -647,14 +647,14 @@ class TestDelete(base.FunctionalTest):
self.post_json('/nodes', ndict)
response = self.delete('/nodes/%s/ports' % ndict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_delete_associated(self):
ndict = post_get_test_node(
instance_uuid='aaaaaaaa-1111-bbbb-2222-cccccccccccc')
self.post_json('/nodes', ndict)
response = self.delete('/nodes/%s' % ndict['uuid'], expect_errors=True)
self.assertEqual(response.status_int, 409)
self.assertEqual(409, response.status_int)
class TestPut(base.FunctionalTest):
@ -682,8 +682,8 @@ class TestPut(base.FunctionalTest):
def test_power_state(self):
response = self.put_json('/nodes/%s/states/power' % self.node['uuid'],
{'target': states.POWER_ON})
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 202)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_code)
self.mock_cnps.assert_called_once_with(mock.ANY,
self.node['uuid'],
@ -704,40 +704,40 @@ class TestPut(base.FunctionalTest):
self.put_json('/nodes/%s/states/power' % self.node['uuid'],
{'target': states.POWER_ON})
self.assertEqual(manager.mock_calls, expected)
self.assertEqual(expected, manager.mock_calls)
self.dbapi.update_node(self.node['uuid'],
{'target_power_state': 'fake'})
response = self.put_json('/nodes/%s/states/power' % self.node['uuid'],
{'target': states.POWER_ON},
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 409)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertTrue(response.json['error_message'])
def test_power_invalid_state_request(self):
ret = self.put_json('/nodes/%s/states/power' % self.node.uuid,
{'target': 'not-supported'}, expect_errors=True)
self.assertEqual(ret.status_code, 400)
self.assertEqual(400, ret.status_code)
def test_provision_with_deploy(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.ACTIVE})
self.assertEqual(ret.status_code, 202)
self.assertEqual(202, ret.status_code)
self.mock_dnd.assert_called_once_with(
mock.ANY, self.node.uuid, 'test-topic')
def test_provision_with_tear_down(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': states.DELETED})
self.assertEqual(ret.status_code, 202)
self.assertEqual(202, ret.status_code)
self.mock_dntd.assert_called_once_with(
mock.ANY, self.node.uuid, 'test-topic')
def test_provision_invalid_state_request(self):
ret = self.put_json('/nodes/%s/states/provision' % self.node.uuid,
{'target': 'not-supported'}, expect_errors=True)
self.assertEqual(ret.status_code, 400)
self.assertEqual(400, ret.status_code)
def test_provision_already_in_progress(self):
ndict = dbutils.get_test_node(id=1, uuid=utils.generate_uuid(),
@ -746,7 +746,7 @@ class TestPut(base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(ret.status_code, 409) # Conflict
self.assertEqual(409, ret.status_code) # Conflict
def test_provision_already_in_state(self):
ndict = dbutils.get_test_node(id=1, uuid=utils.generate_uuid(),
@ -756,4 +756,4 @@ class TestPut(base.FunctionalTest):
ret = self.put_json('/nodes/%s/states/provision' % node.uuid,
{'target': states.ACTIVE},
expect_errors=True)
self.assertEqual(ret.status_code, 400)
self.assertEqual(400, ret.status_code)

View File

@ -72,7 +72,7 @@ class TestListPorts(base.FunctionalTest):
port = self.dbapi.create_port(pdict)
response = self.get_json('/ports/%s/detail' % port['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(404, response.status_int)
def test_many(self):
ports = []
@ -94,7 +94,7 @@ class TestListPorts(base.FunctionalTest):
self.dbapi.create_port(ndict)
data = self.get_json('/ports/%s' % uuid)
self.assertIn('links', data.keys())
self.assertEqual(len(data['links']), 2)
self.assertEqual(2, len(data['links']))
self.assertIn(uuid, data['links'][0]['href'])
self.assertTrue(self.validate_link(data['links'][0]['href']))
self.assertTrue(self.validate_link(data['links'][1]['href']))
@ -108,7 +108,7 @@ class TestListPorts(base.FunctionalTest):
port = self.dbapi.create_port(ndict)
ports.append(port['uuid'])
data = self.get_json('/ports/?limit=3')
self.assertEqual(len(data['ports']), 3)
self.assertEqual(3, len(data['ports']))
next_marker = data['ports'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -123,7 +123,7 @@ class TestListPorts(base.FunctionalTest):
port = self.dbapi.create_port(ndict)
ports.append(port['uuid'])
data = self.get_json('/ports')
self.assertEqual(len(data['ports']), 3)
self.assertEqual(3, len(data['ports']))
next_marker = data['ports'][-1]['uuid']
self.assertIn(next_marker, data['next'])
@ -147,10 +147,10 @@ class TestPatch(base.FunctionalTest):
[{'path': '/extra/foo',
'value': 'bar',
'op': 'add'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % self.pdict['uuid'])
self.assertEqual(result['extra'], extra)
self.assertEqual(extra, result['extra'])
return_updated_at = timeutils.parse_isotime(
result['updated_at']).replace(tzinfo=None)
self.assertEqual(t1, return_updated_at)
@ -159,8 +159,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.pdict['address'],
[{'path': '/extra/foo', 'value': 'bar',
'op': 'add'}], expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(self.pdict['address'], response.json['error_message'])
def test_update_not_found(self):
@ -170,8 +170,8 @@ class TestPatch(base.FunctionalTest):
'value': 'b',
'op': 'add'}],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_replace_singular(self):
@ -179,10 +179,10 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.pdict['uuid'],
[{'path': '/address',
'value': address, 'op': 'replace'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % self.pdict['uuid'])
self.assertEqual(result['address'], address)
self.assertEqual(address, result['address'])
def test_replace_address_already_exist(self):
pdict1 = post_get_test_port(address='AA:AA:AA:AA:AA:AA',
@ -198,8 +198,8 @@ class TestPatch(base.FunctionalTest):
'value': pdict2['address'],
'op': 'replace'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 409)
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_nodeid_dont_exist(self):
@ -208,8 +208,8 @@ class TestPatch(base.FunctionalTest):
'value': '12506333-a81c-4d59-9987-889ed5f8687b',
'op': 'replace'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_replace_multi(self):
@ -222,12 +222,12 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/ports/%s' % pdict['uuid'],
[{'path': '/extra/foo2',
'value': new_value, 'op': 'replace'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % pdict['uuid'])
extra["foo2"] = new_value
self.assertEqual(result['extra'], extra)
self.assertEqual(extra, result['extra'])
def test_remove_multi(self):
extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
@ -239,30 +239,30 @@ class TestPatch(base.FunctionalTest):
# Removing one item from the collection
response = self.patch_json('/ports/%s' % pdict['uuid'],
[{'path': '/extra/foo2', 'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % pdict['uuid'])
extra.pop("foo2")
self.assertEqual(result['extra'], extra)
self.assertEqual(extra, result['extra'])
# Removing the collection
response = self.patch_json('/ports/%s' % pdict['uuid'],
[{'path': '/extra', 'op': 'remove'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % pdict['uuid'])
self.assertEqual(result['extra'], {})
self.assertEqual({}, result['extra'])
# Assert nothing else was changed
self.assertEqual(result['uuid'], pdict['uuid'])
self.assertEqual(result['address'], pdict['address'])
self.assertEqual(pdict['uuid'], result['uuid'])
self.assertEqual(pdict['address'], result['address'])
def test_remove_non_existent_property_fail(self):
response = self.patch_json('/ports/%s' % self.pdict['uuid'],
[{'path': '/extra/non-existent', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type, )
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_remove_mandatory_field(self):
@ -272,8 +272,8 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/ports/%s' % pdict['uuid'],
[{'path': '/address', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['error_message'])
def test_add_singular(self):
@ -281,8 +281,8 @@ class TestPatch(base.FunctionalTest):
[{'path': '/foo', 'value': 'bar',
'op': 'add'}],
expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_add_multi(self):
@ -291,18 +291,18 @@ class TestPatch(base.FunctionalTest):
'op': 'add'},
{'path': '/extra/foo2', 'value': 'bar2',
'op': 'add'}])
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual('application/json', response.content_type)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % self.pdict['uuid'])
expected = {"foo1": "bar1", "foo2": "bar2"}
self.assertEqual(result['extra'], expected)
self.assertEqual(expected, result['extra'])
def test_remove_uuid(self):
response = self.patch_json('/ports/%s' % self.pdict['uuid'],
[{'path': '/uuid', 'op': 'remove'}],
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_update_address_invalid_format(self):
@ -314,8 +314,8 @@ class TestPatch(base.FunctionalTest):
'value': 'invalid-format',
'op': 'replace'}],
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_update_port_address_normalized(self):
@ -323,7 +323,7 @@ class TestPatch(base.FunctionalTest):
response = self.patch_json('/ports/%s' % self.pdict['uuid'],
[{'path': '/address', 'value': new_address,
'op': 'replace'}])
self.assertEqual(response.status_code, 200)
self.assertEqual(200, response.status_code)
result = self.get_json('/ports/%s' % self.pdict['uuid'])
self.assertEqual(new_address.lower(), result['address'])
@ -366,31 +366,31 @@ class TestPost(base.FunctionalTest):
def test_create_port_invalid_extra(self):
pdict = post_get_test_port(extra={'foo': 0.123})
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_no_mandatory_field_address(self):
pdict = post_get_test_port()
del pdict['address']
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_no_mandatory_field_node_uuid(self):
pdict = post_get_test_port()
del pdict['node_uuid']
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_invalid_addr_format(self):
pdict = post_get_test_port(address='invalid-format')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_address_normalized(self):
@ -406,15 +406,15 @@ class TestPost(base.FunctionalTest):
hyphensMAC = colonsMAC.replace(':', '-')
pdict['address'] = hyphensMAC
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_create_port_invalid_node_uuid_format(self):
pdict = post_get_test_port(node_uuid='invalid-format')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_node_uuid_to_node_id_mapping(self):
@ -428,8 +428,8 @@ class TestPost(base.FunctionalTest):
pdict = post_get_test_port(
node_uuid='1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e')
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.status_int, 400)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_create_port_address_already_exist(self):
@ -438,8 +438,8 @@ class TestPost(base.FunctionalTest):
self.post_json('/ports', pdict)
pdict['uuid'] = utils.generate_uuid()
response = self.post_json('/ports', pdict, expect_errors=True)
self.assertEqual(response.status_int, 409)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(409, response.status_int)
self.assertEqual('application/json', response.content_type)
error_msg = response.json['error_message']
self.assertTrue(error_msg)
self.assertIn(address, error_msg.upper())
@ -459,14 +459,14 @@ class TestDelete(base.FunctionalTest):
self.delete('/ports/%s' % pdict['uuid'])
response = self.get_json('/ports/%s' % pdict['uuid'],
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(404, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['error_message'])
def test_delete_port_byaddress(self):
pdict = dbutils.get_test_port()
response = self.delete('/ports/%s' % pdict['address'],
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(400, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn(pdict['address'], response.json['error_message'])