Ejemplo n.º 1
0
    def test_list_voicemails_with_two_voicemails(self, voicemail_search):
        voicemail1 = Voicemail(id=123421,
                               name='10.0.0.1',
                               number='001122334455',
                               context='fasdf',
                               attach_audio=False,
                               delete_messages=False,
                               ask_password=False)
        voicemail2 = Voicemail(id=235235,
                               name='10.0.0.2',
                               number='001122334456',
                               context='dsad',
                               attach_audio=False,
                               delete_messages=False,
                               ask_password=False)

        voicemail_search.return_value = SearchResult(
            total=2, items=[voicemail1, voicemail2])

        expected_result = {
            'total': 2,
            'items':
            [self.build_item(voicemail1),
             self.build_item(voicemail2)]
        }

        result = self.app.get(BASE_URL)

        self.assert_response_for_list(result, expected_result)
        voicemail_search.assert_called_once_with()
Ejemplo n.º 2
0
    def test_list_users_with_no_users(self, user_search):
        expected_response = {'total': 0, 'items': []}

        user_search.return_value = SearchResult(0, [])

        response = self.app.get(BASE_URL)

        user_search.assert_any_call()
        self.assert_response_for_list(response, expected_response)
Ejemplo n.º 3
0
    def test_list_no_devices(self, device_search):
        device_search.return_value = SearchResult(total=0, items=[])

        expected_result = {'total': 0, 'items': []}

        result = self.app.get(BASE_URL)

        self.assert_response_for_list(result, expected_result)
        device_search.assert_called_once_with()
Ejemplo n.º 4
0
    def test_when_sorting_in_descending_order_then_returns_results_in_descending_order(
            self):
        expected = SearchResult(4, [
            self.extension4, self.extension3, self.extension2, self.extension1
        ])

        self.assert_search_returns_result(expected,
                                          order='exten',
                                          direction='desc')
Ejemplo n.º 5
0
    def test_list_extensions_with_no_extensions(self, mock_extension_services_search):
        expected_response = {'total': 0,
                             'items': []}

        mock_extension_services_search.return_value = SearchResult(0, [])

        response = self.app.get(BASE_URL)

        mock_extension_services_search.assert_any_call()
        self.assert_response_for_list(response, expected_response)
Ejemplo n.º 6
0
    def test_when_doing_a_paginated_search_then_returns_a_paginated_result(
            self):
        expected = SearchResult(3, [self.extension2])

        self.assert_search_returns_result(expected,
                                          search='100',
                                          order='exten',
                                          direction='desc',
                                          skip=1,
                                          limit=1)
Ejemplo n.º 7
0
    def test_list_voicemails_with_no_voicemails(
            self, mock_voicemail_services_search):
        mock_voicemail_services_search.return_value = SearchResult(total=0,
                                                                   items=[])

        expected_result = {'total': 0, 'items': []}

        result = self.app.get(BASE_URL)

        self.assert_response_for_list(result, expected_result)
        mock_voicemail_services_search.assert_any_call()
Ejemplo n.º 8
0
def search(**parameters):
    provd_devices = find_devices_ordered(parameters.get('order', None),
                                         parameters.get('direction', None))
    provd_devices = filter_list(provd_devices, parameters.get('search', None))

    total = len(provd_devices)

    provd_devices = paginate_devices(provd_devices, parameters.get('skip', 0),
                                     parameters.get('limit', None))

    items = convert_devices_to_model(provd_devices)
    return SearchResult(total=total, items=items)
Ejemplo n.º 9
0
    def test_list_users_with_new_search(self, user_search):
        user = User(id=1, firstname=u'Bob', caller_id=u'"Bob "')

        expected_response = {'total': 1, 'items': [self.build_item(user)]}

        user_search.return_value = SearchResult(1, [user])

        url = "%s?search=bob&order=firstname&direction=desc&limit=1&skip=2"
        response = self.app.get(url % BASE_URL)

        user_search.assert_called_once_with(search='bob',
                                            order='firstname',
                                            direction='desc',
                                            limit=1,
                                            skip=2)
        self.assert_response_for_list(response, expected_response)
