Fixed httplib2 mocking (bug 1050091, bug 1050097)
- 204 No Content should be mocked with empty response bodies - Content-Type headers should not be mocked with empty response bodies - httplib2 would never return None as a response body - The Identity API never expects a req/resp body with a string value of "null" Change-Id: Ie22e8e5288573268165ed06049978195955f8ca6
This commit is contained in:
parent
dd84cdc340
commit
0ee5147030
keystoneclient
tests/v2_0
@ -98,7 +98,10 @@ class Manager(object):
|
||||
"POST": self.api.post,
|
||||
"PATCH": self.api.patch}
|
||||
try:
|
||||
resp, body = methods[method](url, body=body)
|
||||
if body is not None:
|
||||
resp, body = methods[method](url, body=body)
|
||||
else:
|
||||
resp, body = methods[method](url)
|
||||
except KeyError:
|
||||
raise exceptions.ClientException("Invalid update method: %s"
|
||||
% method)
|
||||
|
@ -139,7 +139,7 @@ class EC2Tests(utils.TestCase):
|
||||
user_id = 'usr'
|
||||
access = 'access'
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": "",
|
||||
})
|
||||
|
||||
|
@ -83,7 +83,7 @@ class EndpointTests(utils.TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": "",
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
|
@ -66,7 +66,7 @@ class RoleTests(utils.TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": "",
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
@ -147,62 +147,60 @@ class RoleTests(utils.TestCase):
|
||||
|
||||
def test_add_user_role(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
||||
'PUT',
|
||||
body='null',
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.roles.add_user_role('foo', 'barrr')
|
||||
|
||||
def test_add_user_role_tenant(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'PUT',
|
||||
body='null',
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.roles.add_user_role('foo', 'barrr', '4')
|
||||
|
||||
def test_remove_user_role(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.roles.remove_user_role('foo', 'barrr')
|
||||
|
||||
def test_remove_user_role_tenant(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.roles.remove_user_role('foo', 'barrr', '4')
|
||||
|
@ -83,7 +83,7 @@ class TenantTests(utils.TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": "",
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
@ -220,31 +220,30 @@ class TenantTests(utils.TestCase):
|
||||
|
||||
def test_add_user(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'PUT',
|
||||
body='null',
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.tenants.add_user('4', 'foo', 'barrr')
|
||||
|
||||
def test_remove_user(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.tenants.remove_user('4', 'foo', 'barrr')
|
||||
@ -259,16 +258,15 @@ class TenantTests(utils.TestCase):
|
||||
},
|
||||
}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'PUT',
|
||||
body='null',
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# make tenant object with manager
|
||||
@ -287,15 +285,15 @@ class TenantTests(utils.TestCase):
|
||||
},
|
||||
}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({}),
|
||||
"status": 204,
|
||||
"body": '',
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, None))
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
# make tenant object with manager
|
||||
|
@ -18,7 +18,7 @@ class TokenTests(utils.TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": ""})
|
||||
|
||||
req = httplib2.Http.request(
|
||||
|
@ -82,7 +82,7 @@ class UserTests(utils.TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"status": 204,
|
||||
"body": "",
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user