Sort project list by name
Change-Id: I8063cffb9fb01442076e59c9288b9834fd6aaa0c Closes-Bug: #1258590
This commit is contained in:
parent
b2eab841d9
commit
71f45cd027
|
@ -62,7 +62,7 @@ def generate_test_data():
|
|||
'description': '',
|
||||
'enabled': True}
|
||||
tenant_dict_2 = {'id': uuid.uuid4().hex,
|
||||
'name': '',
|
||||
'name': 'tenant_two',
|
||||
'description': '',
|
||||
'enabled': False}
|
||||
test_data.tenant_one = Tenant(TenantManager(None),
|
||||
|
|
|
@ -107,7 +107,7 @@ def generate_test_data():
|
|||
'domain_id': domain_dict['id'],
|
||||
'enabled': True}
|
||||
project_dict_2 = {'id': uuid.uuid4().hex,
|
||||
'name': '',
|
||||
'name': 'tenant_two',
|
||||
'description': '',
|
||||
'domain_id': domain_dict['id'],
|
||||
'enabled': False}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import copy
|
||||
|
||||
import mox
|
||||
|
||||
from django import test
|
||||
|
@ -22,9 +24,9 @@ from keystoneclient import exceptions as keystone_exceptions
|
|||
from keystoneclient.v2_0 import client as client_v2
|
||||
from keystoneclient.v3 import client as client_v3
|
||||
|
||||
from .data_v2 import generate_test_data as data_v2
|
||||
from .data_v3 import generate_test_data as data_v3
|
||||
import copy
|
||||
from openstack_auth.tests.data_v2 import generate_test_data as data_v2
|
||||
from openstack_auth.tests.data_v3 import generate_test_data as data_v3
|
||||
from openstack_auth.utils import get_project_list
|
||||
|
||||
|
||||
DEFAULT_DOMAIN = settings.OPENSTACK_KEYSTONE_DEFAULT_DOMAIN
|
||||
|
@ -435,6 +437,35 @@ class OpenStackAuthTestsV2(test.TestCase):
|
|||
def test_switch_region_with_next(self, next=None):
|
||||
self.test_switch_region(next='/next_url')
|
||||
|
||||
def test_tenant_sorting(self):
|
||||
tenants = [self.data.tenant_two, self.data.tenant_one]
|
||||
expected_tenants = [self.data.tenant_one, self.data.tenant_two]
|
||||
user = self.data.user
|
||||
unscoped = self.data.unscoped_access_info
|
||||
|
||||
self.mox.StubOutWithMock(self.ks_client_module, "Client")
|
||||
self.mox.StubOutWithMock(self.keystone_client_unscoped.tenants, "list")
|
||||
|
||||
self.ks_client_module.Client(user_id=user.id,
|
||||
auth_url=settings.OPENSTACK_KEYSTONE_URL,
|
||||
token=unscoped.auth_token,
|
||||
insecure=False,
|
||||
cacert=None,
|
||||
debug=False)\
|
||||
.AndReturn(self.keystone_client_unscoped)
|
||||
self.keystone_client_unscoped.tenants.list().AndReturn(tenants)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
tenant_list = get_project_list(
|
||||
user_id=user.id,
|
||||
auth_url=settings.OPENSTACK_KEYSTONE_URL,
|
||||
token=unscoped.auth_token,
|
||||
insecure=False,
|
||||
cacert=None,
|
||||
debug=False)
|
||||
self.assertEqual(tenant_list, expected_tenants)
|
||||
|
||||
|
||||
def EndpointMetaFactory(endpoint_type):
|
||||
def endpoint_wrapper(func):
|
||||
|
@ -894,6 +925,36 @@ class OpenStackAuthTestsV3(test.TestCase):
|
|||
def test_switch_region_with_next(self, next=None):
|
||||
self.test_switch_region(next='/next_url')
|
||||
|
||||
def test_tenant_sorting(self):
|
||||
projects = [self.data.project_two, self.data.project_one]
|
||||
expected_projects = [self.data.project_one, self.data.project_two]
|
||||
user = self.data.user
|
||||
unscoped = self.data.unscoped_access_info
|
||||
|
||||
self.mox.StubOutWithMock(self.ks_client_module, "Client")
|
||||
self.mox.StubOutWithMock(self.keystone_client_unscoped.projects, "list")
|
||||
|
||||
self.ks_client_module.Client(user_id=user.id,
|
||||
auth_url=settings.OPENSTACK_KEYSTONE_URL,
|
||||
token=unscoped.auth_token,
|
||||
insecure=False,
|
||||
cacert=None,
|
||||
debug=False)\
|
||||
.AndReturn(self.keystone_client_unscoped)
|
||||
self.keystone_client_unscoped.projects.list(user=user.id) \
|
||||
.AndReturn(projects)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
project_list = get_project_list(
|
||||
user_id=user.id,
|
||||
auth_url=settings.OPENSTACK_KEYSTONE_URL,
|
||||
token=unscoped.auth_token,
|
||||
insecure=False,
|
||||
cacert=None,
|
||||
debug=False)
|
||||
self.assertEqual(project_list, expected_projects)
|
||||
|
||||
|
||||
class OpenStackAuthTestsV3WithPublicURL(OpenStackAuthTestsV3):
|
||||
"""Test V3 with settings.OPENSTACK_ENDPOINT_TYPE = 'publicURL'."""
|
||||
|
|
|
@ -154,10 +154,13 @@ def get_keystone_client():
|
|||
def get_project_list(*args, **kwargs):
|
||||
if get_keystone_version() < 3:
|
||||
client = get_keystone_client().Client(*args, **kwargs)
|
||||
return client.tenants.list()
|
||||
projects = client.tenants.list()
|
||||
else:
|
||||
auth_url = kwargs.get('auth_url', '').replace('v2.0', 'v3')
|
||||
kwargs['auth_url'] = auth_url
|
||||
client = get_keystone_client().Client(*args, **kwargs)
|
||||
client.management_url = auth_url
|
||||
return client.projects.list(user=kwargs.get('user_id'))
|
||||
projects = client.projects.list(user=kwargs.get('user_id'))
|
||||
|
||||
projects.sort(key=lambda project: project.name.lower())
|
||||
return projects
|
||||
|
|
Loading…
Reference in New Issue