class TestCELFetcher(TestCase):
    def setUp(self):
        self.cel_fetcher = CELFetcher()

    def tearDown(self):
        pass

    @patch('xivo_dao.resources.cel.dao.find_last_unprocessed')
    def test_fetch_last_unprocessed(self, mock_cel_dao):
        cel_count = 333
        cels = mock_cel_dao.return_value = [Mock(), Mock(), Mock()]

        result = self.cel_fetcher.fetch_last_unprocessed(cel_count)

        mock_cel_dao.assert_called_once_with(cel_count, None)
        assert_that(result, equal_to(cels))

    @patch('xivo_dao.resources.cel.dao.find_from_linked_id')
    def test_find_from_linked_id(self, mock_cel_dao):
        linked_id = '666'
        cels = mock_cel_dao.return_value = [Mock(), Mock(), Mock()]

        result = self.cel_fetcher.fetch_from_linked_id(linked_id)

        mock_cel_dao.assert_called_once_with(linked_id)
        assert_that(result, equal_to(cels))
Example #2
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)
    key_config = load_key_file(DEFAULT_CONFIG)
    config = ChainMap(key_config, DEFAULT_CONFIG)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator([
        LocalOriginateCELInterpretor(confd_client),
        DispatchCELInterpretor(CallerCELInterpretor(confd_client),
                               CalleeCELInterpretor(confd_client))
    ])
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Example #3
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri')
    }
    key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    init_db_from_config(config)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(confd_client),
            DispatchCELInterpretor(
                CallerCELInterpretor(confd_client), CalleeCELInterpretor(confd_client)
            ),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid
    )
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
Example #4
0
 def __init__(self, config):
     auth_config = dict(config['auth'])
     auth_config.pop('key_file', None)
     auth_client = AuthClient(**auth_config)
     cel_fetcher = CELFetcher()
     confd_client = ConfdClient(**config['confd'])
     generator = CallLogsGenerator([
         LocalOriginateCELInterpretor(confd_client),
         DispatchCELInterpretor(CallerCELInterpretor(confd_client),
                                CalleeCELInterpretor(confd_client))
     ])
     writer = CallLogsWriter()
     self._publisher = BusPublisher(config)
     self.manager = CallLogsManager(cel_fetcher, generator, writer,
                                    self._publisher)
     self.bus_client = BusClient(config)
     self.rest_api = CoreRestApi(config)
     self.token_renewer = TokenRenewer(auth_client)
     self.token_renewer.subscribe_to_token_change(confd_client.set_token)
     self._load_plugins(config)
Example #5
0
 def __init__(self, config):
     auth_client = AuthClient(**config['auth'])
     cel_fetcher = CELFetcher()
     confd_client = ConfdClient(**config['confd'])
     generator = CallLogsGenerator(
         confd_client,
         [
             LocalOriginateCELInterpretor(confd_client),
             DispatchCELInterpretor(
                 CallerCELInterpretor(confd_client),
                 CalleeCELInterpretor(confd_client),
             ),
         ],
     )
     writer = CallLogsWriter()
     self.token_renewer = TokenRenewer(auth_client)
     self.token_renewer.subscribe_to_token_change(confd_client.set_token)
     self.token_renewer.subscribe_to_next_token_details_change(
         generator.set_default_tenant_uuid)
     self._publisher = BusPublisher(config)
     self.manager = CallLogsManager(cel_fetcher, generator, writer,
                                    self._publisher)
     self.bus_client = BusClient(config)
     self.rest_api = CoreRestApi(config)
     self.status_aggregator = StatusAggregator()
     self.token_status = TokenStatus()
     plugin_helpers.load(
         namespace='wazo_call_logd.plugins',
         names=config['enabled_plugins'],
         dependencies={
             'api': api,
             'config': config,
             'token_renewer': self.token_renewer,
             'status_aggregator': self.status_aggregator,
         },
     )
 def setUp(self):
     self.cel_fetcher = CELFetcher()