summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZiad Sawalha <github@highbridgellc.com>2011-04-27 12:18:55 -0700
committerZiad Sawalha <github@highbridgellc.com>2011-04-27 12:18:55 -0700
commit7122789e2f17c381b53cb4cf3ebc83f034ae100d (patch)
treec9736bc8f9a079958097c98f626cbaa246ccdf7b
parent79c78088b600beb5351fed180ada384e012c9db1 (diff)
parenta1c66e6112337f9d530db6370886d03e650fe29c (diff)
downloadkeystone-7122789e2f17c381b53cb4cf3ebc83f034ae100d.tar.gz
keystone-7122789e2f17c381b53cb4cf3ebc83f034ae100d.tar.xz
keystone-7122789e2f17c381b53cb4cf3ebc83f034ae100d.zip
Merge branch 'master' of github.com:khussein/keystone
-rw-r--r--README.md16
-rw-r--r--test/unit/test_identity.py774
2 files changed, 639 insertions, 151 deletions
diff --git a/README.md b/README.md
index 7938cb8e..2126bb87 100644
--- a/README.md
+++ b/README.md
@@ -133,6 +133,22 @@ To Test Identity Service:
* Double click on "Keystone Tests" and press the green play (>) button
+Unit Test on Identity Services
+------------------------------
+In order to run the unit test on identity services, run from the keystone directory
+
+ python identity.py
+
+Once the Identity service is running, go to unit test/unit directory
+
+ python test_identity.py
+
+For more on unit testing please refer
+
+python test_identity --help
+
+
+
DATABASE SCHEMA
---------------
diff --git a/test/unit/test_identity.py b/test/unit/test_identity.py
index c3a278f4..dfd4ba26 100644
--- a/test/unit/test_identity.py
+++ b/test/unit/test_identity.py
@@ -1,10 +1,8 @@
import unittest
from webtest import TestApp
import httplib2
-import pprint
-import bottle
-from keystone.logic.types import auth
-from keystone.db.sqlalchemy.api import token_get
+from lxml import etree
+
try:
import simplejson as json
except ImportError:
@@ -12,128 +10,239 @@ except ImportError:
URL = 'http://localhost:8080/v1.0/'
-def get_token(user,pswd,type=''):
+def get_token(user, pswd, type=''):
h = httplib2.Http(".cache")
url = '%stoken' % URL
body = '{"passwordCredentials" : { "username" : "%s", "password" :\
- "%s"} }'% (user,pswd)
+ "%s"} }' % (user, pswd)
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json"})
- content=json.loads(content)
- token=str(content['auth']['token']['id'])
- if type=='token':
+ headers={"Content-Type": "application/json"})
+ content = json.loads(content)
+ token = str(content['auth']['token']['id'])
+ if type == 'token':
return token
else:
- return (resp,content)
-def delete_token(token,auth_token):
+ return (resp, content)
+
+
+def get_token_xml(user, pswd, type=''):
+ h = httplib2.Http(".cache")
+ url = '%stoken' % URL
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <passwordCredentials \
+ xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ password="%s" username="%s" \
+ tenantId="77654"/> ' % (pswd, user)
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
+ dom = etree.fromstring(content)
+ root = dom.find("{http://docs.openstack.org/idm/api/v1.0}token")
+ token_root = root.attrib
+ token = str(token_root['id'])
+ if type == 'token':
+ return token
+ else:
+ return (resp, content)
+
+
+def delete_token(token, auth_token):
+ h = httplib2.Http(".cache")
+ url = '%stoken/%s' % (URL, token)
+ resp, content = h.request(url, "DELETE", body='', \
+ headers={"Content-Type": "application/json", \
+ "X-Auth-Token": auth_token})
+ return (resp, content)
+
+
+def delete_token_xml(token, auth_token):
h = httplib2.Http(".cache")
url = '%stoken/%s' % (URL, token)
resp, content = h.request(url, "DELETE", body='',\
- headers={"Content-Type":"application/json", \
- "X-Auth-Token" : auth_token})
- return (resp,content)
+ headers={"Content-Type": "application/xml", \
+ "X-Auth-Token": auth_token,
+ "ACCEPT": "application/xml"})
+ return (resp, content)
+
-def create_tenant(tenantid,auth_token):
+def create_tenant(tenantid, auth_token):
h = httplib2.Http(".cache")
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % tenantid
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : auth_token})
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": auth_token})
+
+ return (resp, content)
+
+
+def create_tenant_xml(tenantid, auth_token):
+ h = httplib2.Http(".cache")
+ url = '%stenants' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % tenantid
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": auth_token,
+ "ACCEPT": "application/xml"})
+ return (resp, content)
- return (resp,content)
def delete_tenant(tenantid, auth_token):
h = httplib2.Http(".cache")
+ url = '%stenants/%s' % (URL, tenantid)
+ resp, content = h.request(url, "DELETE", body='{}',\
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": auth_token})
+ return (resp, content)
- url = '%stenants/%s' % (URL,tenantid)
+def delete_tenant_xml(tenantid, auth_token):
+ h = httplib2.Http(".cache")
+ url = '%stenants/%s' % (URL, tenantid)
resp, content = h.request(url, "DELETE", body='',\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : auth_token})
- return (resp,content)
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": auth_token,
+ "ACCEPT": "application/xml"})
+ return (resp, content)
def get_tenant():
return '1234'
+
def get_user():
return '1234'
+
def get_userdisabled():
return '1234'
+
def get_auth_token():
return '999888777666'
+
def get_exp_auth_token():
return '000999'
+
def get_disabled_token():
return '999888777'
class identity_test(unittest.TestCase):
- #given _a_ to make inherited test cases in an order.
+ #Given _a_ to make inherited test cases in an order.
#here to call below method will call as last test case
+
def test_a_get_version(self):
h = httplib2.Http(".cache")
url = URL
resp, content = h.request(url, "GET", body="",\
- headers={"Content-Type":"application/json"})
+ headers={"Content-Type": "application/json"})
self.assertEqual(200, int(resp['status']))
self.assertEqual('application/json', resp['content-type'])
+ def test_a_get_version(self):
+ h = httplib2.Http(".cache")
+ url = URL
+ resp, content = h.request(url, "GET", body="",\
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
+ self.assertEqual(200, int(resp['status']))
+ self.assertEqual('application/xml', resp['content-type'])
+
class authorize_test(identity_test):
def setUp(self):
- self.token=get_token('joeuser','secrete','token')
- self.tenant=get_tenant()
- self.user=get_user()
- self.userdisabled=get_userdisabled()
- self.auth_token=get_auth_token()
- self.exp_auth_token=get_exp_auth_token()
- self.disabled_token=get_disabled_token()
-
+ self.token = get_token('joeuser', 'secrete', 'token')
+ self.tenant = get_tenant()
+ self.user = get_user()
+ self.userdisabled = get_userdisabled()
+ self.auth_token = get_auth_token()
+ self.exp_auth_token = get_exp_auth_token()
+ self.disabled_token = get_disabled_token()
def tearDown(self):
- delete_token(self.token,self.auth_token)
-
+ delete_token(self.token, self.auth_token)
def test_a_authorize(self):
- resp,content= get_token('joeuser','secrete')
+ resp, content = get_token('joeuser', 'secrete')
self.assertEqual(200, int(resp['status']))
self.assertEqual('application/json', resp['content-type'])
+ def test_a_authorize_xml(self):
+ resp, content = get_token_xml('joeuser', 'secrete')
+ self.assertEqual(200, int(resp['status']))
+ self.assertEqual('application/xml', resp['content-type'])
def test_a_authorize_user_disaabled(self):
h = httplib2.Http(".cache")
url = '%stoken' % URL
- body = '{"passwordCredentials" : { "username" : "disabled", "password" :\
+ body = '{"passwordCredentials" : { "username": "disabled", "password":\
"secrete"} }'
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json"})
- content=json.loads(content)
+ headers={"Content-Type": "application/json"})
+ content = json.loads(content)
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
self.fail('Service Not Available')
self.assertEqual(403, int(resp['status']))
+ def test_a_authorize_user_disaabled_xml(self):
+ h = httplib2.Http(".cache")
+ url = '%stoken' % URL
+
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <passwordCredentials \
+ xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ password="secrete" username="disabled" \
+ />'
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
+ content = etree.fromstring(content)
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
def test_a_authorize_user_wrong(self):
h = httplib2.Http(".cache")
url = '%stoken' % URL
- body = '{"passwordCredentials" : { "username-w" : "disabled", "password" :\
- "secrete"} }'
+ body = '{"passwordCredentials" : { "username-w" : "disabled", \
+ "password" : "secrete"} }'
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/json"})
+ content = json.loads(content)
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(400, int(resp['status']))
+
+ def test_a_authorize_user_wrong_xml(self):
+ h = httplib2.Http(".cache")
+ url = '%stoken' % URL
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <passwordCredentials \
+ xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ password="secrete" username-w="disabled" \
+ />'
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json"})
- content=json.loads(content)
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
+ content = etree.fromstring(content)
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
@@ -146,10 +255,10 @@ class validate_token(authorize_test):
def test_validate_token_true(self):
h = httplib2.Http(".cache")
- url = '%stoken/%s?belongsTo=%s' % (URL, self.token,self.tenant)
+ url = '%stoken/%s?belongsTo=%s' % (URL, self.token, self.tenant)
resp, content = h.request(url, "GET", body='',\
- headers={"Content-Type":"application/json", \
- "X-Auth-Token" : self.auth_token})
+ headers={"Content-Type": "application/json", \
+ "X-Auth-Token": self.auth_token})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
@@ -157,14 +266,27 @@ class validate_token(authorize_test):
self.assertEqual(200, int(resp['status']))
self.assertEqual('application/json', resp['content-type'])
+ def test_validate_token_true_xml(self):
+ h = httplib2.Http(".cache")
+ url = '%stoken/%s?belongsTo=%s' % (URL, self.token, self.tenant)
+ resp, content = h.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('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+ self.assertEqual('application/xml', resp['content-type'])
def test_validate_token_expired(self):
h = httplib2.Http(".cache")
-
- url = '%stoken/%s?belongsTo=%s' % (URL, self.exp_auth_token,self.tenant)
+ url = '%stoken/%s?belongsTo=%s' % (URL, self.exp_auth_token, \
+ self.tenant)
resp, content = h.request(url, "GET", body='',\
- headers={"Content-Type":"application/json", \
- "X-Auth-Token" : self.exp_auth_token})
+ headers={"Content-Type": "application/json", \
+ "X-Auth-Token": self.exp_auth_token})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
@@ -172,14 +294,29 @@ class validate_token(authorize_test):
self.assertEqual(401, int(resp['status']))
self.assertEqual('application/json', resp['content-type'])
+ def test_validate_token_expired_xml(self):
+ h = httplib2.Http(".cache")
+
+ url = '%stoken/%s?belongsTo=%s' % (URL, self.exp_auth_token, \
+ self.tenant)
+ resp, content = h.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('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(401, int(resp['status']))
+ self.assertEqual('application/xml', resp['content-type'])
def test_validate_token_invalid(self):
h = httplib2.Http(".cache")
-
- url = '%stoken/%s?belongsTo=%s' % (URL, 'NonExistingToken',self.tenant)
+ url = '%stoken/%s?belongsTo=%s' % (URL, 'NonExistingToken', \
+ self.tenant)
resp, content = h.request(url, "GET", body='',\
- headers={"Content-Type":"application/json", \
- "X-Auth-Token" : self.auth_token})
+ headers={"Content-Type": "application/json", \
+ "X-Auth-Token": self.auth_token})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -188,67 +325,109 @@ class validate_token(authorize_test):
self.assertEqual(404, int(resp['status']))
self.assertEqual('application/json', resp['content-type'])
+ def test_validate_token_invalid_xml(self):
+ h = httplib2.Http(".cache")
+ url = '%stoken/%s?belongsTo=%s' % (URL, 'NonExistingToken', \
+ self.tenant)
+ resp, content = h.request(url, "GET", body='',\
+ headers={"Content-Type": "application/json", \
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+ self.assertEqual('application/json', resp['content-type'])
+
class tenant_test(unittest.TestCase):
+
def setUp(self):
- self.token=get_token('joeuser','secrete','token')
- self.tenant=get_tenant()
- self.user=get_user()
- self.userdisabled=get_userdisabled()
- self.auth_token=get_auth_token()
- self.exp_auth_token=get_exp_auth_token()
- self.disabled_token=get_disabled_token()
+ self.token = get_token('joeuser', 'secrete', 'token')
+ self.tenant = get_tenant()
+ self.user = get_user()
+ self.userdisabled = get_userdisabled()
+ self.auth_token = get_auth_token()
+ self.exp_auth_token = get_exp_auth_token()
+ self.disabled_token = get_disabled_token()
def tearDown(self):
- resp,content=delete_tenant(self.tenant,self.auth_token)
+ resp, content = delete_tenant(self.tenant, self.auth_token)
class create_tenant_test(tenant_test):
def test_tenant_create(self):
- resp,content=delete_tenant('test_tenant', str(self.auth_token))
- resp,content=create_tenant('test_tenant', str(self.auth_token))
- self.tenant='test_tenant'
- content=json.loads(content)
+ resp, content = delete_tenant('test_tenant', str(self.auth_token))
+ resp, content = create_tenant('test_tenant', str(self.auth_token))
+ self.tenant = 'test_tenant'
+
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
self.fail('Service Not Available')
- if int(resp['status']) not in (200, 201) :
+ if int(resp['status']) not in (200, 201):
self.fail('Failed due to %d' % int(resp['status']))
- def test_tenant_create_again(self):
+ def test_tenant_create_xml(self):
+ resp, content = delete_tenant_xml('test_tenant', str(self.auth_token))
+ resp, content = create_tenant_xml('test_tenant', str(self.auth_token))
+ self.tenant = 'test_tenant'
+ content = etree.fromstring(content)
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
- resp,content=create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) not in (200, 201):
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ self.fail('Failed due to %d' % int(resp['status']))
+
+ def test_tenant_create_again(self):
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
self.fail('Service Not Available')
self.assertEqual(409, int(resp['status']))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
+
+ def test_tenant_create_again_xml(self):
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get("id")
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(409, int(resp['status']))
+ if int(resp['status']) == 200:
+ self.tenant = content.get("id")
def test_tenant_create_forbidden_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % self.tenant
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : self.token})
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": self.token})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -256,20 +435,68 @@ class create_tenant_test(tenant_test):
self.fail('Service Not Available')
self.assertEqual(403, int(resp['status']))
+ def test_tenant_create_forbidden_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get('id')
+
+ url = '%stenants' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % self.tenant
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.token,
+ "ACCEPT": "application/xml"})
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
def test_tenant_create_expired_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % self.tenant
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : self.exp_auth_token})
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": self.exp_auth_token})
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(401, int(resp['status']))
+
+ def test_tenant_create_expired_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get('id')
+
+ url = '%stenants' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % self.tenant
+
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.exp_auth_token,
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -279,16 +506,40 @@ class create_tenant_test(tenant_test):
def test_tenant_create_missing_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % self.tenant
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json"})
+ headers={"Content-Type": "application/json"})
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(401, int(resp['status']))
+
+ def test_tenant_create_missing_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get('id')
+
+ url = '%stenants' % (URL)
+
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % self.tenant
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -298,17 +549,41 @@ class create_tenant_test(tenant_test):
def test_tenant_create_disabled_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % self.tenant
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : self.disabled_token})
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": self.disabled_token})
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
+
+ def test_tenant_create_disabled_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get('id')
+
+ url = '%stenants' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % self.tenant
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",
+ "X-Auth-Token": self.disabled_token,
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -318,17 +593,41 @@ class create_tenant_test(tenant_test):
def test_tenant_create_invalid_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant("test_tenant", str(self.auth_token))
- if int(resp['status'])==200:
- self.tenant=content['tenant']['id']
+ resp, content = create_tenant("test_tenant", str(self.auth_token))
+ if int(resp['status']) == 200:
+ self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body='{"tenant": { "id": "%s", \
+ body = '{"tenant": { "id": "%s", \
"description": "A description ...", "enabled"\
:true } }' % self.tenant
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type":"application/json",\
- "X-Auth-Token" : 'nonexsitingtoken'})
+ headers={"Content-Type": "application/json",\
+ "X-Auth-Token": 'nonexsitingtoken'})
+
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(401, int(resp['status']))
+
+ def test_tenant_create_invalid_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml("test_tenant", str(self.auth_token))
+ content = etree.fromstring(content)
+ if int(resp['status']) == 200:
+ self.tenant = content.get('id')
+
+ url = '%stenants' % (URL)
+ body = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true" id="%s"> \
+ <description>A description...</description> \
+ </tenant>' % self.tenant
+ resp, content = h.request(url, "POST", body=body,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": 'nonexsitingtoken',
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -336,16 +635,32 @@ class create_tenant_test(tenant_test):
self.fail('Service Not Available')
self.assertEqual(401, int(resp['status']))
+
class get_tenants_test(tenant_test):
def test_get_tenants(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants' % (URL)
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{}',\
+ resp, content = h.request(url, "GET", body='{}',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
+ def test_get_tenants_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
+ #test for Content-Type = application/json
+ resp, content = h.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('IDM fault')
elif int(resp['status']) == 503:
@@ -354,12 +669,27 @@ class get_tenants_test(tenant_test):
def test_get_tenants_forbidden_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants' % (URL)
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{}',\
+ resp, content = h.request(url, "GET", body='{}',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.token})
+ "X-Auth-Token": self.token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(403, int(resp['status']))
+
+ def test_get_tenants_forbidden_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
+ #test for Content-Type = application/json
+ resp, content = h.request(url, "GET", body='',\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.token,
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
@@ -368,12 +698,27 @@ class get_tenants_test(tenant_test):
def test_get_tenants_exp_token(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants' % (URL)
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{}',\
+ resp, content = h.request(url, "GET", body='{}',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.exp_auth_token})
+ "X-Auth-Token": self.exp_auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(401, int(resp['status']))
+
+ def test_get_tenants_exp_token_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants' % (URL)
+ #test for Content-Type = application/json
+ resp, content = h.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('IDM fault')
elif int(resp['status']) == 503:
@@ -385,25 +730,56 @@ class get_tenant_test(tenant_test):
def test_get_tenant(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/%s' % (URL, self.tenant)
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{}',\
+ resp, content = h.request(url, "GET", body='{}',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
self.fail('Service Not Available')
self.assertEqual(200, int(resp['status']))
+
+ def test_get_tenant_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
+ #test for Content-Type = application/json
+ resp, content = h.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('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+
def test_get_tenant_bad(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/%s' % (URL, 'tenant_bad')
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, 'tenant_bad')
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{',\
+ resp, content = h.request(url, "GET", body='{',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+
+ def test_get_tenant_bad_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, 'tenant_bad')
+ #test for Content-Type = application/json
+ resp, content = h.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('IDM fault')
elif int(resp['status']) == 503:
@@ -412,12 +788,27 @@ class get_tenant_test(tenant_test):
def test_get_tenant_not_found(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/NonexistingID' % (URL)
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/NonexistingID' % (URL)
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body='{}',\
+ resp, content = h.request(url, "GET", body='{}',\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+
+ def test_get_tenant_not_found_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/NonexistingID' % (URL)
+ #test for Content-Type = application/json
+ resp, content = h.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('IDM fault')
elif int(resp['status']) == 503:
@@ -429,13 +820,14 @@ class update_tenant_test(tenant_test):
def test_update_tenant(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/%s' % (URL, self.tenant)
- data='{"tenant": { "description": "A NEW description..." ,"enabled":true }}'
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
+ data = '{"tenant": { "description": "A NEW description..." ,\
+ "enabled":true }}'
#test for Content-Type = application/json
- resp,content= h.request(url,"PUT", body=data,\
+ resp, content = h.request(url, "PUT", body=data,\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
body = json.loads(content)
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -446,15 +838,63 @@ class update_tenant_test(tenant_test):
self.assertEqual('A NEW description...', \
body['tenant']['description'])
+ def test_update_tenant_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant_xml(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
+ data = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true"> \
+ <description>A NEW description...</description> \
+ </tenant>'
+
+ #test for Content-Type = application/json
+ resp, content = h.request(url, "PUT", body=data,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
+ body = etree.fromstring(content)
+ desc = body.find("{http://docs.openstack.org/idm/api/v1.0}description")
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(200, int(resp['status']))
+ self.assertEqual(int(self.tenant), int(body.get('id')))
+ self.assertEqual('A NEW description...', \
+ desc.text)
+
def test_update_tenant_bad(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/%s' % (URL, self.tenant)
- data='{"tenant": { "description_bad": "A NEW description...","enabled":true }}'
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
+ data = '{"tenant": { "description_bad": "A NEW description...",\
+ "enabled":true }}'
#test for Content-Type = application/json
- resp,content= h.request(url,"PUT", body=data,\
+
+ resp, content = h.request(url, "PUT", body=data,\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(400, int(resp['status']))
+
+ def test_update_tenant_bad_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/%s' % (URL, self.tenant)
+ data = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true"> \
+ <description_bad>A NEW description...</description> \
+ </tenant>'
+ #test for Content-Type = application/json
+ resp, content = h.request(url, "PUT", body=data,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
@@ -463,36 +903,68 @@ class update_tenant_test(tenant_test):
def test_update_tenant_not_found(self):
h = httplib2.Http(".cache")
- resp,content=create_tenant(self.tenant, str(self.auth_token))
- url='%stenants/NonexistingID' % (URL)
- data='{"tenant": { "description": "A NEW description...","enabled":true }}'
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/NonexistingID' % (URL)
+ data = '{"tenant": { "description": "A NEW description...",\
+ "enabled":true }}'
#test for Content-Type = application/json
- resp,content= h.request(url,"GET", body=data,\
+ resp, content = h.request(url, "GET", body=data,\
headers={"Content-Type": "application/json",\
- "X-Auth-Token" : self.auth_token})
+ "X-Auth-Token": self.auth_token})
+ if int(resp['status']) == 500:
+ self.fail('IDM fault')
+ elif int(resp['status']) == 503:
+ self.fail('Service Not Available')
+ self.assertEqual(404, int(resp['status']))
+
+ def test_update_tenant_not_found_xml(self):
+ h = httplib2.Http(".cache")
+ resp, content = create_tenant(self.tenant, str(self.auth_token))
+ url = '%stenants/NonexistingID' % (URL)
+ data = '<?xml version="1.0" encoding="UTF-8"?> \
+ <tenant xmlns="http://docs.openstack.org/idm/api/v1.0" \
+ enabled="true"> \
+ <description_bad>A NEW description...</description> \
+ </tenant>'
+ #test for Content-Type = application/json
+ resp, content = h.request(url, "GET", body=data,\
+ headers={"Content-Type": "application/xml",\
+ "X-Auth-Token": self.auth_token,
+ "ACCEPT": "application/xml"})
if int(resp['status']) == 500:
self.fail('IDM fault')
elif int(resp['status']) == 503:
self.fail('Service Not Available')
self.assertEqual(404, int(resp['status']))
+
class delete_tenant_test(tenant_test):
def test_delete_tenant_not_found(self):
#resp,content=create_tenant("test_tenant_delete", str(self.auth_token))
- resp,content=delete_tenant("test_tenant_delete111", str(self.auth_token))
+ resp, content = delete_tenant("test_tenant_delete111", \
+ str(self.auth_token))
self.assertEqual(404, int(resp['status']))
- def test_delete_tenant(self):
- resp,content=create_tenant("test_tenant_delete", str(self.auth_token))
- resp,content=delete_tenant("test_tenant_delete", str(self.auth_token))
+ def test_delete_tenant_not_found_xml(self):
+ #resp,content=create_tenant("test_tenant_delete", str(self.auth_token))
+ resp, content = delete_tenant_xml("test_tenant_delete111", \
+ str(self.auth_token))
+ self.assertEqual(404, int(resp['status']))
+ def test_delete_tenant(self):
+ resp, content = create_tenant("test_tenant_delete", \
+ str(self.auth_token))
+ resp, content = delete_tenant("test_tenant_delete", \
+ str(self.auth_token))
self.assertEqual(204, int(resp['status']))
-
-
-
-
+ def test_delete_tenant_xml(self):
+ resp, content = create_tenant_xml("test_tenant_delete", \
+ str(self.auth_token))
+ resp, content = delete_tenant_xml("test_tenant_delete", \
+ str(self.auth_token))
+ self.assertEqual(204, int(resp['status']))
if __name__ == '__main__':
unittest.main()