Example #1
0
    def test_stat_user_channel(self, *args):
        user_channel_vos = UserChannelFactory.build_batch(10, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), user_channel_vos))

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

        self.transaction.method = 'stat'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        values = user_channel_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_user_channel')
Example #2
0
    def test_update_user_channel_secret(self, *args):
        user_channel_vo = UserChannelFactory(domain_id=self.domain_id, secret_id='secret-xyz')
        name = 'Update User Channel'
        data = {
            'token': 'update-token',
            'channel': 'update-channel'
        }

        params = {
            'name': name,
            'user_channel_id': user_channel_vo.user_channel_id,
            'data': data,
            'tags': {
                utils.random_string(): utils.random_string()
            },
            'domain_id': self.domain_id
        }

        self.transaction.method = 'update'
        user_ch_svc = UserChannelService(transaction=self.transaction)
        update_user_ch_vo = user_ch_svc.update(params.copy())

        print_data(update_user_ch_vo.to_dict(), 'test_update_user_channel_secret')
        UserChannelInfo(update_user_ch_vo)

        self.assertIsInstance(update_user_ch_vo, UserChannel)
        self.assertEqual(name, update_user_ch_vo.name)
        self.assertEqual('secret-xyz', update_user_ch_vo.secret_id)
        self.assertEqual({}, update_user_ch_vo.data)
        self.assertEqual(params['tags'], update_user_ch_vo.tags)
        self.assertEqual(params['domain_id'], update_user_ch_vo.domain_id)
    def test_set_schedule(self, *args):
        user_channel_vo = UserChannelFactory(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 = {
            'user_channel_id': user_channel_vo.user_channel_id,
            'is_scheduled': True,
            'schedule': schedule,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'set_schedule'
        user_ch_svc = UserChannelService(transaction=self.transaction)
        schedule_user_ch_vo = user_ch_svc.set_schedule(params.copy())

        print_data(schedule_user_ch_vo.to_dict(), 'test_set_schedule')
        UserChannelInfo(schedule_user_ch_vo)

        self.assertIsInstance(schedule_user_ch_vo, UserChannel)
        self.assertEqual(schedule_user_ch_vo.is_scheduled, True)
        self.assertEqual(schedule['day_of_week'],
                         schedule_user_ch_vo.schedule.day_of_week)
        self.assertEqual(schedule['start_hour'],
                         schedule_user_ch_vo.schedule.start_hour)
        self.assertEqual(schedule['end_hour'],
                         schedule_user_ch_vo.schedule.end_hour)
Example #4
0
    def test_delete_user_channel_secret(self, *args):
        user_channel_vo = UserChannelFactory(domain_id=self.domain_id, secret_id='secret-abcde')
        params = {
            'user_channel_id': user_channel_vo.user_channel_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'delete'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        result = user_channel_svc.delete(params)

        self.assertIsNone(result)
Example #5
0
    def test_get_user_channel(self, *args):
        user_channel_vo = UserChannelFactory(domain_id=self.domain_id)
        params = {
            'user_channel_id': user_channel_vo.user_channel_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'get'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        get_user_channel_vo = user_channel_svc.get(params)

        print_data(get_user_channel_vo.to_dict(), 'test_get_user_channel')
        UserChannelInfo(get_user_channel_vo)

        self.assertIsInstance(get_user_channel_vo, UserChannel)
Example #6
0
    def test_list_user_channels_by_name(self, *args):
        user_channel_vos = UserChannelFactory.build_batch(10, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), user_channel_vos))

        params = {
            'name': user_channel_vos[0].name,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'list'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        user_channel_vos, total_count = user_channel_svc.list(params)
        UserChannelsInfo(user_channel_vos, total_count)

        self.assertEqual(len(user_channel_vos), 1)
        self.assertIsInstance(user_channel_vos[0], UserChannel)
        self.assertEqual(total_count, 1)
Example #7
0
    def test_disable_user_channel(self, *args):
        user_channel_vo = UserChannelFactory(domain_id=self.domain_id, state='ENABLED')
        params = {
            'user_channel_id': user_channel_vo.user_channel_id,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'disable'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        updated_user_channel_vo = user_channel_svc.disable(params.copy())

        print_data(updated_user_channel_vo.to_dict(), 'test_disable_project_channel')
        UserChannelInfo(updated_user_channel_vo)

        self.assertIsInstance(updated_user_channel_vo, UserChannel)
        self.assertEqual(updated_user_channel_vo.user_channel_id, user_channel_vo.user_channel_id)
        self.assertEqual('DISABLED', updated_user_channel_vo.state)
    def test_create_notification_with_user_channel(self, *args):
        protocol_vo = ProtocolFactory(domain_id=self.domain_id)
        user_channel_vo = UserChannelFactory(
            domain_id=self.domain_id, protocol_id=protocol_vo.protocol_id)

        params = {
            'resource_type': 'identity.User',
            'resource_id': user_channel_vo.user_id,
            'topic': 'topic-a',
            'message': {
                'message': 'TEST..'
            },
            'notification_type': 'ERROR',
            'notification_level': 'ALL',
            'domain_id': self.domain_id,
        }

        self.transaction.method = 'create'
        notification_svc = NotificationService(transaction=self.transaction)
        notification_svc.create(params.copy())
Example #9
0
    def test_stat_user_channel_distinct(self, *args):
        user_channel_vos = UserChannelFactory.build_batch(10, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), user_channel_vos))

        params = {
            'domain_id': self.domain_id,
            'query': {
                'distinct': 'user_channel_id',
                'page': {
                    'start': 2,
                    'limit': 3
                }
            }
        }

        self.transaction.method = 'stat'
        user_channel_svc = UserChannelService(transaction=self.transaction)
        values = user_channel_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_user_channel_distinct')
    def test_set_subscription(self, *args):
        user_channel_vo = UserChannelFactory(domain_id=self.domain_id,
                                             secret_id='secret-xyz',
                                             is_subscribe=False,
                                             subscriptions=[])
        subscriptions = ['a', 'b', 'c']

        params = {
            'user_channel_id': user_channel_vo.user_channel_id,
            'is_subscribe': True,
            'subscriptions': subscriptions,
            'domain_id': self.domain_id
        }

        self.transaction.method = 'set_schedule'
        user_ch_svc = UserChannelService(transaction=self.transaction)
        subscription_user_ch_vo = user_ch_svc.set_schedule(params.copy())

        print_data(subscription_user_ch_vo.to_dict(), 'test_set_subscription')
        UserChannelInfo(subscription_user_ch_vo)

        self.assertIsInstance(subscription_user_ch_vo, UserChannel)
        self.assertEqual(subscription_user_ch_vo.is_subscribe, True)
        self.assertEqual(subscriptions, subscription_user_ch_vo.subscriptions)