1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from unittest import skipIf
5 from django.conf import settings
6 from django.test.utils import override_settings
7 from catalogue.test_utils import WLTestCase, get_fixture
9 from catalogue.models import Book
10 from search.index import Index, Search
15 @override_settings(SEARCH_INDEX=tempfile.mkdtemp(prefix='djangotest_search_'))
16 @skipIf(getattr(settings, 'NO_SEARCH_INDEX', False),
17 'Requires search server and NO_SEARCH_INDEX=False.')
18 class BookSearchTests(WLTestCase):
20 WLTestCase.setUp(self)
23 self.search = Search()
24 index.delete_query(self.search.index.query(uid="*"))
27 self.do_doktora = Book.from_xml_file(
28 get_fixture('do-doktora.xml', opds))
29 self.do_anusie = Book.from_xml_file(
30 get_fixture('fraszka-do-anusie.xml', catalogue))
32 # TODO: Add slop option to sunburnt
33 # def test_search_perfect_parts(self):
34 # books = self.search.search_phrase("Jakoż hamować")
35 # assert len(books) == 2
37 # b.book_id == self.book.id
38 # a = SearchResult.aggregate(books)
39 # # just one fragment hit.
40 # assert len(a[0].hits) == 1