"Fossies" - the Fresh Open Source Software Archive

Member "cloudkitty-13.0.0/cloudkitty/tests/test_keystone_fetcher.py" (14 Oct 2020, 2898 Bytes) of package /linux/misc/openstack/cloudkitty-13.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_keystone_fetcher.py": 12.1.0_vs_13.0.0.

    1 # -*- coding: utf-8 -*-
    2 # Copyright 2015 Objectif Libre
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 #
   16 import unittest
   17 from unittest import mock
   18 
   19 from oslo_utils import uuidutils
   20 
   21 from cloudkitty.fetcher import keystone
   22 from cloudkitty import tests
   23 
   24 
   25 class FakeRole(object):
   26     def __init__(self, name, uuid=None):
   27         self.id = uuid if uuid else uuidutils.generate_uuid()
   28         self.name = name
   29 
   30 
   31 class FakeTenant(object):
   32     def __init__(self, id):
   33         self.id = id
   34 
   35 
   36 class FakeKeystoneClient(object):
   37 
   38     user_id = 'd89e3fee-2b92-4387-b564-63901d62e591'
   39 
   40     def __init__(self, **kwargs):
   41         pass
   42 
   43     class FakeTenants(object):
   44         @classmethod
   45         def list(cls):
   46             return [FakeTenant('f266f30b11f246b589fd266f85eeec39'),
   47                     FakeTenant('4dfb25b0947c4f5481daf7b948c14187')]
   48 
   49     class FakeRoles(object):
   50         roles_mapping = {
   51             'd89e3fee-2b92-4387-b564-63901d62e591': {
   52                 'f266f30b11f246b589fd266f85eeec39': [FakeRole('rating'),
   53                                                      FakeRole('admin')],
   54                 '4dfb25b0947c4f5481daf7b948c14187': [FakeRole('admin')]}}
   55 
   56         @classmethod
   57         def roles_for_user(cls, user_id, tenant, **kwargs):
   58             return cls.roles_mapping[user_id][tenant.id]
   59 
   60     roles = FakeRoles()
   61     tenants = FakeTenants()
   62 
   63 
   64 def Client(**kwargs):
   65     return FakeKeystoneClient(**kwargs)
   66 
   67 
   68 class KeystoneFetcherTest(tests.TestCase):
   69     def setUp(self):
   70         super(KeystoneFetcherTest, self).setUp()
   71         self.conf.set_override('backend', 'keystone', 'tenant_fetcher')
   72         self.conf.import_group('fetcher_keystone',
   73                                'cloudkitty.fetcher.keystone')
   74 
   75     @unittest.SkipTest
   76     def test_fetcher_keystone_filter_list(self):
   77         kclient = 'keystoneclient.client.Client'
   78         with mock.patch(kclient) as kclientmock:
   79             kclientmock.return_value = Client()
   80             fetcher = keystone.KeystoneFetcher()
   81             kclientmock.assert_called_once_with(
   82                 auth_url='http://127.0.0.1:5000/v2.0',
   83                 username='cloudkitty',
   84                 password='cloudkitty',
   85                 tenant_name='cloudkitty',
   86                 region_name='RegionOne')
   87             tenants = fetcher.get_tenants()
   88             self.assertEqual(['f266f30b11f246b589fd266f85eeec39'], tenants)