X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=tests%2Ftest_search.py;h=dfea04113ce21656bb4e4842b38663fef588bdca;hb=5a068e6e04b4441e6efae55619e9b54da2d6a020;hp=991a9079e61e212a9fa76320b65ac431d055ffdd;hpb=4dcbb3e9ee712ebcb78db9675de4bd40a1fce940;p=m_librarian.git diff --git a/tests/test_search.py b/tests/test_search.py old mode 100755 new mode 100644 index 991a907..dfea041 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,24 +1,24 @@ -#! /usr/bin/env python # coding: utf-8 +from dbutils import setup_module, teardown_module # noqa +from dbutils import load_inpx +from m_librarian.db import Author, Book +from m_librarian.search import mk_search_conditions, \ + search_authors, search_books -from tests import TestCase, main -from m_librarian.search import search_authors +def test_search_authors(): + load_inpx('test.inpx') + assert search_authors('full', True, {'surname': u'Друг'}).count() == 1 + assert search_authors('start', True, {'surname': u'Друг'}).count() == 2 + assert search_authors('substring', True, {'surname': u'Друг'}).count() == 2 + assert search_authors( + 'substring', False, {'surname': u'друг'}).count() == 3 -class TestSearch(TestCase): - def test_search_authors(self): - self.import_inpx('test.inpx') - self.assertEqual( - search_authors('exact', True, {'surname': u'Друг'}).count(), 1) - self.assertEqual( - search_authors('start', True, {'surname': u'Друг'}).count(), 2) - self.assertEqual( - search_authors('substring', True, {'surname': u'Друг'}).count(), 2) - self.assertEqual( - search_authors('substring', False, {'surname': u'друг'}).count(), - 3) - - -if __name__ == "__main__": - main() + join_expressions = [] + join_expressions.append(Book.j.authors) + conditions = mk_search_conditions( + Author, 'start', False, {'surname': u'друг'}) + join_expressions.extend(conditions) + assert search_books( + 'start', False, {'title': u'тест'}, join_expressions).count() == 2