Пример #1
0
    def test_get_all_charge(self):
        num_1, num_2 = 0, 0
        charge_list = []
        while num_1 < 3:
            account = conductor_utils.create_test_account(self)
            while num_2 < 4:
                charge = conductor_utils.create_test_charge(
                    self.context, account['user_id'])
                charge_list.append(charge)
                num_2 += 1
            num_1 += 1

        def mock_ks_client(*args):
            return {}

        with mock.patch.object(
            conductor_api, 'get_charges', conductor_utils.get_test_charges):
            with mock.patch.object(conductor_api,
                                   'get_charges_price_and_count',
                                   (conductor_utils.
                                    get_test_charges_price_and_count)):
                with mock.patch.object(ks_client, 'get_user',
                                       mock_ks_client):
                    response = self.get_json('/accounts/charges')
                    self.assertEqual(response['total_count'],
                                     len(response['charges']))
Пример #2
0
 def test_put_account_charge(self):
     body = api_utils.account_put_charge_data()
     account = conductor_utils.create_test_account(self)
     with mock.patch.object(conductor_api, 'charge_account',
                            conductor_utils.charge_test_account):
         response = self.put_json('/accounts/%s' % account.user_id, body)
         self.assertEqual(200, response.status_int)
Пример #3
0
    def test_get_all(self):
        num = 0
        account_list = []
        while num < 3:
            account = conductor_utils.create_test_account(self.context)
            account_list.append(account)
            num += 1

        with mock.patch.object(
            conductor_api, 'get_accounts', conductor_utils.get_test_accounts):
            response = self.get_json('/accounts?limit=2')
            self.assertEqual(2, len(response['accounts']))
Пример #4
0
    def test_delete_account(self):
        account = conductor_utils.create_test_account(self)

        with mock.patch.object(conductor_api, 'delete_account',
                               conductor_utils.delete_test_account):
            self.delete('/accounts/%s' % account.user_id)
            with mock.patch.object(conductor_api, 'get_account',
                                   conductor_utils.get_test_account):
                response = self.get_json('/accounts/%s' % account.user_id,
                                         expect_errors=True)
                self.assertEqual(404, response.status_int)
                self.assertEqual('application/json', response.content_type)
Пример #5
0
 def test_put_account_level(self):
     body = api_utils.account_put_level_data()
     account = conductor_utils.create_test_account(self)
     with mock.patch.object(conductor_api, 'change_account_level',
                            conductor_utils.change_test_account_level):
         def _mock_inside(*args, **kwargs):
             pass
         with mock.patch.object(sql_dbapi.Connection,
                                '_update_params', _mock_inside):
             response = self.put_json('/accounts/%s/level' %
                                      account.user_id, body)
             self.assertEqual(200, response.status_int)
Пример #6
0
    def setUp(self):
        super(TestWorker, self).setUp()

        ctx = context.make_admin_context(all_tenants=True)
        account = conductor_utils.create_test_account(ctx)
        project = conductor_utils.create_test_project(ctx,
                                                      user_id=account.user_id)
        conductor_utils.create_test_relation(ctx,
                                             user_id=account.user_id,
                                             project_id=project.project_id)

        class mock_keystone_fetcher(object):
            @classmethod
            def get_rate_user(*args):
                return account.user_id

        class mock_gnocchi_fetcher(object):
            @classmethod
            def get_resources(*args):
                return []

            @classmethod
            def get_current_consume(*args):
                return 0

            @classmethod
            def set_state(*args):
                pass

        class mock_conductor_api(object):
            @classmethod
            def get_account(*args):
                return conductor_utils.get_test_account(*args)

            @classmethod
            def update_account(*args, **kwargs):
                return conductor_utils.update_test_account(*args, **kwargs)

        tools = {
            'conductor': mock_conductor_api,
            'gnocchi_fetcher': mock_gnocchi_fetcher,
            'keystone_fetcher': mock_keystone_fetcher
        }

        with mock.patch.object(fetcher, 'KeystoneFetcher',
                               mock_keystone_fetcher):
            with mock.patch.object(fetcher, 'GnocchiFetcher',
                                   mock_gnocchi_fetcher):
                with mock.patch.object(conductor_api, 'API',
                                       mock_conductor_api):
                    self.Worker = service.Worker(ctx, project.project_id, 0,
                                                 tools)
Пример #7
0
    def test_get_one_charge(self):
        num = 0
        account = conductor_utils.create_test_account(self)
        charge_list = []
        while num < 3:
            charge = conductor_utils.create_test_charge(self.context,
                                                        account.user_id)
            charge_list.append(charge)
            num += 1

        with mock.patch.object(
            conductor_api, 'get_charges', conductor_utils.get_test_charges):
            with mock.patch.object(
                conductor_api, 'get_charges_price_and_count',
                conductor_utils.get_test_charges_price_and_count):
                    response = self.get_json('/accounts/%s/charges' %
                                             account['user_id'])
                    self.assertEqual(3, len(response['charges']))
Пример #8
0
 def test_get_one(self):
     account = conductor_utils.create_test_account(self.context)
     with mock.patch.object(conductor_api, 'get_account',
                            conductor_utils.get_test_account):
         response = self.get_json('/accounts/%s' % account.user_id)
         self.assertEqual(response['user_id'], account.user_id)