Utilizes assertIsNone and assertIsNotNone
Using assertTrue and the 'is' operator to test if an element is None is too python2.4. Our unit testing framework supports assertIsNone and assertIsNotNone which were created for these types of tests. Fixes bug #1230028 Change-Id: Ia58d92c52d0aca9c22360dd44de19d4e5878ab13
This commit is contained in:
parent
512bdfa713
commit
d53f1c8570
@ -58,7 +58,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
|
|
||||||
def test_construct_eventlet_api_request(self):
|
def test_construct_eventlet_api_request(self):
|
||||||
e = nare.NvpApiRequestEventlet(self.client, self.url)
|
e = nare.NvpApiRequestEventlet(self.client, self.url)
|
||||||
self.assertTrue(e is not None)
|
self.assertIsNotNone(e)
|
||||||
|
|
||||||
def test_apirequest_spawn(self):
|
def test_apirequest_spawn(self):
|
||||||
def x(id):
|
def x(id):
|
||||||
@ -99,7 +99,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
self.assertTrue(getattr(req, att) is getattr(self.req, att))
|
self.assertTrue(getattr(req, att) is getattr(self.req, att))
|
||||||
|
|
||||||
def test_request_error(self):
|
def test_request_error(self):
|
||||||
self.assertTrue(self.req.request_error is None)
|
self.assertIsNone(self.req.request_error)
|
||||||
|
|
||||||
def test_run_and_handle_request(self):
|
def test_run_and_handle_request(self):
|
||||||
self.req._request_timeout = None
|
self.req._request_timeout = None
|
||||||
@ -118,7 +118,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
self.req._handle_request = new.instancemethod(
|
self.req._handle_request = new.instancemethod(
|
||||||
my_handle_request, self.req, nare.NvpApiRequestEventlet)
|
my_handle_request, self.req, nare.NvpApiRequestEventlet)
|
||||||
self.req.start()
|
self.req.start()
|
||||||
self.assertTrue(self.req.join() is None)
|
self.assertIsNone(self.req.join())
|
||||||
|
|
||||||
def prep_issue_request(self):
|
def prep_issue_request(self):
|
||||||
mysock = Mock()
|
mysock = Mock()
|
||||||
@ -165,52 +165,52 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
(mysock, myresponse, myconn) = self.prep_issue_request()
|
(mysock, myresponse, myconn) = self.prep_issue_request()
|
||||||
myconn.sock = None
|
myconn.sock = None
|
||||||
self.req.start()
|
self.req.start()
|
||||||
self.assertTrue(self.req.join() is None)
|
self.assertIsNone(self.req.join())
|
||||||
self.assertTrue(self.client.acquire_connection.called)
|
self.assertTrue(self.client.acquire_connection.called)
|
||||||
|
|
||||||
def test_issue_request_exceed_maximum_retries(self):
|
def test_issue_request_exceed_maximum_retries(self):
|
||||||
(mysock, myresponse, myconn) = self.prep_issue_request()
|
(mysock, myresponse, myconn) = self.prep_issue_request()
|
||||||
self.req.start()
|
self.req.start()
|
||||||
self.assertTrue(self.req.join() is None)
|
self.assertIsNone(self.req.join())
|
||||||
self.assertTrue(self.client.acquire_connection.called)
|
self.assertTrue(self.client.acquire_connection.called)
|
||||||
|
|
||||||
def test_issue_request_trigger_non_redirect(self):
|
def test_issue_request_trigger_non_redirect(self):
|
||||||
(mysock, myresponse, myconn) = self.prep_issue_request()
|
(mysock, myresponse, myconn) = self.prep_issue_request()
|
||||||
myresponse.status = httplib.OK
|
myresponse.status = httplib.OK
|
||||||
self.req.start()
|
self.req.start()
|
||||||
self.assertTrue(self.req.join() is None)
|
self.assertIsNone(self.req.join())
|
||||||
self.assertTrue(self.client.acquire_connection.called)
|
self.assertTrue(self.client.acquire_connection.called)
|
||||||
|
|
||||||
def test_issue_request_trigger_internal_server_error(self):
|
def test_issue_request_trigger_internal_server_error(self):
|
||||||
(mysock, myresponse, myconn) = self.prep_issue_request()
|
(mysock, myresponse, myconn) = self.prep_issue_request()
|
||||||
self.req._redirect_params.return_value = (myconn, None)
|
self.req._redirect_params.return_value = (myconn, None)
|
||||||
self.req.start()
|
self.req.start()
|
||||||
self.assertTrue(self.req.join() is None)
|
self.assertIsNone(self.req.join())
|
||||||
self.assertTrue(self.client.acquire_connection.called)
|
self.assertTrue(self.client.acquire_connection.called)
|
||||||
|
|
||||||
def test_redirect_params_break_on_location(self):
|
def test_redirect_params_break_on_location(self):
|
||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', None)])
|
myconn, [('location', None)])
|
||||||
self.assertTrue(retval is None)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
def test_redirect_params_parse_a_url(self):
|
def test_redirect_params_parse_a_url(self):
|
||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', '/path/a/b/c')])
|
myconn, [('location', '/path/a/b/c')])
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
|
|
||||||
def test_redirect_params_invalid_redirect_location(self):
|
def test_redirect_params_invalid_redirect_location(self):
|
||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', '+path/a/b/c')])
|
myconn, [('location', '+path/a/b/c')])
|
||||||
self.assertTrue(retval is None)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
def test_redirect_params_invalid_scheme(self):
|
def test_redirect_params_invalid_scheme(self):
|
||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', 'invalidscheme://hostname:1/path')])
|
myconn, [('location', 'invalidscheme://hostname:1/path')])
|
||||||
self.assertTrue(retval is None)
|
self.assertIsNone(retval)
|
||||||
|
|
||||||
def test_redirect_params_setup_https_with_cooki(self):
|
def test_redirect_params_setup_https_with_cooki(self):
|
||||||
with patch(CLIENT_NAME) as mock:
|
with patch(CLIENT_NAME) as mock:
|
||||||
@ -220,7 +220,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', 'https://host:1/path')])
|
myconn, [('location', 'https://host:1/path')])
|
||||||
|
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||||
|
|
||||||
def test_redirect_params_setup_htttps_and_query(self):
|
def test_redirect_params_setup_htttps_and_query(self):
|
||||||
@ -231,7 +231,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
(conn, retval) = self.req._redirect_params(myconn, [
|
(conn, retval) = self.req._redirect_params(myconn, [
|
||||||
('location', 'https://host:1/path?q=1')])
|
('location', 'https://host:1/path?q=1')])
|
||||||
|
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||||
|
|
||||||
def test_redirect_params_setup_https_connection_no_cookie(self):
|
def test_redirect_params_setup_https_connection_no_cookie(self):
|
||||||
@ -242,7 +242,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
(conn, retval) = self.req._redirect_params(myconn, [
|
(conn, retval) = self.req._redirect_params(myconn, [
|
||||||
('location', 'https://host:1/path')])
|
('location', 'https://host:1/path')])
|
||||||
|
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||||
|
|
||||||
def test_redirect_params_setup_https_and_query_no_cookie(self):
|
def test_redirect_params_setup_https_and_query_no_cookie(self):
|
||||||
@ -252,7 +252,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(
|
(conn, retval) = self.req._redirect_params(
|
||||||
myconn, [('location', 'https://host:1/path?q=1')])
|
myconn, [('location', 'https://host:1/path?q=1')])
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
self.assertTrue(api_client.acquire_redirect_connection.called)
|
self.assertTrue(api_client.acquire_redirect_connection.called)
|
||||||
|
|
||||||
def test_redirect_params_path_only_with_query(self):
|
def test_redirect_params_path_only_with_query(self):
|
||||||
@ -264,7 +264,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
myconn = Mock()
|
myconn = Mock()
|
||||||
(conn, retval) = self.req._redirect_params(myconn, [
|
(conn, retval) = self.req._redirect_params(myconn, [
|
||||||
('location', '/path?q=1')])
|
('location', '/path?q=1')])
|
||||||
self.assertTrue(retval is not None)
|
self.assertIsNotNone(retval)
|
||||||
|
|
||||||
def test_handle_request_auto_login(self):
|
def test_handle_request_auto_login(self):
|
||||||
self.req._auto_login = True
|
self.req._auto_login = True
|
||||||
@ -294,7 +294,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
# NvpLoginRequestEventlet tests.
|
# NvpLoginRequestEventlet tests.
|
||||||
def test_construct_eventlet_login_request(self):
|
def test_construct_eventlet_login_request(self):
|
||||||
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
||||||
self.assertTrue(r is not None)
|
self.assertIsNotNone(r)
|
||||||
|
|
||||||
def test_session_cookie_session_cookie_retrieval(self):
|
def test_session_cookie_session_cookie_retrieval(self):
|
||||||
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
||||||
@ -303,7 +303,7 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
r.value = Mock()
|
r.value = Mock()
|
||||||
r.value.get_header = Mock()
|
r.value.get_header = Mock()
|
||||||
r.value.get_header.return_value = 'cool'
|
r.value.get_header.return_value = 'cool'
|
||||||
self.assertTrue(r.session_cookie() is not None)
|
self.assertIsNotNone(r.session_cookie())
|
||||||
|
|
||||||
def test_session_cookie_not_retrieved(self):
|
def test_session_cookie_not_retrieved(self):
|
||||||
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
r = nare.NvpLoginRequestEventlet(self.client, 'user', 'password')
|
||||||
@ -312,17 +312,17 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
r.value = Mock()
|
r.value = Mock()
|
||||||
r.value.get_header = Mock()
|
r.value.get_header = Mock()
|
||||||
r.value.get_header.return_value = 'cool'
|
r.value.get_header.return_value = 'cool'
|
||||||
self.assertTrue(r.session_cookie() is None)
|
self.assertIsNone(r.session_cookie())
|
||||||
|
|
||||||
# NvpGetApiProvidersRequestEventlet tests.
|
# NvpGetApiProvidersRequestEventlet tests.
|
||||||
def test_construct_eventlet_get_api_providers_request(self):
|
def test_construct_eventlet_get_api_providers_request(self):
|
||||||
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
||||||
self.assertTrue(r is not None)
|
self.assertIsNotNone(r)
|
||||||
|
|
||||||
def test_api_providers_none_api_providers(self):
|
def test_api_providers_none_api_providers(self):
|
||||||
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
||||||
r.successful = Mock(return_value=False)
|
r.successful = Mock(return_value=False)
|
||||||
self.assertTrue(r.api_providers() is None)
|
self.assertIsNone(r.api_providers())
|
||||||
|
|
||||||
def test_api_providers_non_none_api_providers(self):
|
def test_api_providers_non_none_api_providers(self):
|
||||||
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
r = nare.NvpGetApiProvidersRequestEventlet(self.client)
|
||||||
@ -334,4 +334,4 @@ class NvpApiRequestEventletTest(base.BaseTestCase):
|
|||||||
"listen_addr": "pssl:1.1.1.1:1" }]}]}"""
|
"listen_addr": "pssl:1.1.1.1:1" }]}]}"""
|
||||||
r.successful = Mock(return_value=True)
|
r.successful = Mock(return_value=True)
|
||||||
LOG.info('%s' % r.api_providers())
|
LOG.info('%s' % r.api_providers())
|
||||||
self.assertTrue(r.api_providers() is not None)
|
self.assertIsNotNone(r.api_providers())
|
||||||
|
@ -885,7 +885,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase):
|
|||||||
another_l3_agent_id = com['id']
|
another_l3_agent_id = com['id']
|
||||||
another_l3_agent_host = com['host']
|
another_l3_agent_host = com['host']
|
||||||
break
|
break
|
||||||
self.assertTrue(another_l3_agent_id is not None)
|
self.assertIsNotNone(another_l3_agent_id)
|
||||||
self._add_router_to_l3_agent(another_l3_agent_id,
|
self._add_router_to_l3_agent(another_l3_agent_id,
|
||||||
router['router']['id'],
|
router['router']['id'],
|
||||||
expected_code=exc.HTTPConflict.code)
|
expected_code=exc.HTTPConflict.code)
|
||||||
|
Loading…
Reference in New Issue
Block a user