Exemplo n.º 1
0
 def setUp(self):
     self.source_name = 'my_source'
     self.xivo_id = 'my_xivo_abc'
     backend = 'my_backend'
     self.SourceResult = make_result_class(backend,
                                           self.source_name,
                                           unique_column='id')
Exemplo n.º 2
0
    def load(self, dependencies):
        config = dependencies['config']
        self.auth = config['auth']
        self.name = config['name']
        self.google = services.GoogleService()
        self.unique_column = 'id'

        format_columns = dependencies['config'].get(self.FORMAT_COLUMNS, {})
        if 'reverse' not in format_columns:
            logger.info(
                'no "reverse" column has been configured on %s will use "name"',
                self.name)
            format_columns['reverse'] = '{name}'

        self._SourceResult = make_result_class(
            'google',
            self.name,
            self.unique_column,
            format_columns,
        )

        self._searched_columns = config.get(self.SEARCHED_COLUMNS, [])
        if not self._searched_columns:
            logger.info(
                'no "searched_columns" configured on "%s" no results will be matched',
                self.name,
            )

        self._first_matched_columns = config.get(self.FIRST_MATCHED_COLUMNS,
                                                 [])
        if not self._first_matched_columns:
            logger.info(
                'no "first_matched_columns" configured on "%s" no results will be matched',
                self.name,
            )
Exemplo n.º 3
0
    def load(self, args):
        self._config = args.get('config', {})
        self._name = self._config.get('name', 'sample_directory')
        self._format_columns = self._config.get(self.FORMAT_COLUMNS, {})

        backend = self._config.get('backend', '')
        SourceResult = make_result_class(backend, self._name, 'id',
                                         self._format_columns)
        self._result = SourceResult(SAMPLE_RESULT)
Exemplo n.º 4
0
 def __init__(self, ldap_config):
     self._unique_column = ldap_config.unique_column()
     self._bin_uuid = ldap_config.has_binary_uuid()
     self._SourceResult = make_result_class(
         'ldap',
         ldap_config.name(),
         self._unique_column,
         ldap_config.format_columns(),
     )
Exemplo n.º 5
0
    def test_first_match(self):
        SourceResult = make_result_class('sample_backend', 'sample_directory', 'id')
        only_result = SourceResult({
            'id': 1,
            'firstname': 'John',
            'lastname': 'Doe',
            'number': '555',
            'description': 'It works but this wazo-dird installation is still using the default configuration',
        })

        self.source.load({})
        result = self.source.first_match('555')

        assert_that(result, equal_to(only_result))
Exemplo n.º 6
0
    def load(self, dependencies):
        config = dependencies['config']
        self._searched_columns = config.get(self.SEARCHED_COLUMNS, [])
        self._first_matched_columns = config.get(self.FIRST_MATCHED_COLUMNS, [])
        self.name = config['name']
        self._client = registry.get(config)

        self._SourceResult = make_result_class(
            'conference',
            self.name,
            'id',
            format_columns=config.get(self.FORMAT_COLUMNS),
        )
        logger.info('Wazo %s successfully loaded', config['name'])
Exemplo n.º 7
0
    def test_that_format_results_marks_personal(self):
        result1 = self.SourceResult(
            {
                'id': 1,
                'firstname': 'Alice',
                'lastname': 'AAA',
                'telephoneNumber': '5555555555'
            }, self.xivo_id, None, 1, UUID1, None)
        result2 = self.SourceResult(
            {
                'id': 2,
                'firstname': 'Bob',
                'lastname': 'BBB',
                'telephoneNumber': '5555556666'
            }, self.xivo_id, 'agent_id', 2, UUID2, 'endpoint_id')
        result3 = make_result_class(
            'personal',
            'personal_source',
            unique_column='id',
            is_personal=True,
            is_deletable=True)({
                'id': 'my-id',
                'firstname': 'Charlie',
                'lastname': 'CCC',
                'telephoneNumber': '5555557777'
            }, self.xivo_id, None, None, None)

        display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, '', 'lastname'),
            DisplayColumn('Number', 'office_number', None, 'telephoneNumber'),
            DisplayColumn('Personal', 'personal', None, None),
        ]
        formatter = _ResultFormatter(display)

        result = formatter.format_results([result1, result2, result3], {})

        assert_that(
            result,
            has_entry(
                'results',
                contains_inanyorder(
                    has_entry('column_values',
                              contains('Alice', 'AAA', '5555555555', False)),
                    has_entry('column_values',
                              contains('Bob', 'BBB', '5555556666', False)),
                    has_entry('column_values',
                              contains('Charlie', 'CCC', '5555557777',
                                       True)))))
    def test_first_match(self):
        SourceResult = make_result_class('sample_backend', 'sample_directory',
                                         'id')
        only_result = SourceResult({
            'id': 1,
            'firstname': 'John',
            'lastname': 'Doe',
            'number': '555',
            'description': MSG,
        })

        self.source.load({})
        result = self.source.first_match('555')

        assert_that(result, equal_to(only_result))
    def test_search(self):
        SourceResult = make_result_class('sample_backend', 'sample_directory',
                                         'id')
        only_result = SourceResult({
            'id': 1,
            'firstname': 'John',
            'lastname': 'Doe',
            'number': '555',
            'description': MSG,
        })

        self.source.load({})
        results = self.source.search('anything')

        assert_that(results, contains(only_result))
