Merge "Fixed httplib2 mocking (bug 1050091, bug 1050097)"

This commit is contained in:
Jenkins
2012-09-29 19:13:29 +00:00
committed by Gerrit Code Review
7 changed files with 38 additions and 39 deletions

View File

@@ -91,7 +91,10 @@ class Manager(object):
methods = {"PUT": self.api.put,
"POST": self.api.post}
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)

View File

@@ -139,7 +139,7 @@ class EC2Tests(utils.TestCase):
user_id = 'usr'
access = 'access'
resp = httplib2.Response({
"status": 200,
"status": 204,
"body": "",
})

View File

@@ -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,

View File

@@ -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')

View File

@@ -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,
@@ -260,31 +260,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')
@@ -299,16 +298,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
@@ -327,15 +325,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

View File

@@ -18,7 +18,7 @@ class TokenTests(utils.TestCase):
def test_delete(self):
resp = httplib2.Response({
"status": 200,
"status": 204,
"body": ""})
req = httplib2.Http.request(

View File

@@ -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'),