Refactor the test cases so that all the test cases are under one test class.
Change-Id: I31c5c51a3f7fa4b7cb068b7b93692411956e62ac
This commit is contained in:
parent
50117fb2e8
commit
5d1a013baf
@ -49,6 +49,15 @@ class TestDhcpAgent(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.driver_cls_p.stop()
|
self.driver_cls_p.stop()
|
||||||
|
|
||||||
|
def test_dhcp_agent_main(self):
|
||||||
|
with mock.patch('quantum.agent.dhcp_agent.DeviceManager') as dev_mgr:
|
||||||
|
with mock.patch('quantum.agent.dhcp_agent.DhcpAgent') as dhcp:
|
||||||
|
dhcp_agent.main()
|
||||||
|
dev_mgr.assert_called_once(mock.ANY, 'sudo')
|
||||||
|
dhcp.assert_has_calls([
|
||||||
|
mock.call(mock.ANY),
|
||||||
|
mock.call().daemon_loop()])
|
||||||
|
|
||||||
def test_daemon_loop_survives_get_network_state_delta_failure(self):
|
def test_daemon_loop_survives_get_network_state_delta_failure(self):
|
||||||
def stop_loop(*args):
|
def stop_loop(*args):
|
||||||
self.dhcp._run = False
|
self.dhcp._run = False
|
||||||
@ -254,8 +263,6 @@ class TestDeviceManager(unittest.TestCase):
|
|||||||
self.filter_called = True
|
self.filter_called = True
|
||||||
raise sqlsoup.SQLAlchemyError()
|
raise sqlsoup.SQLAlchemyError()
|
||||||
|
|
||||||
return filter_results.pop(0)
|
|
||||||
|
|
||||||
mock_db = mock.Mock()
|
mock_db = mock.Mock()
|
||||||
mock_db.ports = mock.Mock(name='ports2')
|
mock_db.ports = mock.Mock(name='ports2')
|
||||||
mock_db.ports.filter_by = mock.Mock(
|
mock_db.ports.filter_by = mock.Mock(
|
||||||
@ -305,8 +312,6 @@ class TestDeviceManager(unittest.TestCase):
|
|||||||
self.filter_called = True
|
self.filter_called = True
|
||||||
raise sqlsoup.SQLAlchemyError()
|
raise sqlsoup.SQLAlchemyError()
|
||||||
|
|
||||||
return filter_results.pop(0)
|
|
||||||
|
|
||||||
mock_db = mock.Mock()
|
mock_db = mock.Mock()
|
||||||
mock_db.ports = mock.Mock(name='ports2')
|
mock_db.ports = mock.Mock(name='ports2')
|
||||||
mock_db.ports.filter_by = mock.Mock(
|
mock_db.ports.filter_by = mock.Mock(
|
||||||
@ -336,13 +341,3 @@ class TestAugmentingWrapper(unittest.TestCase):
|
|||||||
wrapped = dhcp_agent.AugmentingWrapper(net, db)
|
wrapped = dhcp_agent.AugmentingWrapper(net, db)
|
||||||
self.assertEqual(wrapped.name, 'foo')
|
self.assertEqual(wrapped.name, 'foo')
|
||||||
self.assertEqual(repr(net), repr(wrapped))
|
self.assertEqual(repr(net), repr(wrapped))
|
||||||
|
|
||||||
|
|
||||||
def test_dhcp_agent_main():
|
|
||||||
with mock.patch('quantum.agent.dhcp_agent.DeviceManager') as dev_mgr:
|
|
||||||
with mock.patch('quantum.agent.dhcp_agent.DhcpAgent') as dhcp:
|
|
||||||
dhcp_agent.main()
|
|
||||||
dev_mgr.assert_called_once(mock.ANY, 'sudo')
|
|
||||||
dhcp.assert_has_calls([
|
|
||||||
mock.call(mock.ANY),
|
|
||||||
mock.call().daemon_loop()])
|
|
||||||
|
@ -90,7 +90,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
member = {'notimplemented_function': "GET"}
|
member = {'notimplemented_function': "GET"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
member_actions=member)
|
member_actions=member)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
# Ideally we would check for a 501 code here but webtest doesn't take
|
# Ideally we would check for a 501 code here but webtest doesn't take
|
||||||
# anything that is below 200 or above 400 so we can't actually check
|
# anything that is below 200 or above 400 so we can't actually check
|
||||||
@ -106,7 +106,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
def test_resource_can_be_added_as_extension(self):
|
def test_resource_can_be_added_as_extension(self):
|
||||||
res_ext = extensions.ResourceExtension(
|
res_ext = extensions.ResourceExtension(
|
||||||
'tweedles', self.ResourceExtensionController())
|
'tweedles', self.ResourceExtensionController())
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
index_response = test_app.get("/tweedles")
|
index_response = test_app.get("/tweedles")
|
||||||
self.assertEqual(200, index_response.status_int)
|
self.assertEqual(200, index_response.status_int)
|
||||||
self.assertEqual("resource index", index_response.body)
|
self.assertEqual("resource index", index_response.body)
|
||||||
@ -119,7 +119,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
member = {'custom_member_action': "GET"}
|
member = {'custom_member_action': "GET"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
member_actions=member)
|
member_actions=member)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.get("/tweedles/some_id/custom_member_action")
|
response = test_app.get("/tweedles/some_id/custom_member_action")
|
||||||
self.assertEqual(200, response.status_int)
|
self.assertEqual(200, response.status_int)
|
||||||
@ -131,7 +131,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
collections = {'custom_collection_action': "GET"}
|
collections = {'custom_collection_action': "GET"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections)
|
collection_actions=collections)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.get("/tweedles/custom_collection_action")
|
response = test_app.get("/tweedles/custom_collection_action")
|
||||||
self.assertEqual(200, response.status_int)
|
self.assertEqual(200, response.status_int)
|
||||||
@ -142,7 +142,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
collections = {'custom_collection_action': "PUT"}
|
collections = {'custom_collection_action': "PUT"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections)
|
collection_actions=collections)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.put("/tweedles/custom_collection_action")
|
response = test_app.put("/tweedles/custom_collection_action")
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
collections = {'custom_collection_action': "POST"}
|
collections = {'custom_collection_action': "POST"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections)
|
collection_actions=collections)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.post("/tweedles/custom_collection_action")
|
response = test_app.post("/tweedles/custom_collection_action")
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
collections = {'custom_collection_action': "DELETE"}
|
collections = {'custom_collection_action': "DELETE"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections)
|
collection_actions=collections)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.delete("/tweedles/custom_collection_action")
|
response = test_app.delete("/tweedles/custom_collection_action")
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
collections = {'custom_collection_action': "GET"}
|
collections = {'custom_collection_action': "GET"}
|
||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections)
|
collection_actions=collections)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.get("/tweedles/custom_collection_action.json")
|
response = test_app.get("/tweedles/custom_collection_action.json")
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
res_ext = extensions.ResourceExtension('tweedles', controller,
|
res_ext = extensions.ResourceExtension('tweedles', controller,
|
||||||
collection_actions=collections,
|
collection_actions=collections,
|
||||||
parent=parent)
|
parent=parent)
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
|
||||||
|
|
||||||
response = test_app.get("/beetles/beetle_id"
|
response = test_app.get("/beetles/beetle_id"
|
||||||
"/tweedles/custom_collection_action")
|
"/tweedles/custom_collection_action")
|
||||||
@ -201,7 +201,7 @@ class ResourceExtensionTest(unittest.TestCase):
|
|||||||
self.assertEqual(jsonutils.loads(response.body)['collection'], "value")
|
self.assertEqual(jsonutils.loads(response.body)['collection'], "value")
|
||||||
|
|
||||||
def test_returns_404_for_non_existant_extension(self):
|
def test_returns_404_for_non_existant_extension(self):
|
||||||
test_app = setup_extensions_test_app(SimpleExtensionManager(None))
|
test_app = _setup_extensions_test_app(SimpleExtensionManager(None))
|
||||||
|
|
||||||
response = test_app.get("/non_extistant_extension", status='*')
|
response = test_app.get("/non_extistant_extension", status='*')
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class ActionExtensionTest(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ActionExtensionTest, self).setUp()
|
super(ActionExtensionTest, self).setUp()
|
||||||
self.extension_app = setup_extensions_test_app()
|
self.extension_app = _setup_extensions_test_app()
|
||||||
|
|
||||||
def test_extended_action_for_adding_extra_data(self):
|
def test_extended_action_for_adding_extra_data(self):
|
||||||
action_name = 'FOXNSOX:add_tweedle'
|
action_name = 'FOXNSOX:add_tweedle'
|
||||||
@ -287,7 +287,7 @@ class RequestExtensionTest(BaseTest):
|
|||||||
self.assertEqual('knox', response_data['fort'])
|
self.assertEqual('knox', response_data['fort'])
|
||||||
|
|
||||||
def test_get_resources(self):
|
def test_get_resources(self):
|
||||||
app = setup_extensions_test_app()
|
app = _setup_extensions_test_app()
|
||||||
|
|
||||||
response = app.get("/dummy_resources/1?chewing=newblue")
|
response = app.get("/dummy_resources/1?chewing=newblue")
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ class RequestExtensionTest(BaseTest):
|
|||||||
'/dummy_resources/:(id)',
|
'/dummy_resources/:(id)',
|
||||||
handler)
|
handler)
|
||||||
manager = SimpleExtensionManager(None, None, req_ext)
|
manager = SimpleExtensionManager(None, None, req_ext)
|
||||||
return setup_extensions_test_app(manager)
|
return _setup_extensions_test_app(manager)
|
||||||
|
|
||||||
|
|
||||||
class ExtensionManagerTest(unittest.TestCase):
|
class ExtensionManagerTest(unittest.TestCase):
|
||||||
@ -434,7 +434,7 @@ class ExtensionControllerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ExtensionControllerTest, self).setUp()
|
super(ExtensionControllerTest, self).setUp()
|
||||||
self.test_app = setup_extensions_test_app()
|
self.test_app = _setup_extensions_test_app()
|
||||||
|
|
||||||
def test_index_gets_all_registerd_extensions(self):
|
def test_index_gets_all_registerd_extensions(self):
|
||||||
response = self.test_app.get("/extensions")
|
response = self.test_app.get("/extensions")
|
||||||
@ -482,7 +482,7 @@ def setup_extensions_middleware(extension_manager=None):
|
|||||||
return ExtensionMiddleware(app, ext_mgr=extension_manager)
|
return ExtensionMiddleware(app, ext_mgr=extension_manager)
|
||||||
|
|
||||||
|
|
||||||
def setup_extensions_test_app(extension_manager=None):
|
def _setup_extensions_test_app(extension_manager=None):
|
||||||
return TestApp(setup_extensions_middleware(extension_manager))
|
return TestApp(setup_extensions_middleware(extension_manager))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user