Merge "Resolve identifiers when linking objects"
This commit is contained in:
@@ -28,6 +28,66 @@ from ooi.tests import fakes
|
||||
import webob.exc
|
||||
|
||||
|
||||
class TestIDGetter(base.TestCase):
|
||||
def test_resolve_id_relative_url(self):
|
||||
res_url = uuid.uuid4().hex
|
||||
base_url = "http://foobar.com/foo"
|
||||
r = helpers._resolve_id(base_url, res_url)
|
||||
self.assertEqual(base_url, r[0])
|
||||
self.assertEqual(res_url, r[1])
|
||||
|
||||
def test_resolve_id_absolute(self):
|
||||
res_id = uuid.uuid4().hex
|
||||
res_url = "/%s" % res_id
|
||||
base_url = "http://foobar.com/foo"
|
||||
r = helpers._resolve_id(base_url, res_url)
|
||||
self.assertEqual("http://foobar.com/", r[0])
|
||||
self.assertEqual(res_id, r[1])
|
||||
|
||||
def test_resolve_id_no_resource_url(self):
|
||||
base_url = "http://foobar.com/foo"
|
||||
r = helpers._resolve_id(base_url, "")
|
||||
self.assertEqual(base_url, r[0])
|
||||
self.assertEqual("", r[1])
|
||||
|
||||
def test_get_id_no_kind_relative(self):
|
||||
req_url = '/foo'
|
||||
req = webob.Request.blank(req_url)
|
||||
res_url = "%s" % uuid.uuid4().hex
|
||||
r = helpers.get_id_with_kind(req, res_url)
|
||||
self.assertEqual('%s%s' % (req.application_url, req_url), r[0])
|
||||
self.assertEqual(res_url, r[1])
|
||||
|
||||
def test_get_id_no_kind_absolute(self):
|
||||
req_url = '/foo'
|
||||
req = webob.Request.blank(req_url)
|
||||
res_id = uuid.uuid4().hex
|
||||
res_url = "/bar/%s" % res_id
|
||||
r = helpers.get_id_with_kind(req, res_url)
|
||||
self.assertEqual('%s/bar' % (req.application_url), r[0])
|
||||
self.assertEqual(res_id, r[1])
|
||||
|
||||
def test_get_id_kind_matching(self):
|
||||
m = mock.MagicMock()
|
||||
m.location = "foo/"
|
||||
req_url = "/foo"
|
||||
req = webob.Request.blank(req_url)
|
||||
res_url = "%s" % uuid.uuid4().hex
|
||||
r = helpers.get_id_with_kind(req, res_url, m)
|
||||
self.assertEqual("%s%s" % (req.application_url, req_url), r[0])
|
||||
self.assertEqual(res_url, r[1])
|
||||
|
||||
def test_get_id_kind_not_matching(self):
|
||||
m = mock.MagicMock()
|
||||
m.location = "foo/"
|
||||
req_url = "/foo"
|
||||
req = webob.Request.blank(req_url)
|
||||
from ooi import exception
|
||||
self.assertRaises(exception.Invalid,
|
||||
helpers.get_id_with_kind,
|
||||
req, "/bar/baz", m)
|
||||
|
||||
|
||||
class TestExceptionHelper(base.TestCase):
|
||||
@staticmethod
|
||||
def get_fault(code):
|
||||
|
||||
@@ -121,7 +121,8 @@ class TestStorageLinkController(base.TestController):
|
||||
|
||||
@mock.patch.object(helpers.OpenStackHelper, "create_server_volumes_link")
|
||||
@mock.patch("ooi.occi.validator.Validator")
|
||||
def test_create_link(self, m_validator, m_create):
|
||||
@mock.patch("ooi.api.helpers.get_id_with_kind")
|
||||
def test_create_link(self, m_get_id, m_validator, m_create):
|
||||
tenant = fakes.tenants["foo"]
|
||||
req = self._build_req(tenant["id"])
|
||||
vol_id = uuid.uuid4().hex
|
||||
@@ -138,6 +139,7 @@ class TestStorageLinkController(base.TestController):
|
||||
# NOTE(aloga): MOG!
|
||||
req.get_parser.return_value.return_value.parse.return_value = obj
|
||||
m_validator.validate.return_value = True
|
||||
m_get_id.side_effect = [('', vol_id), ('', server_id)]
|
||||
attachment = {
|
||||
"device": "/dev/vdd",
|
||||
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
|
||||
|
||||
@@ -134,7 +134,11 @@ class TestStorageLinkController(test_middleware.TestMiddleware):
|
||||
tenant = fakes.tenants["foo"]
|
||||
|
||||
server_id = fakes.servers[tenant["id"]][0]["id"]
|
||||
server_url = utils.join_url(self.application_url + "/",
|
||||
"compute/%s" % server_id)
|
||||
vol_id = fakes.volumes[tenant["id"]][0]["id"]
|
||||
vol_url = utils.join_url(self.application_url + "/",
|
||||
"storage/%s" % vol_id)
|
||||
|
||||
app = self.get_app()
|
||||
headers = {
|
||||
@@ -145,7 +149,7 @@ class TestStorageLinkController(test_middleware.TestMiddleware):
|
||||
'X-OCCI-Attribute': (
|
||||
'occi.core.source="%s", '
|
||||
'occi.core.target="%s"'
|
||||
) % (server_id, vol_id)
|
||||
) % (server_url, vol_url)
|
||||
}
|
||||
req = self._build_req("/storagelink", tenant["id"], method="POST",
|
||||
headers=headers)
|
||||
@@ -163,7 +167,11 @@ class TestStorageLinkController(test_middleware.TestMiddleware):
|
||||
tenant = fakes.tenants["foo"]
|
||||
|
||||
server_id = fakes.servers[tenant["id"]][0]["id"]
|
||||
server_url = utils.join_url(self.application_url + "/",
|
||||
"compute/%s" % server_id)
|
||||
vol_id = fakes.volumes[tenant["id"]][0]["id"]
|
||||
vol_url = utils.join_url(self.application_url + "/",
|
||||
"storage/%s" % vol_id)
|
||||
|
||||
app = self.get_app()
|
||||
headers = {
|
||||
@@ -175,7 +183,7 @@ class TestStorageLinkController(test_middleware.TestMiddleware):
|
||||
'occi.storagelink.deviceid="/dev/vdc", '
|
||||
'occi.core.source="%s", '
|
||||
'occi.core.target="%s"'
|
||||
) % (server_id, vol_id)
|
||||
) % (server_url, vol_url)
|
||||
}
|
||||
req = self._build_req("/storagelink", tenant["id"], method="POST",
|
||||
headers=headers)
|
||||
|
||||
Reference in New Issue
Block a user