summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorZiad Sawalha <github@highbridgellc.com>2011-05-23 19:10:07 -0500
committerZiad Sawalha <github@highbridgellc.com>2011-05-23 19:10:07 -0500
commit5a7d10b93b74896942fd63df9c09765efec5a700 (patch)
tree567e51ccd915af0cc637dc85a1623db061371e06 /test
parent5cb71ca44d71417a7970d5b2a6bd9c2d2d09b69e (diff)
parent15f3c818ff4c131fa2cb1075850657cf95f3223d (diff)
Merge branch 'master' of https://github.com/khussein/keystone
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_common.py28
-rw-r--r--test/unit/test_roles.py166
2 files changed, 194 insertions, 0 deletions
diff --git a/test/unit/test_common.py b/test/unit/test_common.py
index 800f1a7c..2dc6e193 100644
--- a/test/unit/test_common.py
+++ b/test/unit/test_common.py
@@ -704,3 +704,31 @@ def handle_user_resp(self, content, respvalue, resptype):
self.fail('Identity Fault')
elif respvalue == 503:
self.fail('Service Not Available')
+
+def create_role(roleid, auth_token):
+ header = httplib2.Http(".cache")
+
+ url = '%sroles' % (URL)
+ body = {"role": {"id": roleid,
+ "description": "A description ..."}}
+ resp, content = header.request(url, "POST", body=json.dumps(body),
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": auth_token})
+ return (resp, content)
+
+def create_role_xml(role_id, auth_token):
+ header = httplib2.Http(".cache")
+ url = '%sroles' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?>\
+ <role xmlns="http://docs.openstack.org/identity/api/v2.0" \
+ id="%s" description="A Description of the group"/>\
+ ' % role_id
+ print "Role XML Body is :" ,body
+ resp, content = header.request(url, "POST", body=body,
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": auth_token,
+ "ACCEPT": "application/xml"})
+ return (resp, content)
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file
diff --git a/test/unit/test_roles.py b/test/unit/test_roles.py
new file mode 100644
index 00000000..37021440
--- /dev/null
+++ b/test/unit/test_roles.py
@@ -0,0 +1,166 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# Copyright (c) 2010-2011 OpenStack, LLC.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import httplib2
+import json
+from lxml import etree
+import os
+import sys
+sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__),
+ '..', '..', '..', '..', 'keystone')))
+import unittest
+
+import test_common as utils
+from test_common import URL
+
+class RolesTest(unittest.TestCase):
+ def setUp(self):
+ self.tenant = utils.get_tenant()
+ self.password = utils.get_password()
+ self.email = utils.get_email()
+ self.user = utils.get_user()
+ self.userdisabled = utils.get_userdisabled()
+ self.auth_token = utils.get_auth_token()
+ self.exp_auth_token = utils.get_exp_auth_token()
+ self.disabled_token = utils.get_disabled_token()
+ self.missing_token = utils.get_none_token()
+ self.invalid_token = utils.get_non_existing_token()
+ utils.create_tenant(self.tenant, str(self.auth_token))
+ utils.add_user_json(self.tenant, self.user, self.auth_token)
+ self.token = utils.get_token(self.user, 'secrete', self.tenant,
+ 'token')
+
+ def tearDown(self):
+ utils.delete_user(self.tenant, self.user, self.auth_token)
+ utils.delete_tenant(self.tenant, self.auth_token)
+
+class GetRolesTest(RolesTest):
+ def test_get_roles(self):
+ header = httplib2.Http(".cache")
+ url = '%sroles' % (utils.URL)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='{}',
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
+ def test_get_roles_xml(self):
+ header = httplib2.Http(".cache")
+ url = '%sroles' % (utils.URL)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='',
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
+ def test_get_roles_exp_token(self):
+ header = httplib2.Http(".cache")
+ url = '%sroles' % (utils.URL)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='{}',
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": self.exp_auth_token})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
+
+ def test_get_roles_exp_token_xml(self):
+ header = httplib2.Http(".cache")
+ url = '%stenants' % (utils.URL)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='',
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": self.exp_auth_token,
+ "ACCEPT": "application/xml"})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
+
+class GetRoleTest(RolesTest):
+
+ def test_get_role(self):
+ self.role = 'Admin'
+ header = httplib2.Http(".cache")
+ url = '%sroles/%s' % (utils.URL, self.role)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='{}',
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
+ def test_get_role_xml(self):
+ self.role = 'Admin'
+ header = httplib2.Http(".cache")
+ url = '%sroles/%s' % (utils.URL, self.role)
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='',
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
+ def test_get_role_bad(self):
+ header = httplib2.Http(".cache")
+ url = '%sroles/%s' % (utils.URL, 'tenant_bad')
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='',
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+
+ def test_get_role_bad_xml(self):
+ header = httplib2.Http(".cache")
+ resp, content = utils.create_tenant(self.tenant, str(self.auth_token))
+ url = '%sroles/%s' % (utils.URL, 'role_bad')
+ #test for Content-Type = application/json
+ resp, content = header.request(url, "GET", body='',
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
+ if int(resp['status']) == 500:
+ self.fail('Identity Fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+
+if __name__ == '__main__':
+ unittest.main()