Merge "Fixed httplib2 mocking (bug 1050091, bug 1050097)"
This commit is contained in:
@@ -91,7 +91,10 @@ class Manager(object):
|
|||||||
methods = {"PUT": self.api.put,
|
methods = {"PUT": self.api.put,
|
||||||
"POST": self.api.post}
|
"POST": self.api.post}
|
||||||
try:
|
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:
|
except KeyError:
|
||||||
raise exceptions.ClientException("Invalid update method: %s"
|
raise exceptions.ClientException("Invalid update method: %s"
|
||||||
% method)
|
% method)
|
||||||
|
@@ -139,7 +139,7 @@ class EC2Tests(utils.TestCase):
|
|||||||
user_id = 'usr'
|
user_id = 'usr'
|
||||||
access = 'access'
|
access = 'access'
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": "",
|
"body": "",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ class EndpointTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": "",
|
"body": "",
|
||||||
})
|
})
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
|
@@ -66,7 +66,7 @@ class RoleTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": "",
|
"body": "",
|
||||||
})
|
})
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
@@ -147,62 +147,60 @@ class RoleTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_add_user_role(self):
|
def test_add_user_role(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'PUT',
|
'PUT',
|
||||||
body='null',
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
headers=self.TEST_POST_HEADERS) \
|
.AndReturn((resp, resp['body']))
|
||||||
.AndReturn((resp, None))
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.roles.add_user_role('foo', 'barrr')
|
self.client.roles.add_user_role('foo', 'barrr')
|
||||||
|
|
||||||
def test_add_user_role_tenant(self):
|
def test_add_user_role_tenant(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'PUT',
|
'PUT',
|
||||||
body='null',
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
headers=self.TEST_POST_HEADERS) \
|
.AndReturn((resp, resp['body']))
|
||||||
.AndReturn((resp, None))
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.roles.add_user_role('foo', 'barrr', '4')
|
self.client.roles.add_user_role('foo', 'barrr', '4')
|
||||||
|
|
||||||
def test_remove_user_role(self):
|
def test_remove_user_role(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'DELETE',
|
'DELETE',
|
||||||
headers=self.TEST_REQUEST_HEADERS) \
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
.AndReturn((resp, None))
|
.AndReturn((resp, resp['body']))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.roles.remove_user_role('foo', 'barrr')
|
self.client.roles.remove_user_role('foo', 'barrr')
|
||||||
|
|
||||||
def test_remove_user_role_tenant(self):
|
def test_remove_user_role_tenant(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'DELETE',
|
'DELETE',
|
||||||
headers=self.TEST_REQUEST_HEADERS) \
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
.AndReturn((resp, None))
|
.AndReturn((resp, resp['body']))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.roles.remove_user_role('foo', 'barrr', '4')
|
self.client.roles.remove_user_role('foo', 'barrr', '4')
|
||||||
|
@@ -83,7 +83,7 @@ class TenantTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": "",
|
"body": "",
|
||||||
})
|
})
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
@@ -260,31 +260,30 @@ class TenantTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_add_user(self):
|
def test_add_user(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'PUT',
|
'PUT',
|
||||||
body='null',
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
headers=self.TEST_POST_HEADERS) \
|
.AndReturn((resp, resp['body']))
|
||||||
.AndReturn((resp, None))
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.tenants.add_user('4', 'foo', 'barrr')
|
self.client.tenants.add_user('4', 'foo', 'barrr')
|
||||||
|
|
||||||
def test_remove_user(self):
|
def test_remove_user(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'DELETE',
|
'DELETE',
|
||||||
headers=self.TEST_REQUEST_HEADERS) \
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
.AndReturn((resp, None))
|
.AndReturn((resp, resp['body']))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.client.tenants.remove_user('4', 'foo', 'barrr')
|
self.client.tenants.remove_user('4', 'foo', 'barrr')
|
||||||
@@ -299,16 +298,15 @@ class TenantTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'PUT',
|
'PUT',
|
||||||
body='null',
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
headers=self.TEST_POST_HEADERS) \
|
.AndReturn((resp, resp['body']))
|
||||||
.AndReturn((resp, None))
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
# make tenant object with manager
|
# make tenant object with manager
|
||||||
@@ -327,15 +325,15 @@ class TenantTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": json.dumps({}),
|
"body": '',
|
||||||
})
|
})
|
||||||
|
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||||
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
|
||||||
'DELETE',
|
'DELETE',
|
||||||
headers=self.TEST_REQUEST_HEADERS) \
|
headers=self.TEST_REQUEST_HEADERS) \
|
||||||
.AndReturn((resp, None))
|
.AndReturn((resp, resp['body']))
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
# make tenant object with manager
|
# make tenant object with manager
|
||||||
|
@@ -18,7 +18,7 @@ class TokenTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": ""})
|
"body": ""})
|
||||||
|
|
||||||
req = httplib2.Http.request(
|
req = httplib2.Http.request(
|
||||||
|
@@ -82,7 +82,7 @@ class UserTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
resp = httplib2.Response({
|
resp = httplib2.Response({
|
||||||
"status": 200,
|
"status": 204,
|
||||||
"body": "",
|
"body": "",
|
||||||
})
|
})
|
||||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'),
|
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'),
|
||||||
|
Reference in New Issue
Block a user