diff --git a/libra/mgm/nova.py b/libra/mgm/nova.py index 05d16a61..ee89437b 100644 --- a/libra/mgm/nova.py +++ b/libra/mgm/nova.py @@ -29,5 +29,5 @@ class Node(object): "imageId": image, "flavourId": node_type, }} - resp, body = self.api.post(url, body) + resp, body = self.nova.post(url, body) return body diff --git a/tests/mock.py b/tests/mock_objects.py similarity index 100% rename from tests/mock.py rename to tests/mock_objects.py diff --git a/tests/test_lbaas_mgm.py b/tests/test_lbaas_mgm.py index 5c172f32..c8a1d4b8 100644 --- a/tests/test_lbaas_mgm.py +++ b/tests/test_lbaas_mgm.py @@ -1,15 +1,41 @@ import unittest import logging - import mock +import httplib2 + +import mock_objects +from libra.mgm.nova import Node + +fake_response = httplib2.Response({"status": 200}) +fake_body = '{"hi": "there"}' +mock_request = mock.Mock(return_value=(fake_response, fake_body)) class TestLBaaSMgmTask(unittest.TestCase): def setUp(self): self.logger = logging.getLogger('lbass_mgm_test') - self.lh = mock.MockLoggingHandler() + self.lh = mock_objects.MockLoggingHandler() self.logger.setLevel(logging.DEBUG) self.logger.addHandler(self.lh) def tearDown(self): pass + + +class TestLBaaSMgmNova(unittest.TestCase): + def setUp(self): + self.api = Node( + "username", "password", "auth_test", "tenant1", "region1" + ) + self.api.nova.management_url = "http://example.com" + self.api.nova.auth_token = "token" + + def tearDown(self): + pass + + def testCreateNode(self): + @mock.patch.object(httplib2.Http, "request", mock_request) + @mock.patch('time.time', mock.Mock(return_value=1234)) + def testCreateCall(): + data = self.api.create('4321', '123', '321') + self.assertEqual(data, {"hi": "there"}) diff --git a/tools/pip-requires b/tools/pip-requires index 801a5157..b9c1d43a 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -1,3 +1,4 @@ gearman python-daemon requests +python_novaclient diff --git a/tools/test-requires b/tools/test-requires index 922f930d..284e5195 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -1 +1,3 @@ pytest-pep8 +mock +httplib2 diff --git a/tox.ini b/tox.ini index 99de3cec..95837688 100644 --- a/tox.ini +++ b/tox.ini @@ -11,4 +11,4 @@ commands = py.test --pep8 -k pep8 --clearcache [testenv:pyflakes] deps = pyflakes -commands = pyflakes libra +commands = pyflakes libra