Change try..except to assertRaises in UT
Following patch changes the try..except condition for testing to assertRaises. Change-Id: I2253b4e75f778ad077bd905487ede075a430a1fa
This commit is contained in:
@@ -695,13 +695,10 @@ class ClientV2TestJson(CLITestV20Base):
|
|||||||
def test_do_request_with_long_uri_exception(self):
|
def test_do_request_with_long_uri_exception(self):
|
||||||
long_string = 'x' * 8200 # 8200 > MAX_URI_LEN:8192
|
long_string = 'x' * 8200 # 8200 > MAX_URI_LEN:8192
|
||||||
params = {'id': long_string}
|
params = {'id': long_string}
|
||||||
|
exception = self.assertRaises(exceptions.RequestURITooLong,
|
||||||
try:
|
self.client.do_request,
|
||||||
self.client.do_request('GET', '/test', body='', params=params)
|
'GET', '/test', body='', params=params)
|
||||||
except exceptions.RequestURITooLong as cm:
|
self.assertNotEqual(0, exception.excess)
|
||||||
self.assertNotEqual(0, cm.excess)
|
|
||||||
else:
|
|
||||||
self.fail('Expected exception NOT raised')
|
|
||||||
|
|
||||||
def test_do_request_request_ids(self):
|
def test_do_request_request_ids(self):
|
||||||
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
||||||
|
|||||||
@@ -260,13 +260,10 @@ class CLITestV20RouterJSON(test_cli20.CLITestV20Base):
|
|||||||
'--no-routes',
|
'--no-routes',
|
||||||
'--route',
|
'--route',
|
||||||
'destination=10.0.3.0/24,nexthop=10.0.0.10']
|
'destination=10.0.3.0/24,nexthop=10.0.0.10']
|
||||||
actual_error_code = 0
|
exception = self.assertRaises(SystemExit,
|
||||||
try:
|
self._test_update_resource,
|
||||||
self._test_update_resource(resource, cmd, myid, args, None)
|
resource, cmd, myid, args, None)
|
||||||
except SystemExit:
|
self.assertEqual(2, exception.code)
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
||||||
actual_error_code = exc_value.code
|
|
||||||
self.assertEqual(2, actual_error_code)
|
|
||||||
|
|
||||||
def test_delete_router(self):
|
def test_delete_router(self):
|
||||||
# Delete router: myid.
|
# Delete router: myid.
|
||||||
|
|||||||
@@ -648,15 +648,11 @@ class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
|
|||||||
# Update sbunet: --enable-dhcp and --disable-dhcp.
|
# Update sbunet: --enable-dhcp and --disable-dhcp.
|
||||||
resource = 'subnet'
|
resource = 'subnet'
|
||||||
cmd = subnet.UpdateSubnet(test_cli20.MyApp(sys.stdout), None)
|
cmd = subnet.UpdateSubnet(test_cli20.MyApp(sys.stdout), None)
|
||||||
try:
|
self.assertRaises(exceptions.CommandError,
|
||||||
self._test_update_resource(resource, cmd, 'myid',
|
self._test_update_resource,
|
||||||
['myid', '--name', 'myname',
|
resource, cmd, 'myid',
|
||||||
'--enable-dhcp', '--disable-dhcp'],
|
['myid', '--name', 'myname', '--enable-dhcp',
|
||||||
{'name': 'myname', }
|
'--disable-dhcp'], {'name': 'myname', })
|
||||||
)
|
|
||||||
except exceptions.CommandError:
|
|
||||||
return
|
|
||||||
self.fail('No exception for --enable-dhcp --disable-dhcp option')
|
|
||||||
|
|
||||||
def test_show_subnet(self):
|
def test_show_subnet(self):
|
||||||
# Show subnet: --fields id --fields name myid.
|
# Show subnet: --fields id --fields name myid.
|
||||||
|
|||||||
@@ -120,11 +120,10 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
||||||
).AndReturn((test_cli20.MyResp(200), resstr))
|
).AndReturn((test_cli20.MyResp(200), resstr))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
try:
|
exception = self.assertRaises(exceptions.NeutronClientNoUniqueMatch,
|
||||||
neutronV20.find_resourceid_by_name_or_id(
|
neutronV20.find_resourceid_by_name_or_id,
|
||||||
self.client, 'network', name)
|
self.client, 'network', name)
|
||||||
except exceptions.NeutronClientNoUniqueMatch as ex:
|
self.assertIn('Multiple', exception.message)
|
||||||
self.assertIn('Multiple', ex.message)
|
|
||||||
|
|
||||||
def test_get_id_from_name_notfound(self):
|
def test_get_id_from_name_notfound(self):
|
||||||
name = 'myname'
|
name = 'myname'
|
||||||
@@ -141,12 +140,11 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
||||||
).AndReturn((test_cli20.MyResp(200), resstr))
|
).AndReturn((test_cli20.MyResp(200), resstr))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
try:
|
exception = self.assertRaises(exceptions.NotFound,
|
||||||
neutronV20.find_resourceid_by_name_or_id(
|
neutronV20.find_resourceid_by_name_or_id,
|
||||||
self.client, 'network', name)
|
self.client, 'network', name)
|
||||||
except exceptions.NotFound as ex:
|
self.assertIn('Unable to find', exception.message)
|
||||||
self.assertIn('Unable to find', ex.message)
|
self.assertEqual(404, exception.status_code)
|
||||||
self.assertEqual(404, ex.status_code)
|
|
||||||
|
|
||||||
def test_get_id_from_name_multiple_with_project(self):
|
def test_get_id_from_name_multiple_with_project(self):
|
||||||
name = 'web_server'
|
name = 'web_server'
|
||||||
@@ -175,9 +173,7 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
def test_get_id_from_name_multiple_with_project_not_found(self):
|
def test_get_id_from_name_multiple_with_project_not_found(self):
|
||||||
name = 'web_server'
|
name = 'web_server'
|
||||||
project = str(uuid.uuid4())
|
project = str(uuid.uuid4())
|
||||||
reses = {'security_groups':
|
resstr_notfound = self.client.serialize({'security_groups': []})
|
||||||
[{'id': str(uuid.uuid4()), 'tenant_id': str(uuid.uuid4())}]}
|
|
||||||
resstr = self.client.serialize(reses)
|
|
||||||
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
||||||
path = getattr(self.client, "security_groups_path")
|
path = getattr(self.client, "security_groups_path")
|
||||||
self.client.httpclient.request(
|
self.client.httpclient.request(
|
||||||
@@ -187,12 +183,10 @@ class CLITestNameorID(testtools.TestCase):
|
|||||||
'GET',
|
'GET',
|
||||||
body=None,
|
body=None,
|
||||||
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
|
||||||
).AndReturn((test_cli20.MyResp(200), resstr))
|
).AndReturn((test_cli20.MyResp(200), resstr_notfound))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
exc = self.assertRaises(exceptions.NotFound,
|
||||||
try:
|
neutronV20.find_resourceid_by_name_or_id,
|
||||||
neutronV20.find_resourceid_by_name_or_id(
|
self.client, 'security_group', name, project)
|
||||||
self.client, 'security_group', name, project)
|
self.assertIn('Unable to find', exc.message)
|
||||||
except exceptions.NotFound as ex:
|
self.assertEqual(404, exc.status_code)
|
||||||
self.assertIn('Unable to find', ex.message)
|
|
||||||
self.assertEqual(404, ex.status_code)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user