Beispiel #1
0
    def test_list_service_accounts_by_tag(self, *args):
        ServiceAccountFactory(tags=[{
            'key': 'tag_key_1',
            'value': 'tag_value_1'
        }],
                              domain_id=self.domain_id)
        service_account_vos = ServiceAccountFactory.build_batch(
            9, project=None, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), service_account_vos))

        params = {
            'query': {
                'filter': [{
                    'k': 'tags.tag_key_1',
                    'v': 'tag_value_1',
                    'o': 'eq'
                }]
            },
            'domain_id': self.domain_id
        }

        service_account_svc = ServiceAccountService()
        service_accounts_vos, total_count = service_account_svc.list(params)

        ServiceAccountsInfo(service_account_vos, total_count)

        self.assertEqual(len(service_accounts_vos), 1)
        self.assertIsInstance(service_accounts_vos[0], ServiceAccount)
        self.assertEqual(total_count, 1)
Beispiel #2
0
    def test_update_service_account(self, *args):
        new_service_account_vo = ServiceAccountFactory(
            domain_id=self.domain_id)
        params = {
            'service_account_id': new_service_account_vo.service_account_id,
            'name': 'Update Account Name',
            'data': {
                'account_id': 'update-1234'
            },
            'tags': {
                'tag_key': 'tag_value'
            },
            'domain_id': self.domain_id
        }

        self.transaction.method = 'update'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        service_account_vo = service_account_svc.update(params.copy())

        print_data(service_account_vo.to_dict(), 'test_update_service_account')
        ServiceAccountInfo(service_account_vo)

        self.assertIsInstance(service_account_vo, ServiceAccount)
        self.assertEqual(new_service_account_vo.service_account_id,
                         service_account_vo.service_account_id)
        self.assertEqual(params['name'], service_account_vo.name)
        self.assertEqual(params['data'], service_account_vo.data)
        self.assertEqual(params['tags'],
                         utils.tags_to_dict(service_account_vo.tags))
Beispiel #3
0
    def test_list_service_accounts_by_project(self, *args):
        service_account_vos = ServiceAccountFactory.build_batch(
            3, project=self.project_vo, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), service_account_vos))

        service_account_vos = ServiceAccountFactory.build_batch(
            7, project=None, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), service_account_vos))

        params = {'project_id': self.project_id, 'domain_id': self.domain_id}

        service_account_svc = ServiceAccountService()
        service_accounts_vos, total_count = service_account_svc.list(params)

        ServiceAccountsInfo(service_account_vos, total_count)

        self.assertEqual(len(service_accounts_vos), 3)
        self.assertIsInstance(service_accounts_vos[0], ServiceAccount)
        self.assertEqual(total_count, 3)
Beispiel #4
0
    def test_delete_service_account(self, *args):
        new_service_account_vo = ServiceAccountFactory(
            domain_id=self.domain_id)
        params = {
            'service_account_id': new_service_account_vo.service_account_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'delete'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        result = service_account_svc.delete(params)

        self.assertIsNone(result)
Beispiel #5
0
    def test_get_service_account(self, *args):
        new_service_account_vo = ServiceAccountFactory(
            domain_id=self.domain_id)
        params = {
            'service_account_id': new_service_account_vo.service_account_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'get'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        service_account_vo = service_account_svc.get(params)

        print_data(service_account_vo.to_dict(), 'test_get_service_account')
        ServiceAccountInfo(service_account_vo)

        self.assertIsInstance(service_account_vo, ServiceAccount)
Beispiel #6
0
    def test_release_service_account_project(self, *args):
        new_service_account_vo = ServiceAccountFactory(
            domain_id=self.domain_id, project=self.project_vo)
        params = {
            'service_account_id': new_service_account_vo.service_account_id,
            'release_project': True,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'update'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        service_account_vo = service_account_svc.update(params.copy())

        print_data(service_account_vo.to_dict(),
                   'test_release_service_account_project')
        ServiceAccountInfo(service_account_vo)

        self.assertIsInstance(service_account_vo, ServiceAccount)
        self.assertIsNone(service_account_vo.project)
Beispiel #7
0
    def test_stat_service_account(self, *args):
        service_account_vos = ServiceAccountFactory.build_batch(
            10, project=None, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), service_account_vos))

        params = {
            'domain_id': self.domain_id,
            'query': {
                'aggregate': [{
                    'group': {
                        'keys': [{
                            'key': 'service_account_id',
                            'name': 'Id'
                        }],
                        'fields': [{
                            'operator': 'count',
                            'name': 'Count'
                        }, {
                            'key': 'project.project_id',
                            'name': 'project_count',
                            'operator': 'size'
                        }]
                    }
                }, {
                    'sort': {
                        'key': 'Count',
                        'desc': True
                    }
                }]
            }
        }

        self.transaction.method = 'stat'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        values = service_account_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_service_account')
Beispiel #8
0
    def test_update_service_account_project(self, *args):
        new_service_account_vo = ServiceAccountFactory(
            domain_id=self.domain_id)
        params = {
            'service_account_id': new_service_account_vo.service_account_id,
            'project_id': self.project_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'update'
        service_account_svc = ServiceAccountService(
            transaction=self.transaction)
        service_account_vo = service_account_svc.update_service_account(
            params.copy())

        print_data(service_account_vo.to_dict(),
                   'test_update_service_account_project')
        ServiceAccountInfo(service_account_vo)

        self.assertIsInstance(service_account_vo, ServiceAccount)
        self.assertIsInstance(service_account_vo.project, Project)
        self.assertEqual(service_account_vo.project.project_id,
                         params['project_id'])
Beispiel #9
0
 def list_service_accounts(self, params):
     return ServiceAccountFactory.build_batch(10, **params), 10
Beispiel #10
0
 def get_service_account(self, params):
     return ServiceAccountFactory(**params)
Beispiel #11
0
    def update(self, params):
        params = copy.deepcopy(params)
        if 'tags' in params:
            params['tags'] = utils.dict_to_tags(params['tags'])

        return ServiceAccountFactory(**params)
Beispiel #12
0
 def update(self, params):
     return ServiceAccountFactory(**params)