Exemplo n.º 10
0
    def load(self, args):
        if 'config' not in args:
            logger.warning('Missing config in startup arguments: %s', args)

        self._config = args.get('config', {})
        self._name = self._config.get('name', '')
        self._content = []
        self._has_unique_id = self._config.get(self.UNIQUE_COLUMN, None) is not None
        self._load_file()
        backend = self._config.get('backend', '')
        self._SourceResult = make_result_class(
            backend,
            self._name,
            self._config.get(self.UNIQUE_COLUMN, None),
            self._config.get(self.FORMAT_COLUMNS, {})
        )
Exemplo n.º 11
0
    def load(self, config, search_engine=None):
        logger.debug('Loading personal source')

        unique_column = 'id'
        source_name = config['config']['name']
        format_columns = config['config'].get(self.FORMAT_COLUMNS, {})

        result_class = make_result_class('personal',
                                         source_name,
                                         unique_column,
                                         format_columns,
                                         is_personal=True,
                                         is_deletable=True)
        self._SourceResult = lambda contact: result_class(
            self._remove_empty_values(contact))
        self._search_engine = search_engine or self._new_search_engine(
            config['config'].get(self.SEARCHED_COLUMNS),
            config['config'].get(self.FIRST_MATCHED_COLUMNS),
        )
Exemplo n.º 12
0
    def load(self, config):
        logger.debug('Loading with %s', config)

        self._name = config['config']['name']
        self._list_url = config['config'].get('list_url')
        self._lookup_url = config['config']['lookup_url']
        self._first_matched_columns = config['config'].get(
            self.FIRST_MATCHED_COLUMNS, [])
        self._searched_columns = config['config'].get(self.SEARCHED_COLUMNS,
                                                      [])
        self._unique_column = config['config'].get(self.UNIQUE_COLUMN)
        backend = config['config'].get('backend', '')
        self._SourceResult = make_result_class(
            backend, config['config']['name'], self._unique_column,
            config['config'].get(self.FORMAT_COLUMNS, {}))
        self._timeout = config['config'].get('timeout', 10)
        self._delimiter = config['config'].get('delimiter', ',')
        self._verify_certificate = config['config'].get(
            'verify_certificate', True)
        self._reader = _CSVReader(self._delimiter)
Exemplo n.º 13
0
    def load(self, dependencies):
        logger.debug('Loading phonebook source')
        unique_column = 'id'
        config = dependencies['config']
        self._source_name = config['name']
        format_columns = config.get(self.FORMAT_COLUMNS, {})
        searched_columns = config.get(self.SEARCHED_COLUMNS)
        first_matched_columns = config.get(self.FIRST_MATCHED_COLUMNS)

        self._crud = database.PhonebookCRUD(Session)

        tenant_uuid = config['tenant_uuid']
        phonebook_id = self._get_phonebook_id(tenant_uuid, config)

        self._search_engine = database.PhonebookContactSearchEngine(
            Session, tenant_uuid, phonebook_id, searched_columns,
            first_matched_columns)

        self._SourceResult = make_result_class('phonebook', self._source_name,
                                               unique_column, format_columns)

        logger.info('%s loaded', self._source_name)
Exemplo n.º 14
0
    def load(self, dependencies):
        config = dependencies['config']

        self.name = config['name']
        self.sock = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/object' %
                                          (config['server'], config['port']))
        self.db = config['database']
        self.uid = config['userid']
        self.pwd = config['password']

        unique_column = None
        format_columns = dependencies['config'].get(self.FORMAT_COLUMNS, {})
        if 'reverse' not in format_columns:
            logger.info(
                'no "reverse" column has been configured on %s will use "givenName"',
                self.name)
            format_columns['reverse'] = '{givenName}'

        self._SourceResult = make_result_class(
            'odoo',
            self.name,
            unique_column,
            format_columns,
        )
Exemplo n.º 15
0
from hamcrest import contains
from hamcrest import equal_to
from wazo_dird import make_result_class

from ..plugin import CSVPlugin

comma_separated_content = '''\
clientno,firstname,lastname,number,age
1,Alice,AAA,5555555555,20
2,Bob,BBB,5555551234,21
3,Charles,CCC,5555556666,22
'''

pipe_separated_content = comma_separated_content.replace(',', '|')

SourceResult = make_result_class('test-csv', 'my_directory', unique_column='clientno')

alice = {'clientno': '1',
         'firstname': 'Alice',
         'lastname': 'AAA',
         'number': '5555555555',
         'age': '20'}


class BaseCSVTestDirectory(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.fd, cls.fname = tempfile.mkstemp()
        cls.tmp_file = os.fdopen(cls.fd)
Exemplo n.º 16
0
    'config': {
        'uuid': 'ae086548-2d36-4367-8914-8dfcd8645ca7',
        'backend': 'wazo',
        'tenant_uuid': TENANT_UUID,
        'confd': CONFD_CONFIG,
        'auth': AUTH_CONFIG,
        'name': 'my_test_xivo',
        'searched_columns': ['firstname', 'lastname'],
    },
}
UUID = 'my-xivo-uuid'

UUID_1 = '55abf77c-5744-44a0-9c36-34da29f647cb'
UUID_2 = '22f51ae2-296d-4340-a7d5-3567ae66df73'

SourceResult = make_result_class(DEFAULT_ARGS['config']['backend'], DEFAULT_ARGS['config']['name'],
                                 unique_column='id')

CONFD_USER_1 = {
    "agent_id": 42,
    "exten": '666',
    "firstname": "Louis-Jean",
    "id": 226,
    'uuid': UUID_1,
    "lastname": "",
    "line_id": 123,
    'userfield': None,
    'description': None,
    "links": [
        {
            "href": "http://localhost:9487/1.1/users/226",
            "rel": "users"