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))
def test_create_service_account(self, *args): params = { 'name': 'SpaceONE', 'provider': 'aws', 'data': { 'account_id': '000321654' }, 'tags': { 'tag_key': 'tag_value' }, 'domain_id': utils.generate_id('domain') } self.transaction.method = 'create' service_account_svc = ServiceAccountService( transaction=self.transaction) service_account_vo = service_account_svc.create(params.copy()) print_data(service_account_vo.to_dict(), 'test_create_service_account') ServiceAccountInfo(service_account_vo) self.assertIsInstance(service_account_vo, ServiceAccount) self.assertEqual(params['name'], service_account_vo.name) self.assertEqual(params['provider'], service_account_vo.provider) self.assertEqual(params['domain_id'], service_account_vo.domain_id) self.assertEqual(params.get('data', {}), service_account_vo.data) self.assertEqual(params.get('tags', {}), utils.tags_to_dict(service_account_vo.tags))
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)
def test_create_service_account_with_project(self, *args): params = { 'name': 'SpaceONE', 'provider': 'aws', 'data': { 'account_id': '000321654' }, 'project_id': self.project_id, 'domain_id': self.domain_id } self.transaction.method = 'create' service_account_svc = ServiceAccountService( transaction=self.transaction) service_account_vo = service_account_svc.create_service_account( params.copy()) print_data(service_account_vo.to_dict(), 'test_create_service_account_with_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'])
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)
def test_create_service_account_invalid_data(self, *args): params = { 'name': 'SpaceONE', 'provider': 'aws', 'data': { 'account_id2': '000321654' }, 'domain_id': utils.generate_id('domain') } self.transaction.method = 'create' service_account_svc = ServiceAccountService( transaction=self.transaction) with self.assertRaises(ERROR_INVALID_PARAMETER): service_account_svc.create(params)
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)
def test_list_service_accounts_by_name(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 = { 'name': service_account_vos[0].name, '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)
def test_delete_project_exist_service_account(self, *args): params = { 'name': 'SpaceONE', 'provider': 'aws', 'data': { 'account_id': '000321654' }, 'project_id': self.project_id, 'domain_id': self.domain_id } self.transaction.method = 'create' service_account_svc = ServiceAccountService( transaction=self.transaction) service_account_vo = service_account_svc.create(params.copy()) ServiceAccountInfo(service_account_vo) with self.assertRaises(ERROR_EXIST_RESOURCE): self.project_vo.delete()
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)
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')
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'])