From 42f63b91a7387c6f884386dd7899c376898867af Mon Sep 17 00:00:00 2001 From: Yogeshwar Srikrishnan Date: Mon, 23 May 2011 17:52:53 -0500 Subject: Changes to support /Roles calls --- test/IdentitySOAPUI.xml | 12 +-- test/unit/test_common.py | 28 +++++++ test/unit/test_roles.py | 200 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 6 deletions(-) create mode 100644 test/unit/test_roles.py (limited to 'test') diff --git a/test/IdentitySOAPUI.xml b/test/IdentitySOAPUI.xml index d5832df8..dd7795e4 100644 --- a/test/IdentitySOAPUI.xml +++ b/test/IdentitySOAPUI.xml @@ -1,5 +1,5 @@ - + @@ -1264,7 +1264,7 @@ ns1:Response/ns1:tenant/ns1:id = "JGroup65" and ns1:Response/ns1:tenant/ns1:desc } }400falsefalsebadRequestfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; count(//ns1:tenant)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0/tenants'; -count(//ns1:e)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; +count(//ns1:e)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; ns1:tenant/@id1234falsefalsedeclare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; /ns1:tenant/@enabled and /ns1:tenant/ns1:descriptiontruefalsefalse @@ -1281,15 +1281,15 @@ ns1:Response/ns1:tenant/ns1:id1234fals xmlns:v1="http://docs.openstack.org/identity/api/v2.0"> <v1:description>To Be Deleted</v1:description> </v1:tenant>declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; -/ns1:tenant/@enabled = "true" and /ns1:tenant/@id="to_delete" and /ns1:tenant/ns1:description = "To Be Deleted"truefalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; +/ns1:tenant/@enabled = "true" and /ns1:tenant/@id="to_delete" and /ns1:tenant/ns1:description = "To Be Deleted"truefalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; ns1:tenant/@idto_deletefalsefalsedeclare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; /ns1:tenant/@enabled and /ns1:tenant/ns1:descriptiontruefalsefalse -<entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080assert(context.response == null) +<entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080assert(context.response == null) -<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse +<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse <entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080forbiddenfalsefalse403falsefalse @@ -1350,6 +1350,6 @@ ns1:tenant/@idto_deletefalse <xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; count(/ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0/extensions'; -count(//ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; +count(//ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; count(//ns1:version)1falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0'; count(//ns1:version)1falsefalse \ No newline at end of file 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 = '\ + \ + ' % 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..16cf7e29 --- /dev/null +++ b/test/unit/test_roles.py @@ -0,0 +1,200 @@ +# 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 CreateRoleTest(RolesTest): + def test_a_role_create_json(self): + resp, content = utils.create_role('test_role1', + str(self.auth_token)) + self.role = 'test_role1' + resp_val = int(resp['status']) + self.assertEqual(201, resp_val) + + def test_a_role_create_xml(self): + resp, content = utils.create_role_xml('test_role2', + str(self.auth_token)) + self.role = 'test_role1' + resp_val = int(resp['status']) + self.assertEqual(201, resp_val) + self.assertEqual('application/xml', utils.content_type(resp)) + + def test_role_create_again(self): + resp_new, content = utils.create_role_xml('test_role2', + str(self.auth_token)) + if int(resp_new['status']) == 500: + self.fail('IDM fault') + elif int(resp_new['status']) == 503: + self.fail('Service Not Available') + self.assertEqual(409, int(resp_new['status'])) + + def test_role_create_again_xml(self): + resp_new, content = utils.create_role_xml('test_role2', + str(self.auth_token)) + if int(resp_new['status']) == 500: + self.fail('IDM fault') + elif int(resp_new['status']) == 503: + self.fail('Service Not Available') + self.assertEqual(409, int(resp_new['status'])) + +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 = 'test_role1' + 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 = 'test_role1' + 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() -- cgit From 80a286d80331733382f51cc9e478bf7432fcac36 Mon Sep 17 00:00:00 2001 From: Yogeshwar Srikrishnan Date: Mon, 23 May 2011 17:59:39 -0500 Subject: Changes to support /Roles calls.Description included. --- test/IdentitySOAPUI.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/IdentitySOAPUI.xml b/test/IdentitySOAPUI.xml index dd7795e4..d5832df8 100644 --- a/test/IdentitySOAPUI.xml +++ b/test/IdentitySOAPUI.xml @@ -1,5 +1,5 @@ - + @@ -1264,7 +1264,7 @@ ns1:Response/ns1:tenant/ns1:id = "JGroup65" and ns1:Response/ns1:tenant/ns1:desc } }400falsefalsebadRequestfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; count(//ns1:tenant)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0/tenants'; -count(//ns1:e)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; +count(//ns1:e)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; ns1:tenant/@id1234falsefalsedeclare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; /ns1:tenant/@enabled and /ns1:tenant/ns1:descriptiontruefalsefalse @@ -1281,15 +1281,15 @@ ns1:Response/ns1:tenant/ns1:id1234fals xmlns:v1="http://docs.openstack.org/identity/api/v2.0"> <v1:description>To Be Deleted</v1:description> </v1:tenant>declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; -/ns1:tenant/@enabled = "true" and /ns1:tenant/@id="to_delete" and /ns1:tenant/ns1:description = "To Be Deleted"truefalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; +/ns1:tenant/@enabled = "true" and /ns1:tenant/@id="to_delete" and /ns1:tenant/ns1:description = "To Be Deleted"truefalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; ns1:tenant/@idto_deletefalsefalsedeclare namespace ns1='http://docs.openstack.org/identity/api/v2.0'; /ns1:tenant/@enabled and /ns1:tenant/ns1:descriptiontruefalsefalse -<entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080assert(context.response == null) +<entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080assert(context.response == null) -<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse +<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse <entry key="Accept" value="application/xml" xmlns="http://eviware.com/soapui/config"/>http://localhost:8080forbiddenfalsefalse403falsefalse @@ -1350,6 +1350,6 @@ ns1:tenant/@idto_deletefalse <xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; count(/ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0/extensions'; -count(//ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; +count(//ns1:extensions)1falsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080404falsefalseitemNotFoundfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/common/api/v1.0'; count(//ns1:version)1falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0'; count(//ns1:version)1falsefalse \ No newline at end of file -- cgit From 8e759bc6759422920a7ccd9f96ede61ea849e421 Mon Sep 17 00:00:00 2001 From: Yogeshwar Srikrishnan Date: Mon, 23 May 2011 18:05:11 -0500 Subject: Changes to support /Roles calls.Removing create call from being exposed as of now. --- test/unit/test_roles.py | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/unit/test_roles.py b/test/unit/test_roles.py index 16cf7e29..37021440 100644 --- a/test/unit/test_roles.py +++ b/test/unit/test_roles.py @@ -48,40 +48,6 @@ class RolesTest(unittest.TestCase): utils.delete_user(self.tenant, self.user, self.auth_token) utils.delete_tenant(self.tenant, self.auth_token) -class CreateRoleTest(RolesTest): - def test_a_role_create_json(self): - resp, content = utils.create_role('test_role1', - str(self.auth_token)) - self.role = 'test_role1' - resp_val = int(resp['status']) - self.assertEqual(201, resp_val) - - def test_a_role_create_xml(self): - resp, content = utils.create_role_xml('test_role2', - str(self.auth_token)) - self.role = 'test_role1' - resp_val = int(resp['status']) - self.assertEqual(201, resp_val) - self.assertEqual('application/xml', utils.content_type(resp)) - - def test_role_create_again(self): - resp_new, content = utils.create_role_xml('test_role2', - str(self.auth_token)) - if int(resp_new['status']) == 500: - self.fail('IDM fault') - elif int(resp_new['status']) == 503: - self.fail('Service Not Available') - self.assertEqual(409, int(resp_new['status'])) - - def test_role_create_again_xml(self): - resp_new, content = utils.create_role_xml('test_role2', - str(self.auth_token)) - if int(resp_new['status']) == 500: - self.fail('IDM fault') - elif int(resp_new['status']) == 503: - self.fail('Service Not Available') - self.assertEqual(409, int(resp_new['status'])) - class GetRolesTest(RolesTest): def test_get_roles(self): header = httplib2.Http(".cache") @@ -140,7 +106,7 @@ class GetRolesTest(RolesTest): class GetRoleTest(RolesTest): def test_get_role(self): - self.role = 'test_role1' + self.role = 'Admin' header = httplib2.Http(".cache") url = '%sroles/%s' % (utils.URL, self.role) #test for Content-Type = application/json @@ -154,7 +120,7 @@ class GetRoleTest(RolesTest): self.assertEqual(200, int(resp['status'])) def test_get_role_xml(self): - self.role = 'test_role1' + self.role = 'Admin' header = httplib2.Http(".cache") url = '%sroles/%s' % (utils.URL, self.role) #test for Content-Type = application/json -- cgit