def test_token_get_tenant(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.request.session = {'token': 'aToken'}

        self.mox.ReplayAll()

        ret_val = api.token_get_tenant(self.request, TEST_TENANT_ID)
        self.assertEqual(tenant_list[1], ret_val)

        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_token_create(self):
        self.mox.StubOutWithMock(api, "auth_api")
        auth_api_mock = self.mox.CreateMockAnything()
        api.auth_api().AndReturn(auth_api_mock)

        tokens_mock = self.mox.CreateMockAnything()
        auth_api_mock.tokens = tokens_mock

        test_token = Token(TEST_TOKEN_ID, TEST_USERNAME, TEST_TENANT_ID)

        tokens_mock.create(TEST_TENANT_ID, TEST_USERNAME, TEST_PASSWORD).AndReturn(test_token)

        self.mox.ReplayAll()

        ret_val = api.token_create(self.request, TEST_TENANT_ID, TEST_USERNAME, TEST_PASSWORD)

        self.assertEqual(test_token, ret_val)

        self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_token_get_tenant_no_tenant(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)]
        tenants_mock.for_token("aToken").AndReturn(tenant_list)

        self.request.session = {"token": "aToken"}

        self.mox.ReplayAll()

        ret_val = api.token_get_tenant(self.request, TEST_TENANT_ID)
        self.assertIsNone(ret_val)

        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_get_auth_api(self):
        settings.OPENSTACK_KEYSTONE_URL = TEST_URL
        self.mox.StubOutClassWithMocks(OSAuth, "Auth")
        OSAuth.Auth(management_url=settings.OPENSTACK_KEYSTONE_URL)

        self.mox.ReplayAll()

        self.assertIsNotNone(api.auth_api())

        self.mox.VerifyAll()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    def handle(self, request, data):
        try:
            token = api.auth_api().tokens.create("",
                                                 data['username'],
                                                 data['password'])
            info = api.token_info(token)
            request.session['token'] = token.id
            request.session['user'] = info['user']
            request.session['tenant'] = info['tenant']
            request.session['admin'] = info['admin']
            request.session['serviceCatalog'] = token.serviceCatalog
            logging.info(token.serviceCatalog)

            if request.session['admin']:
                return shortcuts.redirect('syspanel_overview')
            else:
                return shortcuts.redirect('dash_overview')

        except api_exceptions.Unauthorized as e:
            messages.error(request, 'Error authenticating: %s' % e.message)
def tenants(request):
    if not request.user or not request.user.is_authenticated():
        return {}
    return {'tenants': api.auth_api().tenants.for_token(request.user.token)}