def setUp(self): DAOTestCase.setUp(self) self.config = SearchConfig(table=UserFeatures, columns={ 'lastname': UserFeatures.lastname, 'firstname': UserFeatures.firstname, 'simultcalls': UserFeatures.simultcalls }, default_sort='lastname') self.search = SearchSystem(self.config)
def setUp(self): DAOTestCase.setUp(self) self.config = SearchConfig(table=UserFeatures, columns={'lastname': UserFeatures.lastname, 'firstname': UserFeatures.firstname, 'simultcalls': UserFeatures.simultcalls}, default_sort='lastname') self.search = SearchSystem(self.config)
class TestSearchSystem(DAOTestCase): def setUp(self): DAOTestCase.setUp(self) self.config = SearchConfig(table=UserFeatures, columns={'lastname': UserFeatures.lastname, 'firstname': UserFeatures.firstname, 'simultcalls': UserFeatures.simultcalls}, default_sort='lastname') self.search = SearchSystem(self.config) def test_given_no_parameters_then_sorts_rows_using_default_sort_and_direction(self): last_user_row = self.add_user(lastname='Zintrabi') first_user_row = self.add_user(lastname='Abigale') rows, total = self.search.search(self.session) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_order_then_sorts_rows_using_order(self): last_user_row = self.add_user(firstname='Bob', lastname='Abigale') first_user_row = self.add_user(firstname='Alice', lastname='Zintrabi') rows, total = self.search.search(self.session, {'order': 'firstname'}) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_direction_then_sorts_rows_using_direction(self): first_user_row = self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'direction': 'desc'}) assert_that(total, equal_to(2)) assert_that(rows, contains(last_user_row, first_user_row)) def test_given_limit_is_negative_number_then_raises_error(self): self.assertRaises(InputError, self.search.search, self.session, {'limit': -1}) def test_given_limit_is_zero_then_raises_error(self): self.assertRaises(InputError, self.search.search, self.session, {'limit': 0}) def test_given_skip_is_negative_number_then_raises_error(self): self.assertRaises(InputError, self.search.search, self.session, {'skip': -1}) def test_given_limit_then_returns_same_number_of_rows_as_limit(self): self.add_user() self.add_user() rows, total = self.search.search(self.session, {'limit': 1}) assert_that(total, equal_to(2)) assert_that(rows, has_length(1)) def test_given_skip_then_skips_a_number_of_rows(self): self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'skip': 1}) assert_that(total, equal_to(2)) assert_that(rows, contains(last_user_row)) def test_given_skip_is_zero_then_does_not_skip_rows(self): first_user_row = self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'skip': 0}) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_search_term_then_searches_in_columns_and_uses_default_sort(self): user_row1 = self.add_user(firstname='a123bcd', lastname='eeefghi') user_row2 = self.add_user(firstname='eeefghi', lastname='a123zzz') self.add_user(description='123') rows, total = self.search.search(self.session, {'search': '123'}) assert_that(total, equal_to(2)) assert_that(rows, contains(user_row2, user_row1)) def test_given_search_term_then_searches_in_numeric_columns(self): self.add_user(simultcalls=1) user_row2 = self.add_user(simultcalls=2) rows, total = self.search.search(self.session, {'search': '2'}) assert_that(total, equal_to(1)) assert_that(rows, contains(user_row2))
def search_from_query(self, query, parameters=None): query = self._apply_type_filter(query, parameters) return SearchSystem.search_from_query(self, query, parameters)
class TestSearchSystem(DAOTestCase): def setUp(self): DAOTestCase.setUp(self) self.config = SearchConfig(table=UserFeatures, columns={ 'lastname': UserFeatures.lastname, 'firstname': UserFeatures.firstname, 'simultcalls': UserFeatures.simultcalls }, default_sort='lastname') self.search = SearchSystem(self.config) def test_given_no_parameters_then_sorts_rows_using_default_sort_and_direction( self): last_user_row = self.add_user(lastname='Zintrabi') first_user_row = self.add_user(lastname='Abigale') rows, total = self.search.search(self.session) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_order_then_sorts_rows_using_order(self): last_user_row = self.add_user(firstname='Bob', lastname='Abigale') first_user_row = self.add_user(firstname='Alice', lastname='Zintrabi') rows, total = self.search.search(self.session, {'order': 'firstname'}) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_direction_then_sorts_rows_using_direction(self): first_user_row = self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'direction': 'desc'}) assert_that(total, equal_to(2)) assert_that(rows, contains(last_user_row, first_user_row)) def test_given_limit_is_negative_number_then_raises_error(self): self.assertRaises(InvalidParametersError, self.search.search, self.session, {'limit': -1}) def test_given_limit_is_zero_then_raises_error(self): self.assertRaises(InvalidParametersError, self.search.search, self.session, {'limit': 0}) def test_given_skip_is_negative_number_then_raises_error(self): self.assertRaises(InvalidParametersError, self.search.search, self.session, {'skip': -1}) def test_given_limit_then_returns_same_number_of_rows_as_limit(self): self.add_user() self.add_user() rows, total = self.search.search(self.session, {'limit': 1}) assert_that(total, equal_to(2)) assert_that(rows, has_length(1)) def test_given_skip_then_skips_a_number_of_rows(self): self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'skip': 1}) assert_that(total, equal_to(2)) assert_that(rows, contains(last_user_row)) def test_given_skip_is_zero_then_does_not_skip_rows(self): first_user_row = self.add_user(lastname='Abigale') last_user_row = self.add_user(lastname='Zintrabi') rows, total = self.search.search(self.session, {'skip': 0}) assert_that(total, equal_to(2)) assert_that(rows, contains(first_user_row, last_user_row)) def test_given_search_term_then_searches_in_columns_and_uses_default_sort( self): user_row1 = self.add_user(firstname='a123bcd', lastname='eeefghi') user_row2 = self.add_user(firstname='eeefghi', lastname='a123zzz') self.add_user(description='123') rows, total = self.search.search(self.session, {'search': '123'}) assert_that(total, equal_to(2)) assert_that(rows, contains(user_row2, user_row1)) def test_given_search_term_then_searches_in_numeric_columns(self): self.add_user(simultcalls=1) user_row2 = self.add_user(simultcalls=2) rows, total = self.search.search(self.session, {'search': '2'}) assert_that(total, equal_to(1)) assert_that(rows, contains(user_row2))
# it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> from xivo_dao.alchemy.userfeatures import UserFeatures from xivo_dao.data_handler.utils.search import SearchSystem from xivo_dao.data_handler.utils.search import SearchConfig config = SearchConfig( table=UserFeatures, columns={ 'firstname': UserFeatures.firstname, 'lastname': UserFeatures.lastname, 'fullname': (UserFeatures.firstname + " " + UserFeatures.lastname), 'caller_id': UserFeatures.callerid, 'description': UserFeatures.description, 'userfield': UserFeatures.userfield }, search=['fullname', 'caller_id', 'description', 'userfield'], default_sort='lastname') user_search = SearchSystem(config)
# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> from xivo_dao.alchemy.voicemail import Voicemail from xivo_dao.data_handler.utils.search import SearchSystem from xivo_dao.data_handler.utils.search import SearchConfig config = SearchConfig(table=Voicemail, columns={'name': Voicemail.fullname, 'number': Voicemail.mailbox, 'email': Voicemail.email, 'context': Voicemail.context, 'language': Voicemail.language, 'timezone': Voicemail.tz}, search=['name', 'number', 'email'], default_sort='number') voicemail_search = SearchSystem(config)
def search(self, parameters): config = SearchConfig(table=FuncKeySchema, columns=self.column_mapping, default_sort='id') return SearchSystem(config).search_from_query(self.query(), parameters)