def tenants(request):
    if not request.user or not request.user.is_authenticated():
        return {}

    try:
        return {'tenants': api.token_list_tenants(request, request.user.token)}
    except api_exceptions.BadRequest, e:
        messages.error(request, "Unable to retrieve tenant list from\
                                  keystone: %s" % e.message)
        return {'tenants': []}
Esempio n. 2
0
def tenants(request):
    if not request.user or not request.user.is_authenticated():
        return {}

    try:
        return {'tenants': api.token_list_tenants(request, request.user.token)}
    except api_exceptions.BadRequest, e:
        messages.error(request, "Unable to retrieve tenant list from\
                                  keystone: %s" % e.message)
        return {'tenants': []}
    def test_token_list_tenants(self):
        self.mox.StubOutWithMock(api, "auth_api")
        auth_api_mock = self.mox.CreateMockAnything()
        api.auth_api().AndReturn(auth_api_mock)

        tenants_mock = self.mox.CreateMockAnything()
        auth_api_mock.tenants = tenants_mock

        tenant_list = [
            Tenant("notTheDroid", "notTheDroid_desc", False),
            Tenant(TEST_TENANT_ID, TEST_TENANT_DESCRIPTION, True),
        ]
        tenants_mock.for_token("aToken").AndReturn(tenant_list)

        self.mox.ReplayAll()

        ret_val = api.token_list_tenants(self.request, "aToken")
        for tenant in ret_val:
            self.assertIn(tenant, tenant_list)

        self.mox.VerifyAll()
def tenants(request):
    if not request.user or not request.user.is_authenticated():
        return {}
    return {'tenants': api.token_list_tenants(request, request.user.token)}