diff options
| author | John Eo <joon.eo@gmail.com> | 2011-04-28 13:50:57 -0500 |
|---|---|---|
| committer | John Eo <joon.eo@gmail.com> | 2011-04-28 13:50:57 -0500 |
| commit | e6482b36eb24e9713dc5de28d051c19bbe4bd615 (patch) | |
| tree | a0a48bda97e2cd21105bdff1ba69d48124f83a50 /test | |
| parent | 62e32e1b3399f308e44a4357819faa8575cd5908 (diff) | |
| parent | b42d40a726868be543e877706958a0921d4dcd93 (diff) | |
| download | keystone-e6482b36eb24e9713dc5de28d051c19bbe4bd615.tar.gz keystone-e6482b36eb24e9713dc5de28d051c19bbe4bd615.tar.xz keystone-e6482b36eb24e9713dc5de28d051c19bbe4bd615.zip | |
Merge branch 'master' of https://github.com/khussein/keystone
Conflicts:
test/unit/test_identity.py
Diffstat (limited to 'test')
| -rw-r--r-- | test/unit/test_identity.py | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/test/unit/test_identity.py b/test/unit/test_identity.py index 2cf2901e..ed3ea3fb 100644 --- a/test/unit/test_identity.py +++ b/test/unit/test_identity.py @@ -8,25 +8,24 @@ import identity import unittest
from webtest import TestApp
import httplib2
+import json
from lxml import etree
+import unittest
+from webtest import TestApp
-try:
- import simplejson as json
-except ImportError:
- import json
URL = 'http://localhost:8080/v1.0/'
-def get_token(user, pswd, type=''):
+def get_token(user, pswd, kind=''):
h = httplib2.Http(".cache")
url = '%stoken' % URL
- body = '{"passwordCredentials" : { "username" : "%s", "password" :\
- "%s"} }' % (user, pswd)
- resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type": "application/json"})
+ body = {"passwordCredentials": {"username": user,
+ "password": pswd}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
+ headers={"Content-Type": "application/json"})
content = json.loads(content)
token = str(content['auth']['token']['id'])
- if type == 'token':
+ if kind == 'token':
return token
else:
return (resp, content)
@@ -76,13 +75,12 @@ def create_tenant(tenantid, auth_token): h = httplib2.Http(".cache")
url = '%stenants' % (URL)
- 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})
-
+ body = {"tenant": {"id": tenantid,
+ "description": "A description ...",
+ "enabled": True}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
+ headers={"Content-Type": "application/json",
+ "X-Auth-Token": auth_token})
return (resp, content)
@@ -152,15 +150,15 @@ class identity_test(unittest.TestCase): def test_a_get_version(self):
h = httplib2.Http(".cache")
url = URL
- resp, content = h.request(url, "GET", body="",\
- headers={"Content-Type": "application/json"})
+ resp, content = h.request(url, "GET", body="",
+ 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="",\
+ resp, content = h.request(url, "GET", body="",
headers={"Content-Type": "application/xml",
"ACCEPT": "application/xml"})
self.assertEqual(200, int(resp['status']))
@@ -194,9 +192,9 @@ class authorize_test(identity_test): def test_a_authorize_user_disaabled(self):
h = httplib2.Http(".cache")
url = '%stoken' % URL
- body = '{"passwordCredentials" : { "username": "disabled", "password":\
- "secrete"} }'
- resp, content = h.request(url, "POST", body=body,\
+ body = {"passwordCredentials": {"username": "disabled",
+ "password": "secrete"}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
headers={"Content-Type": "application/json"})
content = json.loads(content)
if int(resp['status']) == 500:
@@ -215,8 +213,8 @@ class authorize_test(identity_test): password="secrete" username="disabled" \
/>'
resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type": "application/xml",
- "ACCEPT": "application/xml"})
+ headers={"Content-Type": "application/xml",
+ "ACCEPT": "application/xml"})
content = etree.fromstring(content)
if int(resp['status']) == 500:
self.fail('IDM fault')
@@ -227,9 +225,9 @@ class authorize_test(identity_test): def test_a_authorize_user_wrong(self):
h = httplib2.Http(".cache")
url = '%stoken' % URL
- body = '{"passwordCredentials" : { "username-w" : "disabled", \
- "password" : "secrete"} }'
- resp, content = h.request(url, "POST", body=body,\
+ body = {"passwordCredentials": {"username-w": "disabled",
+ "password": "secrete"}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
headers={"Content-Type": "application/json"})
content = json.loads(content)
if int(resp['status']) == 500:
@@ -429,11 +427,11 @@ class create_tenant_test(tenant_test): self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body = '{"tenant": { "id": "%s", \
- "description": "A description ...", "enabled"\
- :true } }' % self.tenant
- resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type": "application/json",\
+ body = {"tenant": {"id": self.tenant,
+ "description": "A description ...",
+ "enabled": True}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
+ headers={"Content-Type": "application/json",
"X-Auth-Token": self.token})
if int(resp['status']) == 500:
@@ -473,11 +471,11 @@ class create_tenant_test(tenant_test): self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body = '{"tenant": { "id": "%s", \
- "description": "A description ...", "enabled"\
- :true } }' % self.tenant
- resp, content = h.request(url, "POST", body=body,\
- headers={"Content-Type": "application/json",\
+ body = {"tenant": {"id": self.tenant,
+ "description": "A description ...",
+ "enabled": True}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
+ headers={"Content-Type": "application/json",
"X-Auth-Token": self.exp_auth_token})
if int(resp['status']) == 500:
@@ -518,10 +516,10 @@ class create_tenant_test(tenant_test): self.tenant = content['tenant']['id']
url = '%stenants' % (URL)
- body = '{"tenant": { "id": "%s", \
- "description": "A description ...", "enabled"\
- :true } }' % self.tenant
- resp, content = h.request(url, "POST", body=body,\
+ body = {"tenant": {"id": self.tenant,
+ "description": "A description ...",
+ "enabled": True}}
+ resp, content = h.request(url, "POST", body=json.dumps(body),
headers={"Content-Type": "application/json"})
if int(resp['status']) == 500:
|
