more pep8 cleanup
This commit is contained in:
@@ -109,7 +109,9 @@ class HTTPClient(httplib2.Http):
|
||||
request_kwargs['headers']['Content-Type'] = 'application/json'
|
||||
request_kwargs['body'] = json.dumps(kwargs['body'])
|
||||
|
||||
resp, body = super(HTTPClient, self).request(url, method, **request_kwargs)
|
||||
resp, body = super(HTTPClient, self).request(url,
|
||||
method,
|
||||
**request_kwargs)
|
||||
|
||||
self.http_log((url, method,), request_kwargs, resp, body)
|
||||
|
||||
|
@@ -21,7 +21,6 @@ Command-line interface to the OpenStack Keystone API.
|
||||
import argparse
|
||||
import httplib2
|
||||
import os
|
||||
import prettytable
|
||||
import sys
|
||||
|
||||
from keystoneclient import exceptions as exc
|
||||
@@ -171,9 +170,11 @@ class OpenStackIdentityShell(object):
|
||||
"via --url or via"
|
||||
"env[KEYSTONE_URL")
|
||||
|
||||
self.cs = self.get_api_class(options.version) \
|
||||
(user, apikey, projectid, url,
|
||||
region_name=region_name)
|
||||
self.cs = self.get_api_class(options.version)(user,
|
||||
apikey,
|
||||
projectid,
|
||||
url,
|
||||
region_name=region_name)
|
||||
|
||||
try:
|
||||
self.cs.authenticate()
|
||||
|
@@ -1,2 +1 @@
|
||||
from keystoneclient.v2_0.client import Client
|
||||
|
||||
|
@@ -32,7 +32,9 @@ class ServiceManager(base.ManagerWithFind):
|
||||
return self._get("/OS-KSADM/services/%s" % id, "OS-KSADM:service")
|
||||
|
||||
def create(self, name, service_type, description):
|
||||
body = {"OS-KSADM:service": {'name': name, 'type':service_type, 'description': description}}
|
||||
body = {"OS-KSADM:service": {'name': name,
|
||||
'type': service_type,
|
||||
'description': description}}
|
||||
return self._create("/OS-KSADM/services", body, "OS-KSADM:service")
|
||||
|
||||
def delete(self, id):
|
||||
|
@@ -15,13 +15,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import getpass
|
||||
import os
|
||||
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient import utils
|
||||
from keystoneclient.v2_0 import client
|
||||
|
||||
|
||||
CLIENT_CLASS = client.Client
|
||||
|
||||
|
@@ -55,11 +55,12 @@ class TenantManager(base.ManagerWithFind):
|
||||
"""
|
||||
return self._list("/tenants", "tenants")
|
||||
|
||||
def update(self, tenant_id, tenant_name=None, description=None, enabled=None):
|
||||
def update(self, tenant_id, tenant_name=None, description=None,
|
||||
enabled=None):
|
||||
"""
|
||||
update a tenant with a new name and description
|
||||
"""
|
||||
body = {"tenant": {'id': tenant_id }}
|
||||
body = {"tenant": {'id': tenant_id}}
|
||||
if tenant_name is not None:
|
||||
body['tenant']['name'] = tenant_name
|
||||
if enabled is not None:
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from keystoneclient import base
|
||||
|
||||
|
||||
class Token(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Token %s>" % self._info
|
||||
@@ -16,6 +17,7 @@ class Token(base.Resource):
|
||||
def tenant(self):
|
||||
return self._info['token'].get('tenant', None)
|
||||
|
||||
|
||||
class TokenManager(base.ManagerWithFind):
|
||||
resource_class = Token
|
||||
|
||||
|
@@ -2,7 +2,6 @@ import httplib2
|
||||
import mock
|
||||
|
||||
from keystoneclient import client
|
||||
from keystoneclient import exceptions
|
||||
from tests import utils
|
||||
|
||||
|
||||
@@ -37,7 +36,8 @@ class ClientTest(utils.TestCase):
|
||||
"X-Auth-Project-Id": "project_id",
|
||||
"User-Agent": cl.USER_AGENT,
|
||||
}
|
||||
mock_request.assert_called_with("http://127.0.0.1:5000/hi?fresh=1234",
|
||||
mock_request.assert_called_with("http://127.0.0.1:5000/"
|
||||
"hi?fresh=1234",
|
||||
"GET", headers=headers)
|
||||
# Automatic JSON parsing
|
||||
self.assertEqual(body, {"hi": "there"})
|
||||
@@ -60,4 +60,3 @@ class ClientTest(utils.TestCase):
|
||||
headers=headers, body='[1, 2, 3]')
|
||||
|
||||
test_post_call()
|
||||
|
||||
|
@@ -7,87 +7,88 @@ from tests import utils
|
||||
# Do not edit this structure. Instead, grab the latest from there.
|
||||
|
||||
SERVICE_CATALOG = {
|
||||
"access":{
|
||||
"token":{
|
||||
"id":"ab48a9efdfedb23ty3494",
|
||||
"expires":"2010-11-01T03:32:15-05:00",
|
||||
"tenant":{
|
||||
"access": {
|
||||
"token": {
|
||||
"id": "ab48a9efdfedb23ty3494",
|
||||
"expires": "2010-11-01T03:32:15-05:00",
|
||||
"tenant": {
|
||||
"id": "345",
|
||||
"name": "My Project"
|
||||
}
|
||||
},
|
||||
"user":{
|
||||
"id":"123",
|
||||
"name":"jqsmith",
|
||||
"roles":[{
|
||||
"id":"234",
|
||||
"name":"compute:admin"
|
||||
"user": {
|
||||
"id": "123",
|
||||
"name": "jqsmith",
|
||||
"roles": [{
|
||||
"id": "234",
|
||||
"name": "compute:admin"
|
||||
},
|
||||
{
|
||||
"id":"235",
|
||||
"name":"object-store:admin",
|
||||
"tenantId":"1"
|
||||
"id": "235",
|
||||
"name": "object-store:admin",
|
||||
"tenantId": "1"
|
||||
}
|
||||
],
|
||||
"roles_links":[]
|
||||
"roles_links": []
|
||||
},
|
||||
"serviceCatalog":[{
|
||||
"name":"Cloud Servers",
|
||||
"type":"compute",
|
||||
"endpoints":[{
|
||||
"tenantId":"1",
|
||||
"publicURL":"https://compute.north.host/v1/1234",
|
||||
"internalURL":"https://compute.north.host/v1/1234",
|
||||
"region":"North",
|
||||
"versionId":"1.0",
|
||||
"versionInfo":"https://compute.north.host/v1.0/",
|
||||
"versionList":"https://compute.north.host/"
|
||||
"serviceCatalog": [{
|
||||
"name": "Cloud Servers",
|
||||
"type": "compute",
|
||||
"endpoints": [{
|
||||
"tenantId": "1",
|
||||
"publicURL": "https://compute.north.host/v1/1234",
|
||||
"internalURL": "https://compute.north.host/v1/1234",
|
||||
"region": "North",
|
||||
"versionId": "1.0",
|
||||
"versionInfo": "https://compute.north.host/v1.0/",
|
||||
"versionList": "https://compute.north.host/"
|
||||
},
|
||||
{
|
||||
"tenantId":"2",
|
||||
"publicURL":"https://compute.north.host/v1.1/3456",
|
||||
"internalURL":"https://compute.north.host/v1.1/3456",
|
||||
"region":"North",
|
||||
"versionId":"1.1",
|
||||
"versionInfo":"https://compute.north.host/v1.1/",
|
||||
"versionList":"https://compute.north.host/"
|
||||
"tenantId": "2",
|
||||
"publicURL": "https://compute.north.host/v1.1/3456",
|
||||
"internalURL": "https://compute.north.host/v1.1/3456",
|
||||
"region": "North",
|
||||
"versionId": "1.1",
|
||||
"versionInfo": "https://compute.north.host/v1.1/",
|
||||
"versionList": "https://compute.north.host/"
|
||||
}
|
||||
],
|
||||
"endpoints_links":[]
|
||||
"endpoints_links": []
|
||||
},
|
||||
{
|
||||
"name":"Cloud Files",
|
||||
"type":"object-store",
|
||||
"endpoints":[{
|
||||
"tenantId":"11",
|
||||
"publicURL":"https://compute.north.host/v1/blah-blah",
|
||||
"internalURL":"https://compute.north.host/v1/blah-blah",
|
||||
"region":"South",
|
||||
"versionId":"1.0",
|
||||
"versionInfo":"uri",
|
||||
"versionList":"uri"
|
||||
},
|
||||
{
|
||||
"tenantId":"2",
|
||||
"publicURL":"https://compute.north.host/v1.1/blah-blah",
|
||||
"internalURL":"https://compute.north.host/v1.1/blah-blah",
|
||||
"region":"South",
|
||||
"versionId":"1.1",
|
||||
"versionInfo":"https://compute.north.host/v1.1/",
|
||||
"versionList":"https://compute.north.host/"
|
||||
}
|
||||
"name": "Cloud Files",
|
||||
"type": "object-store",
|
||||
"endpoints": [{
|
||||
"tenantId": "11",
|
||||
"publicURL": "https://compute.north.host/v1/blah-blah",
|
||||
"internalURL": "https://compute.north.host/v1/blah-blah",
|
||||
"region": "South",
|
||||
"versionId": "1.0",
|
||||
"versionInfo": "uri",
|
||||
"versionList": "uri"
|
||||
},
|
||||
{
|
||||
"tenantId": "2",
|
||||
"publicURL": "https://compute.north.host/v1.1/blah-blah",
|
||||
"internalURL": "https://compute.north.host/v1.1/blah-blah",
|
||||
"region": "South",
|
||||
"versionId": "1.1",
|
||||
"versionInfo": "https://compute.north.host/v1.1/",
|
||||
"versionList": "https://compute.north.host/"
|
||||
}
|
||||
],
|
||||
"endpoints_links":[{
|
||||
"rel":"next",
|
||||
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
|
||||
}
|
||||
"rel":"next",
|
||||
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"serviceCatalog_links":[{
|
||||
"rel":"next",
|
||||
"href":"https://identity.host/v2.0/endpoints?session=2hfh8Ar&marker=2"
|
||||
}
|
||||
"serviceCatalog_links": [{
|
||||
"rel": "next",
|
||||
"href": ("https://identity.host/v2.0/endpoints?"
|
||||
"session=2hfh8Ar&marker=2")
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
}
|
||||
|
||||
def test_authenticate_failure(self):
|
||||
self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = 'bad_key'
|
||||
self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = \
|
||||
'bad_key'
|
||||
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
|
||||
resp = httplib2.Response({
|
||||
"status": 401,
|
||||
@@ -72,7 +73,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
project_id=self.TEST_TENANT,
|
||||
auth_url=self.TEST_URL)
|
||||
|
||||
|
||||
def test_auth_redirect(self):
|
||||
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
|
||||
correct_response = json.dumps(self.TEST_RESPONSE_DICT)
|
||||
@@ -154,7 +154,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.auth_token,
|
||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||
self.assertFalse(cs.service_catalog.catalog.has_key('serviceCatalog'))
|
||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||
|
||||
def test_authenticate_success_token_scoped(self):
|
||||
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
||||
@@ -204,4 +204,4 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.auth_token,
|
||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||
self.assertFalse(cs.service_catalog.catalog.has_key('serviceCatalog'))
|
||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||
|
@@ -12,11 +12,11 @@ class RoleTests(utils.TestCase):
|
||||
super(RoleTests, self).setUp()
|
||||
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_ROLES = {
|
||||
"roles": {
|
||||
"values": [
|
||||
@@ -33,14 +33,15 @@ class RoleTests(utils.TestCase):
|
||||
}
|
||||
|
||||
def test_create(self):
|
||||
req_body = {"role": {"name": "sysadmin",}}
|
||||
resp_body = {"role": {"name": "sysadmin", "id": 3,}}
|
||||
req_body = {"role": {"name": "sysadmin"}}
|
||||
resp_body = {"role": {"name": "sysadmin", "id": 3}}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(resp_body),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/roles'),
|
||||
'POST',
|
||||
body=json.dumps(req_body),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
@@ -57,7 +58,8 @@ class RoleTests(utils.TestCase):
|
||||
"status": 200,
|
||||
"body": ""
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles/1'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/roles/1'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -68,9 +70,11 @@ class RoleTests(utils.TestCase):
|
||||
def test_get(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({'role':self.TEST_ROLES['roles']['values'][0]}),
|
||||
"body": json.dumps({'role':
|
||||
self.TEST_ROLES['roles']['values'][0]}),
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles/1?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/roles/1?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -81,14 +85,14 @@ class RoleTests(utils.TestCase):
|
||||
self.assertEqual(role.id, 1)
|
||||
self.assertEqual(role.name, 'admin')
|
||||
|
||||
|
||||
def test_list(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(self.TEST_ROLES),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/roles?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/roles?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -96,4 +100,3 @@ class RoleTests(utils.TestCase):
|
||||
|
||||
role_list = self.client.roles.list()
|
||||
[self.assertTrue(isinstance(r, roles.Role)) for r in role_list]
|
||||
|
||||
|
@@ -12,34 +12,34 @@ class ServiceTests(utils.TestCase):
|
||||
super(ServiceTests, self).setUp()
|
||||
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
self.TEST_SERVICES = {
|
||||
"OS-KSADM:services": {
|
||||
"values": [
|
||||
{
|
||||
"name": "nova",
|
||||
"type": "compute",
|
||||
"description": "Nova-compatible service.",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"name": "keystone",
|
||||
"type": "identity",
|
||||
"description": "Keystone-compatible service.",
|
||||
"id": 2
|
||||
}
|
||||
]
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_SERVICES = {"OS-KSADM:services": {
|
||||
"values": [
|
||||
{
|
||||
"name": "nova",
|
||||
"type": "compute",
|
||||
"description": "Nova-compatible service.",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"name": "keystone",
|
||||
"type": "identity",
|
||||
"description": ("Keystone-compatible "
|
||||
"service."),
|
||||
"id": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def test_create(self):
|
||||
req_body = {"OS-KSADM:service": {"name": "swift",
|
||||
"type": "object-store",
|
||||
"description": "Swift-compatible service.",}}
|
||||
"description": "Swift-compatible service."}}
|
||||
resp_body = {"OS-KSADM:service": {"name": "swift",
|
||||
"type": "object-store",
|
||||
"description": "Swift-compatible service.",
|
||||
@@ -49,16 +49,18 @@ class ServiceTests(utils.TestCase):
|
||||
"body": json.dumps(resp_body),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/services'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/services'),
|
||||
'POST',
|
||||
body=json.dumps(req_body),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
service = self.client.services.create(req_body['OS-KSADM:service']['name'],
|
||||
req_body['OS-KSADM:service']['type'],
|
||||
req_body['OS-KSADM:service']['description'])
|
||||
service = self.client.services.create(
|
||||
req_body['OS-KSADM:service']['name'],
|
||||
req_body['OS-KSADM:service']['type'],
|
||||
req_body['OS-KSADM:service']['description'])
|
||||
self.assertTrue(isinstance(service, services.Service))
|
||||
self.assertEqual(service.id, 3)
|
||||
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
|
||||
@@ -68,7 +70,8 @@ class ServiceTests(utils.TestCase):
|
||||
"status": 200,
|
||||
"body": ""
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/services/1'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/services/1'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -79,9 +82,11 @@ class ServiceTests(utils.TestCase):
|
||||
def test_get(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({'OS-KSADM:service':self.TEST_SERVICES['OS-KSADM:services']['values'][0]}),
|
||||
"body": json.dumps({'OS-KSADM:service':
|
||||
self.TEST_SERVICES['OS-KSADM:services']['values'][0]}),
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/services/1?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/services/1?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -93,19 +98,19 @@ class ServiceTests(utils.TestCase):
|
||||
self.assertEqual(service.name, 'nova')
|
||||
self.assertEqual(service.type, 'compute')
|
||||
|
||||
|
||||
def test_list(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(self.TEST_SERVICES),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/services?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/services?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
service_list = self.client.services.list()
|
||||
[self.assertTrue(isinstance(r, services.Service)) for r in service_list]
|
||||
|
||||
[self.assertTrue(isinstance(r, services.Service)) \
|
||||
for r in service_list]
|
||||
|
@@ -12,45 +12,44 @@ class TenantTests(utils.TestCase):
|
||||
super(TenantTests, self).setUp()
|
||||
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
self.TEST_TENANTS = {
|
||||
"tenants": {
|
||||
"values": [
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "A description change!",
|
||||
"name": "invisible_to_admin",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "None",
|
||||
"name": "demo",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "None",
|
||||
"name": "admin",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"links": []
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_TENANTS = {"tenants": {
|
||||
"values": [
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "A description change!",
|
||||
"name": "invisible_to_admin",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "None",
|
||||
"name": "demo",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"enabled": True,
|
||||
"description": "None",
|
||||
"name": "admin",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"links": []
|
||||
}
|
||||
}
|
||||
|
||||
def test_create(self):
|
||||
req_body = {"tenant": {"name": "tenantX",
|
||||
"description": "Like tenant 9, but better.",
|
||||
"enabled": True,}}
|
||||
"enabled": True}}
|
||||
resp_body = {"tenant": {"name": "tenantX",
|
||||
"enabled": True,
|
||||
"id": 4,
|
||||
"description": "Like tenant 9, but better.",}}
|
||||
"description": "Like tenant 9, but better."}}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(resp_body),
|
||||
@@ -76,7 +75,8 @@ class TenantTests(utils.TestCase):
|
||||
"status": 200,
|
||||
"body": ""
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/tenants/1'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/1'),
|
||||
'DELETE',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -87,9 +87,11 @@ class TenantTests(utils.TestCase):
|
||||
def test_get(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({'tenant':self.TEST_TENANTS['tenants']['values'][2]}),
|
||||
"body": json.dumps({'tenant':
|
||||
self.TEST_TENANTS['tenants']['values'][2]}),
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/tenants/1?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/1?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -100,14 +102,14 @@ class TenantTests(utils.TestCase):
|
||||
self.assertEqual(t.id, 1)
|
||||
self.assertEqual(t.name, 'admin')
|
||||
|
||||
|
||||
def test_list(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(self.TEST_TENANTS),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/tenants?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -116,22 +118,22 @@ class TenantTests(utils.TestCase):
|
||||
tenant_list = self.client.tenants.list()
|
||||
[self.assertTrue(isinstance(t, tenants.Tenant)) for t in tenant_list]
|
||||
|
||||
|
||||
def test_update(self):
|
||||
req_body = {"tenant": {"id": 4,
|
||||
"name": "tenantX",
|
||||
"description": "I changed you!",
|
||||
"enabled": False,}}
|
||||
"enabled": False}}
|
||||
resp_body = {"tenant": {"name": "tenantX",
|
||||
"enabled": False,
|
||||
"id": 4,
|
||||
"description": "I changed you!",}}
|
||||
"description": "I changed you!"}}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(resp_body),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/tenants/4'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4'),
|
||||
'PUT',
|
||||
body=json.dumps(req_body),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
|
@@ -1,27 +1,27 @@
|
||||
import urlparse
|
||||
import json
|
||||
#import urlparse
|
||||
#import json
|
||||
|
||||
import httplib2
|
||||
#import httplib2
|
||||
|
||||
from keystoneclient.v2_0 import tokens
|
||||
#from keystoneclient.v2_0 import tokens
|
||||
from tests import utils
|
||||
|
||||
|
||||
class TokenTests(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(ServiceTests, self).setUp()
|
||||
#super(ServiceTests, self).setUp()
|
||||
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
'''
|
||||
def test_create(self):
|
||||
req_body = {"OS-KSADM:service": {"name": "swift",
|
||||
"type": "object-store",
|
||||
"description": "Swift-compatible service.",}}
|
||||
"description": "Swift-compatible service."}}
|
||||
resp_body = {"OS-KSADM:service": {"name": "swift",
|
||||
"type": "object-store",
|
||||
"description": "Swift-compatible service.",
|
||||
@@ -31,16 +31,18 @@ class TokenTests(utils.TestCase):
|
||||
"body": json.dumps(resp_body),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/OS-KSADM/services'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/OS-KSADM/services'),
|
||||
'POST',
|
||||
body=json.dumps(req_body),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
service = self.client.services.create(req_body['OS-KSADM:service']['name'],
|
||||
req_body['OS-KSADM:service']['type'],
|
||||
req_body['OS-KSADM:service']['description'])
|
||||
service = self.client.services.create(
|
||||
req_body['OS-KSADM:service']['name'],
|
||||
req_body['OS-KSADM:service']['type'],
|
||||
req_body['OS-KSADM:service']['description'])
|
||||
self.assertTrue(isinstance(service, services.Service))
|
||||
self.assertEqual(service.id, 3)
|
||||
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
|
||||
|
@@ -12,11 +12,11 @@ class UserTests(utils.TestCase):
|
||||
super(UserTests, self).setUp()
|
||||
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': 'aToken',
|
||||
'User-Agent': 'python-keystoneclient',}
|
||||
'User-Agent': 'python-keystoneclient'}
|
||||
self.TEST_USERS = {
|
||||
"users": {
|
||||
"values": [
|
||||
@@ -41,7 +41,7 @@ class UserTests(utils.TestCase):
|
||||
"password": "test",
|
||||
"tenantId": 2,
|
||||
"email": "test@example.com",
|
||||
"enabled": True,}}
|
||||
"enabled": True}}
|
||||
resp_body = {"user": {"name": "gabriel",
|
||||
"enabled": True,
|
||||
"tenantId": 2,
|
||||
@@ -69,6 +69,7 @@ class UserTests(utils.TestCase):
|
||||
self.assertEqual(user.id, 3)
|
||||
self.assertEqual(user.name, "gabriel")
|
||||
self.assertEqual(user.email, "test@example.com")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_delete(self):
|
||||
resp = httplib2.Response({
|
||||
@@ -82,13 +83,15 @@ class UserTests(utils.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.client.users.delete(1)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_get(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps({'user':self.TEST_USERS['users']['values'][0]}),
|
||||
"body": json.dumps({'user': self.TEST_USERS['users']['values'][0]})
|
||||
})
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/1?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -98,6 +101,7 @@ class UserTests(utils.TestCase):
|
||||
self.assertTrue(isinstance(u, users.User))
|
||||
self.assertEqual(u.id, 1)
|
||||
self.assertEqual(u.name, 'admin')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_list(self):
|
||||
resp = httplib2.Response({
|
||||
@@ -105,7 +109,8 @@ class UserTests(utils.TestCase):
|
||||
"body": json.dumps(self.TEST_USERS),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users?fresh=1234'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users?fresh=1234'),
|
||||
'GET',
|
||||
headers=self.TEST_REQUEST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
@@ -113,6 +118,7 @@ class UserTests(utils.TestCase):
|
||||
|
||||
user_list = self.client.users.list()
|
||||
[self.assertTrue(isinstance(u, users.User)) for u in user_list]
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_update(self):
|
||||
req_1 = {"user": {"password": "swordfish", "id": 2}}
|
||||
@@ -120,12 +126,13 @@ class UserTests(utils.TestCase):
|
||||
req_3 = {"user": {"tenantId": 1, "id": 2}}
|
||||
req_4 = {"user": {"enabled": False, "id": 2}}
|
||||
# Keystone basically echoes these back... including the password :-/
|
||||
resp_1 = httplib2.Response({"status": 200, "body": json.dumps(req_1),})
|
||||
resp_2 = httplib2.Response({"status": 200, "body": json.dumps(req_2),})
|
||||
resp_3 = httplib2.Response({"status": 200, "body": json.dumps(req_3),})
|
||||
resp_4 = httplib2.Response({"status": 200, "body": json.dumps(req_3),})
|
||||
resp_1 = httplib2.Response({"status": 200, "body": json.dumps(req_1)})
|
||||
resp_2 = httplib2.Response({"status": 200, "body": json.dumps(req_2)})
|
||||
resp_3 = httplib2.Response({"status": 200, "body": json.dumps(req_3)})
|
||||
resp_4 = httplib2.Response({"status": 200, "body": json.dumps(req_3)})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/2/password'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/2/password'),
|
||||
'PUT',
|
||||
body=json.dumps(req_1),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
@@ -135,12 +142,14 @@ class UserTests(utils.TestCase):
|
||||
body=json.dumps(req_2),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp_2, resp_2['body']))
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/2/tenant'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/2/tenant'),
|
||||
'PUT',
|
||||
body=json.dumps(req_3),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp_3, resp_3['body']))
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/2/enabled'),
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/users/2/enabled'),
|
||||
'PUT',
|
||||
body=json.dumps(req_4),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
@@ -151,3 +160,5 @@ class UserTests(utils.TestCase):
|
||||
user = self.client.users.update_email(2, 'gabriel@example.com')
|
||||
user = self.client.users.update_tenant(2, 1)
|
||||
user = self.client.users.update_enabled(2, False)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
Reference in New Issue
Block a user