Ejemplo n.º 10
0
    def test_list_users_with_two_users(self, user_search):
        user1 = User(id=1, firstname=u'test1', caller_id=u'"test1 "')
        user2 = User(id=2, firstname=u'test2', caller_id=u'"test2 "')

        expected_response = {
            'total': 2,
            'items': [self.build_item(user1),
                      self.build_item(user2)]
        }

        user_search.return_value = SearchResult(2, [user1, user2])

        response = self.app.get(BASE_URL)

        user_search.assert_any_call()
        self.assert_response_for_list(response, expected_response)
Ejemplo n.º 11
0
    def test_list_voicemails_with_parameters(self, voicemail_search):
        voicemail_search.return_value = SearchResult(total=0, items=[])

        expected_result = {'total': 0, 'items': []}

        query_string = 'skip=532&limit=5432&order=email&direction=asc&search=abcd'
        request_parameters = {
            'skip': 532,
            'limit': 5432,
            'order': 'email',
            'direction': 'asc',
            'search': 'abcd'
        }

        result = self.app.get("%s?%s" % (BASE_URL, query_string))

        self.assert_response_for_list(result, expected_result)
        voicemail_search.assert_called_once_with(**request_parameters)
Ejemplo n.º 12
0
    def test_search_devices_with_parameters(self, device_search):
        device_search.return_value = SearchResult(total=0, items=[])

        expected_result = {'total': 0, 'items': []}

        search_parameters = {
            'search': 'search',
            'skip': 1,
            'limit': 2,
            'order': 'ip',
            'direction': 'asc'
        }

        query_url = "search=search&skip=1&limit=2&order=ip&direction=asc"
        result = self.app.get("%s?%s" % (BASE_URL, query_url))

        self.assert_response_for_list(result, expected_result)
        device_search.assert_called_once_with(**search_parameters)
Ejemplo n.º 13
0
    def test_list_devices_with_two_devices(self, device_search):
        device1 = Device(id='abcdefghijklmnopqrstuvwxyz123456',
                         ip='10.0.0.1',
                         mac='00:11:22:33:44:55')
        device2 = Device(id='1234567890abcdefghij1234567890abc',
                         ip='10.0.0.2',
                         mac='00:11:22:33:44:56')

        device_search.return_value = SearchResult(total=2,
                                                  items=[device1, device2])

        expected_result = {
            'total': 2,
            'items': [self.build_item(device1),
                      self.build_item(device2)]
        }

        result = self.app.get(BASE_URL)

        self.assert_response_for_list(result, expected_result)
        device_search.assert_called_once_with()
Ejemplo n.º 14
0
def search(session, **parameters):
    rows, total = voicemail_search.search(session, parameters)
    items = _generate_items(rows)

    return SearchResult(total, items)
Ejemplo n.º 15
0
def search(session, **parameters):
    rows, total = extension_search.search(session, parameters)

    extensions = _rows_to_extension_model(rows)
    return SearchResult(total, extensions)
Ejemplo n.º 16
0
def search(session, **parameters):
    rows, total = user_search.search(session, parameters)
    users = _rows_to_user_model(rows)
    return SearchResult(total, users)
Ejemplo n.º 17
0
def search(session, **parameters):
    rows, total = QueryHelper(session).search(parameters)

    func_keys = [db_converter.to_model(row) for row in rows]
    return SearchResult(total, func_keys)
Ejemplo n.º 18
0
    def test_when_sorting_then_returns_result_in_ascending_order(self):
        expected = SearchResult(4, [
            self.extension1, self.extension2, self.extension3, self.extension4
        ])

        self.assert_search_returns_result(expected, order='exten')
Ejemplo n.º 19
0
    def test_when_searching_then_returns_one_result(self):
        expected = SearchResult(1, [self.extension2])

        self.assert_search_returns_result(expected, search='1001')