summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newton/newton/requests/tests/test_base.py57
-rw-r--r--newton/newton/requests/tests/test_flavor.py148
-rw-r--r--newton/newton/requests/tests/test_hosts.py98
-rw-r--r--newton/newton/requests/tests/test_image.py9
-rw-r--r--newton/newton/requests/tests/test_limits.py66
-rw-r--r--newton/newton/requests/tests/test_network.py211
-rw-r--r--newton/newton/requests/tests/test_subnet.py195
-rw-r--r--newton/newton/requests/tests/test_volume.py188
-rw-r--r--newton/newton/requests/views/util.py6
9 files changed, 299 insertions, 679 deletions
diff --git a/newton/newton/requests/tests/test_base.py b/newton/newton/requests/tests/test_base.py
index 2ba05cb0..d2065b06 100644
--- a/newton/newton/requests/tests/test_base.py
+++ b/newton/newton/requests/tests/test_base.py
@@ -63,12 +63,17 @@ class AbstractTestResource(object):
__metaclass__ = ABCMeta
def __init__(self):
- self.openstack_version = ""
- self.region = ""
- self.resource_name = ""
+
+ self.client = Client()
+
+ self.openstack_version = "newton"
+ self.region = "windriver-hudson-dc_RegionOne"
+ self.url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/".format(
+ self.openstack_version, self.region)
self.MOCK_GET_RESOURCES_RESPONSE = {}
self.MOCK_GET_RESOURCE_RESPONSE = {}
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
self.MOCK_POST_RESOURCE_REQUEST = {}
self.MOCK_POST_RESOURCE_REQUEST_EXISTING = {}
@@ -90,11 +95,7 @@ class AbstractTestResource(object):
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
- response = self.client.get(url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.get(self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
@@ -112,11 +113,7 @@ class AbstractTestResource(object):
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
- response = self.client.get(url + "/uuid_1", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.get(self.url + "/uuid_1", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
@@ -128,17 +125,13 @@ class AbstractTestResource(object):
def test_get_resource_not_found(self, mock_get_vim_info, mock_get_session):
mock_get_session.side_effect = [
get_mock_session(
- ["get"], {"get": {"content": {},
+ ["get"], {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND,
"status_code": 404}}),
]
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.get(url + "/uuid_3", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.get(self.url + "/uuid_3", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
self.assertEquals(self.HTTP_not_found, response.status_code)
@@ -147,19 +140,15 @@ class AbstractTestResource(object):
def test_post_resource(self, mock_get_vim_info, mock_get_session):
mock_get_session.side_effect = [
get_mock_session(
- ["get"], {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}),
+ ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}),
get_mock_session(
["post"], {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE,
"status_code": 202}}),
]
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.post(url, self.MOCK_POST_RESOURCE_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.post(self.url, self.MOCK_POST_RESOURCE_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code)
@@ -177,13 +166,9 @@ class AbstractTestResource(object):
"status_code": 201}}),
]
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.post(url, self.MOCK_POST_RESOURCE_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.post(self.url, self.MOCK_POST_RESOURCE_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
@@ -201,13 +186,9 @@ class AbstractTestResource(object):
"status_code": 202}}),
]
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.post(url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.post(self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertIn('error', context)
@@ -223,13 +204,9 @@ class AbstractTestResource(object):
"status_code": 204}})
]
- url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/{}".format(
- self.openstack_version, self.region, self.resource_name
- )
-
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.delete(url + "/uuid_1", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.delete(self.url + "/uuid_1", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
self.assertIsNone(response.data)
diff --git a/newton/newton/requests/tests/test_flavor.py b/newton/newton/requests/tests/test_flavor.py
index 7ddb1122..26e3f381 100644
--- a/newton/newton/requests/tests/test_flavor.py
+++ b/newton/newton/requests/tests/test_flavor.py
@@ -13,54 +13,67 @@
# limitations under the License.
import mock
+import unittest
from rest_framework import status
from newton.requests.tests import mock_info
from newton.requests.tests import test_base
+from newton.requests.tests.test_base import AbstractTestResource
from newton.requests.views.flavor import Flavors
from newton.requests.views.util import VimDriverUtils
-MOCK_GET_FLAVORS_RESPONSE = {
- "flavors": [
- {"id": "uuid_1", "name": "flavor_1"},
- {"id": "uuid_2", "name": "flavor_2"}
- ]
-}
+class TestFlavorsNewton(unittest.TestCase, AbstractTestResource):
-MOCK_GET_FLAVOR_RESPONSE = {
- "flavor": {
- "id": "uuid_1",
- "name": "flavor_1"
- }
-}
+ def setUp(self):
+ AbstractTestResource.__init__(self)
-MOCK_GET_EXTRA_SPECS = {
- "extra_specs": {
- "key": "test"
- }
-}
+ self.url += "flavors"
-MOCK_POST_FLAVOR_REQUEST = {
- "id": "uuid_3",
- "name": "flavor_3"
-}
+ self.MOCK_GET_RESOURCES_RESPONSE = {
+ "flavors": [
+ {"id": "uuid_1", "name": "flavor_1"},
+ {"id": "uuid_2", "name": "flavor_2"}
+ ]
+ }
-MOCK_POST_FLAVOR_REQUEST_EXISTING = {
- "id": "uuid_1",
- "name": "flavor_1"
-}
+ self.MOCK_GET_RESOURCE_RESPONSE = {
+ "flavor": {
+ "id": "uuid_1",
+ "name": "flavor_1"
+ }
+ }
-MOCK_POST_FLAVOR_RESPONSE = {
- "flavor": {
- "id": "uuid_3",
- "name": "flavor_3"
- }
-}
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
+ self.MOCK_POST_RESOURCE_REQUEST = {
+ "id": "uuid_3",
+ "name": "flavor_3"
+ }
-class TestFlavors(test_base.TestRequest):
+ self.MOCK_POST_RESOURCE_REQUEST_EXISTING = {
+ "id": "uuid_1",
+ "name": "flavor_1"
+ }
+
+ self.MOCK_POST_RESOURCE_RESPONSE = {
+ "flavor": {
+ "id": "uuid_3",
+ "name": "flavor_3"
+ }
+ }
+
+ self.MOCK_GET_EXTRA_SPECS = {
+ "extra_specs": {
+ "key": "test"
+ }
+ }
+
+ self.assert_keys = "flavors"
+ self.assert_key = "flavor"
+
+ self.HTTP_not_found = status.HTTP_404_NOT_FOUND
@mock.patch.object(Flavors, '_get_flavor_extra_specs')
@mock.patch.object(VimDriverUtils, 'get_session')
@@ -69,7 +82,7 @@ class TestFlavors(test_base.TestRequest):
mock_get_flavor_extra_specs):
mock_get_session.side_effect = [
test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_FLAVORS_RESPONSE}}),
+ ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}),
]
mock_extra_specs = mock.Mock(spec=test_base.MockResponse)
@@ -86,7 +99,7 @@ class TestFlavors(test_base.TestRequest):
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertIsNotNone(context['flavors'])
- self.assertEqual(MOCK_GET_FLAVORS_RESPONSE["flavors"],
+ self.assertEqual(self.MOCK_GET_RESOURCES_RESPONSE["flavors"],
context['flavors'])
@mock.patch.object(Flavors, '_get_flavor_extra_specs')
@@ -97,7 +110,7 @@ class TestFlavors(test_base.TestRequest):
mock_get_session.side_effect = [
test_base.get_mock_session(
["get"],
- {"get": {"content": MOCK_GET_FLAVOR_RESPONSE}}),
+ {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}),
]
mock_extra_specs = mock.Mock(spec=test_base.MockResponse)
@@ -113,7 +126,7 @@ class TestFlavors(test_base.TestRequest):
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertEqual(MOCK_GET_FLAVOR_RESPONSE["id"], context["id"])
+ self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], context["id"])
@mock.patch.object(Flavors, '_get_flavor_extra_specs')
@mock.patch.object(VimDriverUtils, 'get_session')
@@ -149,9 +162,9 @@ class TestFlavors(test_base.TestRequest):
mock_get_session.side_effect = [
test_base.get_mock_session(
["get", "post"], {
- "get": {"content": MOCK_GET_FLAVORS_RESPONSE},
+ "get": {"content": self.MOCK_GET_RESOURCES_RESPONSE},
"post": {
- "content": MOCK_POST_FLAVOR_RESPONSE,
+ "content": self.MOCK_POST_RESOURCE_RESPONSE,
"status_code": status.HTTP_202_ACCEPTED,
}
}
@@ -162,7 +175,7 @@ class TestFlavors(test_base.TestRequest):
response = self.client.post(
("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne"
"/fcca3cc49d5e42caae15459e27103efc/flavors"),
- MOCK_POST_FLAVOR_REQUEST,
+ self.MOCK_POST_RESOURCE_REQUEST,
HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
@@ -171,7 +184,6 @@ class TestFlavors(test_base.TestRequest):
self.assertIsNotNone(context['id'])
self.assertEqual(1, context['returnCode'])
-
@mock.patch.object(Flavors, '_get_flavor_extra_specs')
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
@@ -181,9 +193,9 @@ class TestFlavors(test_base.TestRequest):
mock_get_session.side_effect = [
test_base.get_mock_session(
["get", "post"], {
- "get": {"content": MOCK_GET_FLAVORS_RESPONSE},
+ "get": {"content": self.MOCK_GET_RESOURCES_RESPONSE},
"post": {
- "content": MOCK_POST_FLAVOR_RESPONSE,
+ "content": self.MOCK_POST_RESOURCE_RESPONSE,
"status_code": status.HTTP_202_ACCEPTED,
}
}),
@@ -197,7 +209,7 @@ class TestFlavors(test_base.TestRequest):
response = self.client.post(
("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/"
"fcca3cc49d5e42caae15459e27103efc/flavors"),
- MOCK_POST_FLAVOR_REQUEST_EXISTING,
+ self.MOCK_POST_RESOURCE_REQUEST_EXISTING,
HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
@@ -207,42 +219,13 @@ class TestFlavors(test_base.TestRequest):
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_empty_flavor(
- self, mock_get_vim_info,mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get", "post"],
- {
- "get": {"content": MOCK_GET_FLAVORS_RESPONSE},
- "post": {
- "content": MOCK_POST_FLAVOR_RESPONSE,
- "status_code": status.HTTP_202_ACCEPTED
- }
- })
- ]
- mock_extra_specs = mock.Mock(spec=test_base.MockResponse)
- mock_extra_specs.json.return_value = {"extra_specs": {}}
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- response = self.client.post(
- ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/"
- "fcca3cc49d5e42caae15459e27103efc/flavors"),
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertIn('error', context)
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR,
- response.status_code)
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
def test_delete_flavor(self, mock_get_vim_info, mock_get_session):
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
mock_get_session.side_effect = [
test_base.get_mock_session(
["get", "delete"],
{
- "get": { "content": MOCK_GET_EXTRA_SPECS },
+ "get": { "content": self.MOCK_GET_EXTRA_SPECS },
"delete": {"status_code": status.HTTP_204_NO_CONTENT }
}),
]
@@ -255,3 +238,22 @@ class TestFlavors(test_base.TestRequest):
self.assertEqual(status.HTTP_204_NO_CONTENT,
response.status_code)
self.assertIsNone(response.data)
+
+ # Overridden methods from test base to not make it run for current test case.
+ def test_get_resources_list(self):
+ pass
+
+ def test_get_resource_info(self):
+ pass
+
+ def test_get_resource_not_found(self):
+ pass
+
+ def test_post_resource(self):
+ pass
+
+ def test_post_resource_existing(self):
+ pass
+
+ def test_delete_resource(self):
+ pass
diff --git a/newton/newton/requests/tests/test_hosts.py b/newton/newton/requests/tests/test_hosts.py
index e78375b1..13e6b1fc 100644
--- a/newton/newton/requests/tests/test_hosts.py
+++ b/newton/newton/requests/tests/test_hosts.py
@@ -12,90 +12,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import mock
import unittest
-from django.test import Client
from rest_framework import status
-from newton.requests.tests import mock_info
-from newton.requests.tests import test_base
-from newton.requests.views.util import VimDriverUtils
+from newton.requests.tests.test_base import AbstractTestResource
-MOCK_GET_HOSTS_RESPONSE = {
- "hosts": [
- {"id": "uuid_1", "name": "host_1"},
- {"id": "uuid_2", "name": "host_2"}
- ]
-}
-
-MOCK_GET_HOST_RESPONSE = {
- "host": [
- {"resource": {"id": "uuid_1", "name": "host_1"}}
- ]
-}
-
-
-class TestHost(unittest.TestCase):
+class TestHostNewton(unittest.TestCase, AbstractTestResource):
def setUp(self):
- self.client = Client()
- def tearDown(self):
- pass
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_hosts_list(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_HOSTS_RESPONSE}}),
- ]
+ AbstractTestResource.__init__(self)
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
+ self.url += "hosts"
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/hosts",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.MOCK_GET_RESOURCES_RESPONSE = {
+ "hosts": [
+ {"id": "uuid_1", "name": "host_1"},
+ {"id": "uuid_2", "name": "host_2"}
+ ]
+ }
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['hosts'])
- self.assertEqual(MOCK_GET_HOSTS_RESPONSE["hosts"], context["hosts"])
+ self.MOCK_GET_RESOURCE_RESPONSE = {
+ "host": [
+ {"resource": {"id": "uuid_1", "name": "host_1"}}
+ ]
+ }
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_host_info(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_HOST_RESPONSE}}),
- ]
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
+ self.assert_keys = "hosts"
+ self.assert_key = "host"
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/hosts"
- "/uuid_1",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.HTTP_not_found = status.HTTP_500_INTERNAL_SERVER_ERROR
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertEquals(MOCK_GET_HOST_RESPONSE['host'], context['host'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_host_not_found(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": {},
- "status_code": 404}}),
- ]
+ # Overridden methods from test base to not make it run for current test case.
+ def test_post_resource(self):
+ pass
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
+ def test_post_resource_existing(self):
+ pass
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/hosts"
- "/uuid_3",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ def test_post_resource_empty(self):
+ pass
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
- self.assertIn('error', response.data)
+ def test_delete_resource(self):
+ pass
diff --git a/newton/newton/requests/tests/test_image.py b/newton/newton/requests/tests/test_image.py
index 1e747630..a290302e 100644
--- a/newton/newton/requests/tests/test_image.py
+++ b/newton/newton/requests/tests/test_image.py
@@ -16,7 +16,6 @@ import mock
import unittest
from six.moves import urllib
-from django.test import Client
from rest_framework import status
from newton.requests.tests import mock_info
@@ -29,11 +28,9 @@ from newton.requests.views.util import VimDriverUtils
class TestImageNewton(unittest.TestCase, AbstractTestResource):
def setUp(self):
- self.client = Client()
+ AbstractTestResource.__init__(self)
- self.openstack_version = "newton"
- self.region = "windriver-hudson-dc_RegionOne"
- self.resource_name = "images"
+ self.url += "images"
self.MOCK_GET_RESOURCES_RESPONSE = {
"images": [
@@ -49,6 +46,8 @@ class TestImageNewton(unittest.TestCase, AbstractTestResource):
}
}
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
+
self.MOCK_POST_RESOURCE_REQUEST = {
"id": "uuid_3",
"name": "image_3",
diff --git a/newton/newton/requests/tests/test_limits.py b/newton/newton/requests/tests/test_limits.py
index 053a44a0..d37e7e6d 100644
--- a/newton/newton/requests/tests/test_limits.py
+++ b/newton/newton/requests/tests/test_limits.py
@@ -20,28 +20,29 @@ from rest_framework import status
from newton.requests.tests import mock_info
from newton.requests.tests import test_base
+from newton.requests.tests.test_base import AbstractTestResource
from newton.requests.views.util import VimDriverUtils
-MOCK_GET_LIMITS_RESPONSE = {
- "limits": {
- "absolute": {
- "id": "uuid_1", "name": "limit_1"
- }
- }
-}
-
-MOCK_GET_QUOTAS_RESPONSE = {
- "quota": {"limit": "1"}
-}
-
-
-class TestLimit(unittest.TestCase):
+class TestLimitNewton(unittest.TestCase, AbstractTestResource):
def setUp(self):
self.client = Client()
- def tearDown(self):
- pass
+ self.openstack_version = "newton"
+ self.region = "windriver-hudson-dc_RegionOne"
+ self.resource_name = "limits"
+
+ self.MOCK_GET_LIMITS_RESPONSE = {
+ "limits": {
+ "absolute": {
+ "id": "uuid_1", "name": "limit_1"
+ }
+ }
+ }
+
+ self.MOCK_GET_QUOTAS_RESPONSE = {
+ "quota": {"limit": "1"}
+ }
@staticmethod
def _get_mock_response(return_value=None):
@@ -57,9 +58,9 @@ class TestLimit(unittest.TestCase):
mock_get_session.return_value = test_base.get_mock_session(
["get"], {
"side_effect": [
- self._get_mock_response(MOCK_GET_LIMITS_RESPONSE),
- self._get_mock_response(MOCK_GET_QUOTAS_RESPONSE),
- self._get_mock_response(MOCK_GET_LIMITS_RESPONSE)
+ self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE),
+ self._get_mock_response(self.MOCK_GET_QUOTAS_RESPONSE),
+ self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE)
]
})
@@ -73,7 +74,7 @@ class TestLimit(unittest.TestCase):
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertIsNotNone(context)
self.assertIn(
- MOCK_GET_LIMITS_RESPONSE["limits"]["absolute"]['id'], context['id'])
+ self.MOCK_GET_LIMITS_RESPONSE["limits"]["absolute"]['id'], context['id'])
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
@@ -82,9 +83,9 @@ class TestLimit(unittest.TestCase):
mock_get_session.return_value = test_base.get_mock_session(
["get"], {
"side_effect": [
- self._get_mock_response(MOCK_GET_LIMITS_RESPONSE),
+ self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE),
self._get_mock_response({}),
- self._get_mock_response(MOCK_GET_LIMITS_RESPONSE)
+ self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE)
]
})
@@ -97,3 +98,24 @@ class TestLimit(unittest.TestCase):
context = response.json()
self.assertIn('error', context)
self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+
+ def test_get_resources_list(self):
+ pass
+
+ def test_get_resource_info(self):
+ pass
+
+ def test_get_resource_not_found(self):
+ pass
+
+ def test_post_resource(self):
+ pass
+
+ def test_post_resource_existing(self):
+ pass
+
+ def test_post_resource_empty(self):
+ pass
+
+ def test_delete_resource(self):
+ pass
diff --git a/newton/newton/requests/tests/test_network.py b/newton/newton/requests/tests/test_network.py
index 448c098b..353c7fa3 100644
--- a/newton/newton/requests/tests/test_network.py
+++ b/newton/newton/requests/tests/test_network.py
@@ -12,197 +12,50 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import mock
import unittest
-from django.test import Client
from rest_framework import status
-from newton.requests.views.util import VimDriverUtils
-from newton.requests.tests import mock_info
-from newton.requests.tests import test_base
+from newton.requests.tests.test_base import AbstractTestResource
-MOCK_GET_NETWORKS_RESPONSE = {
- "networks": [
- {"name": "network_1"},
- {"name": "network_2"}
- ]
-}
+class TestNetworkNewton(unittest.TestCase, AbstractTestResource):
+ def setUp(self):
+ AbstractTestResource.__init__(self)
-MOCK_GET_NETWORK_RESPONSE = {
- "network": {
- "network_id": "f5dc173b-6804-445a-a6d8-c705dad5b5eb",
- "name": "network_3"
- }
-}
+ self.url += "networks"
-MOCK_POST_NETWORK_REQUEST = {
- "name": "network_3"
-}
+ self.MOCK_GET_RESOURCES_RESPONSE = {
+ "networks": [
+ {"name": "network_1"},
+ {"name": "network_2"}
+ ]
+ }
-MOCK_POST_NETWORK_REQUEST_EXISTING = {
- "name": "network_1"
-}
+ self.MOCK_GET_RESOURCE_RESPONSE = {
+ "network": {
+ "id": "f5dc173b-6804-445a-a6d8-c705dad5b5eb",
+ "name": "network_3"
+ }
+ }
-MOCK_POST_NETWORK_RESPONSE = {
- "network": {
- "network_id": "f5dc173b-6804-445a-a6d8-c705dad5b5eb"
- }
-}
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
+ self.MOCK_POST_RESOURCE_REQUEST = {
+ "name": "network_3"
+ }
-class TestNetwork(unittest.TestCase):
- def setUp(self):
- self.client = Client()
+ self.MOCK_POST_RESOURCE_REQUEST_EXISTING = {
+ "name": "network_1"
+ }
- def tearDown(self):
- pass
+ self.MOCK_POST_RESOURCE_RESPONSE = {
+ "network": {
+ "id": "f5dc173b-6804-445a-a6d8-c705dad5b5eb"
+ }
+ }
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_networks(self, mock_get_vim_info, mock_get_session):
+ self.assert_keys = "networks"
+ self.assert_key = "id"
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_NETWORKS_RESPONSE}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/networks",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['networks'])
- self.assertEqual(MOCK_GET_NETWORKS_RESPONSE["networks"], context['networks'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_network(self, mock_get_vim_info, mock_get_session):
-
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_NETWORK_RESPONSE}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc"
- "/networks/f5dc173b-6804-445a-a6d8-c705dad5b5eb",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertEquals(MOCK_GET_NETWORK_RESPONSE['network_id'], context['network_id'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_network_not_found(self, mock_get_vim_info, mock_get_session):
-
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": {},
- "status_code": 404}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc"
- "/networks/f5dc173b-6804-445a-a6d8-c705dad5b5eb",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- # TODO(sshank): 404 status is not possible.
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
- self.assertIn('error', response.data)
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_post(self, mock_get_vim_info, mock_get_session):
-
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_NETWORKS_RESPONSE}}),
- test_base.get_mock_session(
- ["post"], {"post": {"content": MOCK_POST_NETWORK_RESPONSE,
- "status_code": 202}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.post(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/networks",
- MOCK_POST_NETWORK_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code)
- self.assertIsNotNone(context['network_id'])
- self.assertEqual(1, context['returnCode'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_post_existing(self, mock_get_vim_info, mock_get_session):
-
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_NETWORKS_RESPONSE}}),
- test_base.get_mock_session(
- ["post"], {"post": {"content": MOCK_POST_NETWORK_RESPONSE,
- "status_code": 202}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.post(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/networks",
- MOCK_POST_NETWORK_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['returnCode'])
- self.assertEqual(0, context['returnCode'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_post_empty_body(self, mock_get_vim_info, mock_get_session):
-
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"], {"get": {"content": MOCK_GET_NETWORKS_RESPONSE}}),
- test_base.get_mock_session(
- ["post"], {"post": {"content": MOCK_POST_NETWORK_RESPONSE,
- "status_code": 202}}),
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.post(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/networks",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertIn('error', context)
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_delete(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["delete"], {"delete": {"content": {},
- "status_code": 204}})
- ]
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.delete(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc"
- "/networks/f5dc173b-6804-445a-a6d8-c705dad5b5eb",
- HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
- self.assertIsNone(response.data)
+ self.HTTP_not_found = status.HTTP_500_INTERNAL_SERVER_ERROR
diff --git a/newton/newton/requests/tests/test_subnet.py b/newton/newton/requests/tests/test_subnet.py
index e4b2805e..653df33d 100644
--- a/newton/newton/requests/tests/test_subnet.py
+++ b/newton/newton/requests/tests/test_subnet.py
@@ -15,75 +15,59 @@
import mock
import unittest
-from django.test import Client
from rest_framework import status
from newton.requests.tests import test_base
from newton.requests.tests import mock_info
+from newton.requests.tests.test_base import AbstractTestResource
from newton.requests.views.util import VimDriverUtils
-MOCK_GET_SUBNETS_RESPONSE = {
- "subnets": [
- {"id": "uuid_1", "name": "subnet_1"},
- {"id": "uuid_2", "name": "subnet_2"}
- ]
-}
-
-MOCK_GET_SUBNET_RESPONSE = {
- "subnet": {
- "id": "uuid_1",
- "name": "subnet_1"
- }
-}
-
-MOCK_GET_SUBNET_RESPONSE_NOT_FOUND = {
- "subnet": {}
-}
-
-MOCK_POST_SUBNET_REQUEST = {
- "id": "uuid_3",
- "name": "subnet_3",
-}
-
-MOCK_POST_SUBNET_REQUEST_EXISTING = {
- "id": "uuid_1",
- "name": "subnet_1",
-}
-
-MOCK_POST_SUBNET_RESPONSE = {
- "subnet": {
- "id": "uuid_3",
- "name": "subnet_3"
- }
-}
-
-
-class TestSubnet(unittest.TestCase):
+class TestSubnetNewton(unittest.TestCase, AbstractTestResource):
def setUp(self):
- self.client = Client()
-
- def tearDown(self):
- pass
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_subnets(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_SUBNETS_RESPONSE}})
- ]
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['subnets'])
- self.assertEqual(MOCK_GET_SUBNETS_RESPONSE["subnets"], context["subnets"])
+ AbstractTestResource.__init__(self)
+
+ self.url += "subnets"
+
+ self.MOCK_GET_RESOURCES_RESPONSE = {
+ "subnets": [
+ {"id": "uuid_1", "name": "subnet_1"},
+ {"id": "uuid_2", "name": "subnet_2"}
+ ]
+ }
+
+ self.MOCK_GET_RESOURCE_RESPONSE = {
+ "subnet": {
+ "id": "uuid_1",
+ "name": "subnet_1"
+ }
+ }
+
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {
+ "subnet": {}
+ }
+
+ self.MOCK_POST_RESOURCE_REQUEST = {
+ "id": "uuid_3",
+ "name": "subnet_3"
+ }
+
+ self.MOCK_POST_RESOURCE_REQUEST_EXISTING = {
+ "id": "uuid_1",
+ "name": "subnet_1"
+ }
+
+ self.MOCK_POST_RESOURCE_RESPONSE = {
+ "subnet": {
+ "id": "uuid_3",
+ "name": "subnet_3"
+ }
+ }
+
+ self.assert_keys = "subnets"
+ self.assert_key = "subnet"
+
+ self.HTTP_not_found = status.HTTP_404_NOT_FOUND
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
@@ -91,7 +75,7 @@ class TestSubnet(unittest.TestCase):
mock_get_session.side_effect = [
test_base.get_mock_session(
["get"],
- {"get": {"content": MOCK_GET_SUBNET_RESPONSE}})
+ {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}})
]
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
@@ -102,87 +86,8 @@ class TestSubnet(unittest.TestCase):
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertEqual(MOCK_GET_SUBNET_RESPONSE["id"], context["id"])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_subnet_not_found(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_SUBNET_RESPONSE_NOT_FOUND,
- "status_code": 404}}),
- ]
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.get(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets"
- "/uuid_3",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_404_NOT_FOUND, response.status_code)
- self.assertIsNone(context.get("subnet"))
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_subnet_success(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_SUBNETS_RESPONSE}}),
- test_base.get_mock_session(
- ["post"],
- {"post": {"content": MOCK_POST_SUBNET_RESPONSE,
- "status_code": 201}})
- ]
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.post(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets",
- MOCK_POST_SUBNET_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
- context = response.json()
-
- self.assertEquals(status.HTTP_201_CREATED, response.status_code)
- self.assertEqual(MOCK_POST_SUBNET_RESPONSE["subnet"], context)
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_subnet_fail_existing(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_SUBNETS_RESPONSE}}),
- test_base.get_mock_session(
- ["post"],
- {"post": {"content": MOCK_POST_SUBNET_RESPONSE,
- "status_code": 404}})
- ]
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.post(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets",
- MOCK_POST_SUBNET_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
- context = response.json()
-
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['returnCode'])
- self.assertEqual(0, context['returnCode'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_delete_subnet_success(self, mock_get_vim_info, mock_get_session):
- mock_get_session.side_effect = [
- test_base.get_mock_session(
- ["delete"],
- {"delete": {"content": None,
- "status_code": 204}})
- ]
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
-
- response = self.client.delete(
- "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets"
- "/uuid_1", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], context["id"])
- self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
- self.assertIsNone(response.data)
+ # Overridden method from test base to not make it run for current test case.
+ def test_get_resource_info(self):
+ pass
diff --git a/newton/newton/requests/tests/test_volume.py b/newton/newton/requests/tests/test_volume.py
index 8281e23d..fb58d240 100644
--- a/newton/newton/requests/tests/test_volume.py
+++ b/newton/newton/requests/tests/test_volume.py
@@ -15,174 +15,76 @@
import mock
import unittest
-from django.test import Client
from rest_framework import status
from newton.requests.tests import mock_info
from newton.requests.tests import test_base
+from newton.requests.tests.test_base import AbstractTestResource
from newton.requests.views.util import VimDriverUtils
-from newton.requests.views.volume import Volumes
-
-MOCK_GET_VOLUMES_RESPONSE = {
- "volumes": [
- {"id": "uuid_1", "name": "volume_1"},
- {"id": "uuid_2", "name": "volume_2"}
- ]
-}
-
-MOCK_GET_VOLUME_RESPONSE = {
- "volume": {
- "id": "uuid_1",
- "name": "volume_1"
- }
-}
-
-MOCK_POST_VOLUME_REQUEST = {
- "id": "uuid_3",
- "name": "volume_3"
-}
-
-MOCK_POST_VOLUME_REQUEST_EXISTING = {
- "id": "uuid_1",
- "name": "volume_1"
-}
-
-MOCK_POST_VOLUME_RESPONSE = {
- "volume": {
- "id": "uuid_3",
- "name": "volume_3"
- }
-}
-
-class TestVolumes(test_base.TestRequest):
-
- url = ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/"
- "fcca3cc49d5e42caae15459e27103efc/")
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_volumes(self, mock_get_vim_info, mock_get_session):
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_VOLUMES_RESPONSE}})
- response = self.client.get(
- self.url + "volumes",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+class TestVolumesNewton(unittest.TestCase, AbstractTestResource):
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['volumes'])
- self.assertEqual(MOCK_GET_VOLUMES_RESPONSE["volumes"], context['volumes'])
+ def setUp(self):
+ AbstractTestResource.__init__(self)
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_volume(self, mock_get_vim_info, mock_get_session):
+ self.url += "volumes"
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["get"],
- {"get": {"content": MOCK_GET_VOLUME_RESPONSE}})
-
- response = self.client.get(
- self.url + "volumes/uuid_1",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertEquals(MOCK_GET_VOLUME_RESPONSE['id'], context['id'])
+ self.MOCK_GET_RESOURCES_RESPONSE = {
+ "volumes": [
+ {"id": "uuid_1", "name": "volume_1"},
+ {"id": "uuid_2", "name": "volume_2"}
+ ]
+ }
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_get_volume_not_found(self, mock_get_vim_info, mock_get_session):
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["get"],
- {"get": {"content": None, "status_code": 404}})
+ self.MOCK_GET_RESOURCE_RESPONSE = {
+ "volume": {
+ "id": "uuid_1",
+ "name": "volume_1"
+ }
+ }
- response = self.client.get(
- self.url + "volumes/uuid_3",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND = {}
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
- self.assertIn('error', response.data)
+ self.MOCK_POST_RESOURCE_REQUEST = {
+ "id": "uuid_3",
+ "name": "volume_3"
+ }
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_volume_successfully(self, mock_get_vim_info, mock_get_session):
+ self.MOCK_POST_RESOURCE_REQUEST_EXISTING = {
+ "id": "uuid_1",
+ "name": "volume_1"
+ }
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["get", "post"],
- {
- "get" : {"content": MOCK_GET_VOLUMES_RESPONSE},
- "post": {"content": MOCK_POST_VOLUME_RESPONSE, "status_code": 202}
- })
+ self.MOCK_POST_RESOURCE_RESPONSE = {
+ "volume": {
+ "id": "uuid_3",
+ "name": "volume_3"
+ }
+ }
- response = self.client.post(
- self.url + "volumes",
- MOCK_POST_VOLUME_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.assert_keys = "volumes"
+ self.assert_key = "volume"
- context = response.json()
- self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code)
- self.assertIsNotNone(context['id'])
- self.assertEqual(1, context['returnCode'])
+ self.HTTP_not_found = status.HTTP_500_INTERNAL_SERVER_ERROR
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_existing_volume(self, mock_get_vim_info, mock_get_session):
+ def test_get_volume(self, mock_get_vim_info, mock_get_session):
mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
mock_get_session.return_value = test_base.get_mock_session(
- ["get", "post"],
- {
- "get" : {"content": MOCK_GET_VOLUMES_RESPONSE},
- "post": {"content": MOCK_POST_VOLUME_RESPONSE, "status_code": 202}
- })
+ ["get"],
+ {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}})
- response = self.client.post(
- self.url + "volumes",
- MOCK_POST_VOLUME_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ response = self.client.get(
+ "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/"
+ "volumes/uuid_1", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
context = response.json()
self.assertEquals(status.HTTP_200_OK, response.status_code)
- self.assertIsNotNone(context['returnCode'])
- self.assertEqual(0, context['returnCode'])
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_create_volume_unsuccessfully(self, mock_get_vim_info, mock_get_session):
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["get", "post"],
- {
- "get" : {"content": MOCK_GET_VOLUMES_RESPONSE},
- "post": {"content": MOCK_POST_VOLUME_RESPONSE, "status_code": 202}
- })
-
- response = self.client.post(
- self.url + "volumes",
- {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
-
- context = response.json()
- self.assertIn('error', context)
- self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
-
- @mock.patch.object(VimDriverUtils, 'get_session')
- @mock.patch.object(VimDriverUtils, 'get_vim_info')
- def test_delete_volume(self, mock_get_vim_info, mock_get_session):
-
- mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO
- mock_get_session.return_value = test_base.get_mock_session(
- ["delete"],
- {"delete" : {"content": None, "status_code": 204}})
-
- response = self.client.delete(
- self.url + "volumes/uuid_1",
- HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.assertEquals(self.MOCK_GET_RESOURCE_RESPONSE['id'], context['id'])
- self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
- self.assertIsNone(response.data)
+ # Overridden method from test base to not make it run for current test case.
+ def test_get_resource_info(self):
+ pass
diff --git a/newton/newton/requests/views/util.py b/newton/newton/requests/views/util.py
index 59eed5ab..ba383475 100644
--- a/newton/newton/requests/views/util.py
+++ b/newton/newton/requests/views/util.py
@@ -68,7 +68,8 @@ class VimDriverUtils(object):
password=vim["password"],
user_domain_name=vim["domain"],
project_id=tenantid)
- elif '/identity' in vim["url"]:
+ #elif '/identity' in vim["url"]:
+ else:
auth = keystone_v3.Password(auth_url=vim["url"]+"/v3",
username=vim["userName"],
password=vim["password"],
@@ -87,7 +88,8 @@ class VimDriverUtils(object):
project_name=tenant_name,
user_domain_name=vim["domain"],
project_domain_name=vim["domain"])
- elif '/identity' in vim["url"]:
+ #elif '/identity' in vim["url"]:
+ else:
auth = keystone_v3.Password(auth_url=vim["url"]+"/v3",
username=vim["userName"],
password=vim["password"],