示例#1
0
    def test_that_format_results_adds_results(self):
        result1 = self.SourceResult(
            {
                'id': 1,
                'firstname': 'Alice',
                'lastname': 'AAA',
                'telephoneNumber': '5555555555'
            }, self.xivo_id, None, None, None, None)
        result2 = self.SourceResult(
            {
                'id': 'user_id',
                'firstname': 'Bob',
                'lastname': 'BBB',
                'telephoneNumber': '5555556666'
            }, self.xivo_id, 'agent_id', 'user_id', UUID1, 'endpoint_id')
        display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, '', 'lastname'),
            DisplayColumn(None, 'status', None, None),
            DisplayColumn('Number', 'office_number', None, 'telephoneNumber'),
            DisplayColumn('Country', None, 'Canada', 'country')
        ]
        formatter = _ResultFormatter(display)

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

        assert_that(
            result,
            has_entries('results', [
                {
                    'column_values':
                    ['Alice', 'AAA', None, '5555555555', 'Canada'],
                    'relations': {
                        'xivo_id': self.xivo_id,
                        'agent_id': None,
                        'user_id': None,
                        'user_uuid': None,
                        'endpoint_id': None,
                        'source_entry_id': '1'
                    },
                    'source': self.source_name,
                    'backend': 'my_backend',
                },
                {
                    'column_values':
                    ['Bob', 'BBB', None, '5555556666', 'Canada'],
                    'relations': {
                        'xivo_id': self.xivo_id,
                        'agent_id': 'agent_id',
                        'user_id': 'user_id',
                        'user_uuid': UUID1,
                        'endpoint_id': 'endpoint_id',
                        'source_entry_id': 'user_id'
                    },
                    'source': self.source_name,
                    'backend': 'my_backend',
                },
            ]))
示例#2
0
    def test_that_format_results_marks_favorites(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',
        )
        display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, '', 'lastname'),
            DisplayColumn('Number', 'office_number', None, 'telephoneNumber'),
            DisplayColumn('Favorite', 'favorite', None, None),
        ]
        formatter = _ResultFormatter(display)

        result = formatter.format_results([result1, result2], {
            'my_source': ['2'],
            'my_other_source': ['1', '2', '3']
        })

        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', True)),
                ),
            ),
        )
    def test_that_format_headers_adds_columns_types(self):
        display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, '', 'lastname'),
            DisplayColumn(None, 'status', None, None),
            DisplayColumn('Number', 'office_number', None, 'telephoneNumber'),
            DisplayColumn('Country', None, 'Canada', 'country'),
        ]

        result = format_headers(display)

        expected_types = [None, None, 'status', 'office_number', None]
        assert_that(result, has_entries('column_types', expected_types))
示例#4
0
    def test_that_format_results_adds_columns_headers(self):
        display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, '', 'lastname'),
            DisplayColumn(None, 'status', None, None),
            DisplayColumn('Number', 'office_number', None, 'telephoneNumber'),
            DisplayColumn('Country', None, 'Canada', 'country'),
        ]
        formatter = _ResultFormatter(display)

        result = formatter.format_results([], [])

        expected_headers = ['Firstname', 'Lastname', None, 'Number', 'Country']
        assert_that(result, has_entries('column_headers', expected_headers))
示例#5
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)))))
示例#6
0
    def test_that_make_displays_generate_display_dict(self):
        first_display = [
            DisplayColumn('Firstname', None, 'Unknown', 'firstname'),
            DisplayColumn('Lastname', None, 'ln', 'lastname'),
        ]
        second_display = [
            DisplayColumn('fn', 'some_type', 'N/A', 'firstname'),
            DisplayColumn('ln', None, 'N/A', 'LAST'),
        ]

        first = {
            'name':
            'first_display',
            'columns': [
                {
                    'title': 'Firstname',
                    'type': None,
                    'default': 'Unknown',
                    'field': 'firstname',
                },
                {
                    'title': 'Lastname',
                    'type': None,
                    'default': 'ln',
                    'field': 'lastname',
                },
            ],
        }
        second = {
            'name':
            'second_display',
            'columns': [
                {
                    'title': 'fn',
                    'type': 'some_type',
                    'default': 'N/A',
                    'field': 'firstname',
                },
                {
                    'title': 'ln',
                    'type': None,
                    'default': 'N/A',
                    'field': 'LAST'
                },
            ],
        }

        assert_that(make_display(first), equal_to(first_display))
        assert_that(make_display(second), equal_to(second_display))