Fix tests for query interface.

This commit is contained in:
Enol Fernandez 2015-03-30 16:12:53 +00:00
parent c8e2db13dc
commit d599ced867
3 changed files with 78 additions and 1 deletions

View File

@ -85,6 +85,22 @@ servers = {
def fake_query_results():
cats = []
cats.append(
'compute; '
'scheme="http://schemas.ogf.org/occi/infrastructure"; '
'class="kind"')
cats.append(
'link; '
'scheme="http://schemas.ogf.org/occi/core"; '
'class="kind"')
cats.append(
'resource; '
'scheme="http://schemas.ogf.org/occi/core"; '
'class="kind"')
cats.append(
'entity; '
'scheme="http://schemas.ogf.org/occi/core"; '
'class="kind"')
cats.append(
'start; '
'scheme="http://schemas.ogf.org/occi/infrastructure/compute/action"; '
@ -101,6 +117,38 @@ def fake_query_results():
'suspend; '
'scheme="http://schemas.ogf.org/occi/infrastructure/compute/action"; '
'class="action"')
cats.append(
'bar; '
'scheme="http://schemas.openstack.org/template/os"; '
'class="mixin"')
cats.append(
'bar; '
'scheme="http://schemas.openstack.org/template/resource"; '
'class="mixin"')
cats.append(
'foo; '
'scheme="http://schemas.openstack.org/template/os"; '
'class="mixin"')
cats.append(
'foo; '
'scheme="http://schemas.openstack.org/template/resource"; '
'class="mixin"')
cats.append(
'os_tpl; '
'scheme="http://schemas.ogf.org/occi/infrastructure"; '
'class="mixin"')
cats.append(
'resource_tpl; '
'scheme="http://schemas.ogf.org/occi/infrastructure"; '
'class="mixin"')
cats.append(
'user_data; '
'scheme="http://schemas.openstack.org/compute/instance"; '
'class="mixin"')
cats.append(
'public_key; '
'scheme="http://schemas.openstack.org/instance/credentials"; '
'class="mixin"')
result = []
for c in cats:
@ -125,7 +173,10 @@ class FakeApp(object):
def _populate(self, path_base, obj_name, obj_list):
objs_name = "%ss" % obj_name
objs_path = "%s/%s" % (path_base, objs_name)
objs_details_path = "%s/%s/detail" % (path_base, objs_name)
self.routes[objs_path] = create_fake_json_resp({objs_name: obj_list})
self.routes[objs_details_path] = create_fake_json_resp(
{objs_name: obj_list})
for o in obj_list:
obj_path = "%s/%s" % (objs_path, o["id"])

View File

@ -23,7 +23,8 @@ class TestQueryController(test_middleware.TestMiddleware):
"""Test OCCI query controller."""
def test_query(self):
result = self._build_req("/-/", "tenant").get_response(self.get_app())
tenant_id = fakes.tenants["bar"]["id"]
result = self._build_req("/-/", tenant_id).get_response(self.get_app())
self.assertContentType(result)
self.assertExpectedResult(fakes.fake_query_results(), result)
self.assertEqual(200, result.status_code)

View File

@ -18,6 +18,7 @@ import uuid
from ooi.occi.infrastructure import templates as occi_templates
from ooi.openstack import helpers
from ooi.openstack import mixins
from ooi.openstack import templates
from ooi.tests import base
@ -69,3 +70,27 @@ class TestHelpers(base.TestCase):
self.assertEqual("suspended", helpers.occi_state("SUSPENDED"))
self.assertEqual("suspended", helpers.occi_state("STOPPED"))
self.assertEqual("inactive", helpers.occi_state("BUILDING"))
class TestOpenStackUserData(base.TestCase):
def test_os_userdata(self):
user_data = "foobar"
mxn = mixins.OpenStackUserData(user_data)
self.assertEqual("user_data", mxn.term)
self.assertTrue(mxn.scheme.startswith(helpers._PREFIX))
self.assertEqual(user_data, mxn.user_data)
class TestOpenStackPublicKey(base.TestCase):
def test_os_userdata(self):
key_name = "foobar"
key_data = "1234"
mxn = mixins.OpenStackPublicKey(key_name, key_data)
self.assertEqual("public_key", mxn.term)
self.assertTrue(mxn.scheme.startswith(helpers._PREFIX))
self.assertEqual(key_name, mxn.name)
self.assertEqual(key_data, mxn.data)