1 # -*- coding: utf-8 -*-
2 from django.conf import settings
3 from django.test.utils import override_settings
4 from catalogue.test_utils import WLTestCase, get_fixture
7 from catalogue.models import Book, Tag
8 from search import Index, Search, SearchResult
14 SEARCH_INDEX = tempfile.mkdtemp(prefix='djangotest_search_'),
16 class BookSearchTests(WLTestCase):
18 WLTestCase.setUp(self)
21 self.search = Search()
22 index.delete_query(self.search.index.query(uid="*"))
25 with self.settings(NO_SEARCH_INDEX=False):
26 self.do_doktora = Book.from_xml_file(
27 get_fixture('do-doktora.xml', opds))
28 self.do_anusie = Book.from_xml_file(
29 get_fixture('fraszka-do-anusie.xml', catalogue))
31 def test_search_perfect_book_author(self):
32 books = self.search.search_books(self.search.index.query(authors=u"sęp szarzyński"))
33 assert len(books) == 1
34 assert books[0].id == self.do_anusie.id
36 # here we lack slop functionality as well
37 def test_search_perfect_book_title(self):
38 books = self.search.search_books(self.search.index.query(title=u"fraszka do anusie"))
39 assert len(books) == 1
40 assert books[0].id == self.do_anusie.id
42 # TODO: Add slop option to sunburnt
43 # def test_search_perfect_parts(self):
44 # books = self.search.search_phrase(u"Jakoż hamować")
45 # assert len(books) == 2
47 # b.book_id == self.book.id
48 # a = SearchResult.aggregate(books)
49 # # just one fragment hit.
50 # assert len(a[0].hits) == 1