def test_update_project_channel_secret(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id, secret_id='secret-xyz') name = 'Update Project Channel' data = { 'token': 'update-token', 'channel': 'update-channel' } params = { 'name': name, 'project_channel_id': project_channel_vo.project_channel_id, 'data': data, 'tags': { utils.random_string(): utils.random_string() }, 'domain_id': self.domain_id } self.transaction.method = 'update' prj_ch_svc = ProjectChannelService(transaction=self.transaction) update_project_ch_vo = prj_ch_svc.update(params.copy()) print_data(update_project_ch_vo.to_dict(), 'test_update_project_channel') ProjectChannelInfo(update_project_ch_vo) self.assertIsInstance(update_project_ch_vo, ProjectChannel) self.assertEqual(name, update_project_ch_vo.name) self.assertEqual('secret-xyz', update_project_ch_vo.secret_id) self.assertEqual({}, update_project_ch_vo.data) self.assertEqual(params['tags'], update_project_ch_vo.tags) self.assertEqual(params['domain_id'], update_project_ch_vo.domain_id)
def test_stat_project_channel(self, *args): project_channel_vos = ProjectChannelFactory.build_batch(10, domain_id=self.domain_id) list(map(lambda vo: vo.save(), project_channel_vos)) params = { 'domain_id': self.domain_id, 'query': { 'aggregate': [{ 'group': { 'keys': [{ 'key': 'project_channel_id', 'name': 'Id' }], 'fields': [{ 'operator': 'count', 'name': 'Count' }] } }, { 'sort': { 'key': 'Count', 'desc': True } }] } } self.transaction.method = 'stat' project_channel_svc = ProjectChannelService(transaction=self.transaction) values = project_channel_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_project_channel')
def test_set_subscription(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id, secret_id='secret-xyz', is_subscribe=False, subscriptions=[]) subscriptions = ['a', 'b', 'c'] params = { 'project_channel_id': project_channel_vo.project_channel_id, 'is_subscribe': True, 'subscriptions': subscriptions, 'domain_id': self.domain_id } self.transaction.method = 'set_schedule' prj_ch_svc = ProjectChannelService(transaction=self.transaction) subscription_project_ch_vo = prj_ch_svc.set_schedule(params.copy()) print_data(subscription_project_ch_vo.to_dict(), 'test_set_subscription') ProjectChannelInfo(subscription_project_ch_vo) self.assertIsInstance(subscription_project_ch_vo, ProjectChannel) self.assertEqual(subscription_project_ch_vo.is_subscribe, True) self.assertEqual(subscriptions, subscription_project_ch_vo.subscriptions)
def test_set_schedule(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id, secret_id='secret-xyz', is_scheduled=False, schedule=None) schedule = { 'day_of_week': ['MON', 'TUE'], 'start_hour': 1, 'end_hour': 23 } params = { 'project_channel_id': project_channel_vo.project_channel_id, 'is_scheduled': True, 'schedule': schedule, 'domain_id': self.domain_id } self.transaction.method = 'set_schedule' prj_ch_svc = ProjectChannelService(transaction=self.transaction) schedule_project_ch_vo = prj_ch_svc.set_schedule(params.copy()) print_data(schedule_project_ch_vo.to_dict(), 'test_set_schedule') ProjectChannelInfo(schedule_project_ch_vo) self.assertIsInstance(schedule_project_ch_vo, ProjectChannel) self.assertEqual(schedule_project_ch_vo.is_scheduled, True) self.assertEqual(schedule['day_of_week'], schedule_project_ch_vo.schedule.day_of_week) self.assertEqual(schedule['start_hour'], schedule_project_ch_vo.schedule.start_hour) self.assertEqual(schedule['end_hour'], schedule_project_ch_vo.schedule.end_hour)
def test_update_project_channel(self, *args): protocol_vo = ProtocolFactory(domain_id=self.domain_id) project_channel_vo = ProjectChannelFactory( protocol_id=protocol_vo.protocol_id, domain_id=self.domain_id) name = 'Update Project Channel' data = {'phone_number': '0109993333'} params = { 'name': name, 'project_channel_id': project_channel_vo.project_channel_id, 'data': data, 'tags': { utils.random_string(): utils.random_string() }, 'domain_id': self.domain_id } self.transaction.method = 'update' prj_ch_svc = ProjectChannelService(transaction=self.transaction) update_project_ch_vo = prj_ch_svc.update(params.copy()) print_data(update_project_ch_vo.to_dict(), 'test_update_project_channel') ProjectChannelInfo(update_project_ch_vo) self.assertIsInstance(update_project_ch_vo, ProjectChannel) self.assertEqual(name, update_project_ch_vo.name) self.assertEqual(data, update_project_ch_vo.data) self.assertEqual(params['tags'], update_project_ch_vo.tags) self.assertEqual(params['domain_id'], update_project_ch_vo.domain_id)
def test_delete_user_channel_secret(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id, secret_id='secret-abcde') params = { 'project_channel_id': project_channel_vo.project_channel_id, 'domain_id': self.domain_id } self.transaction.method = 'delete' project_channel_svc = ProjectChannelService(transaction=self.transaction) result = project_channel_svc.delete(params) self.assertIsNone(result)
def test_get_project_channel(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id) params = { 'project_channel_id': project_channel_vo.project_channel_id, 'domain_id': self.domain_id } self.transaction.method = 'get' project_channel_svc = ProjectChannelService(transaction=self.transaction) get_project_channel_vo = project_channel_svc.get(params) print_data(get_project_channel_vo.to_dict(), 'test_get_project_channel') ProjectChannelInfo(get_project_channel_vo) self.assertIsInstance(get_project_channel_vo, ProjectChannel)
def test_list_project_channels_by_name(self, *args): project_channel_vos = ProjectChannelFactory.build_batch(10, domain_id=self.domain_id) list(map(lambda vo: vo.save(), project_channel_vos)) params = { 'name': project_channel_vos[0].name, 'domain_id': self.domain_id } self.transaction.method = 'list' project_channel_svc = ProjectChannelService(transaction=self.transaction) project_channel_vos, total_count = project_channel_svc.list(params) ProjectChannelsInfo(project_channel_vos, total_count) self.assertEqual(len(project_channel_vos), 1) self.assertIsInstance(project_channel_vos[0], ProjectChannel) self.assertEqual(total_count, 1)
def test_disable_project_channel(self, *args): project_channel_vo = ProjectChannelFactory(domain_id=self.domain_id, state='ENABLED') params = { 'project_channel_id': project_channel_vo.project_channel_id, 'domain_id': self.domain_id } self.transaction.method = 'disable' project_channel_svc = ProjectChannelService(transaction=self.transaction) updated_project_channel_vo = project_channel_svc.disable(params.copy()) print_data(updated_project_channel_vo.to_dict(), 'test_disable_project_channel') ProjectChannelInfo(updated_project_channel_vo) self.assertIsInstance(updated_project_channel_vo, ProjectChannel) self.assertEqual(updated_project_channel_vo.project_channel_id, project_channel_vo.project_channel_id) self.assertEqual('DISABLED', updated_project_channel_vo.state)
def test_create_notification_with_project_channel(self, *args): protocol_vo = ProtocolFactory(domain_id=self.domain_id) project_channel_vo = ProjectChannelFactory( domain_id=self.domain_id, protocol_id=protocol_vo.protocol_id) params = { 'resource_type': 'identity.Project', 'resource_id': project_channel_vo.project_id, 'topic': 'topic-a', 'message': { 'message': 'TEST..' }, 'notification_type': 'ERROR', 'notification_level': 'LV1', 'domain_id': self.domain_id, } self.transaction.method = 'create' notification_svc = NotificationService(transaction=self.transaction) notification_svc.create(params.copy())
def test_stat_project_channel_distinct(self, *args): project_channel_vos = ProjectChannelFactory.build_batch(10, domain_id=self.domain_id) list(map(lambda vo: vo.save(), project_channel_vos)) params = { 'domain_id': self.domain_id, 'query': { 'distinct': 'project_channel_id', 'page': { 'start': 2, 'limit': 3 } } } self.transaction.method = 'stat' project_channel_svc = ProjectChannelService(transaction=self.transaction) values = project_channel_svc.stat(params) StatisticsInfo(values) print_data(values, 'test_stat_project_channel_distinct')