1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from unittest import skipIf
6 from django.conf import settings
7 from django.test.utils import override_settings
8 from catalogue.test_utils import WLTestCase, get_fixture
10 from catalogue.models import Book
11 from search.index import Index, Search
16 @override_settings(SEARCH_INDEX=tempfile.mkdtemp(prefix='djangotest_search_'))
17 @skipIf(getattr(settings, 'NO_SEARCH_INDEX', False),
18 u'Requires search server and NO_SEARCH_INDEX=False.')
19 class BookSearchTests(WLTestCase):
21 WLTestCase.setUp(self)
24 self.search = Search()
25 index.delete_query(self.search.index.query(uid="*"))
28 self.do_doktora = Book.from_xml_file(
29 get_fixture('do-doktora.xml', opds))
30 self.do_anusie = Book.from_xml_file(
31 get_fixture('fraszka-do-anusie.xml', catalogue))
33 def test_search_perfect_book_author(self):
34 books = self.search.search_books(self.search.index.query(authors=u"sęp szarzyński"))
35 assert len(books) == 1
36 assert books[0].id == self.do_anusie.id
38 # here we lack slop functionality as well
39 def test_search_perfect_book_title(self):
40 books = self.search.search_books(self.search.index.query(title=u"fraszka do anusie"))
41 assert len(books) == 1
42 assert books[0].id == self.do_anusie.id
44 # TODO: Add slop option to sunburnt
45 # def test_search_perfect_parts(self):
46 # books = self.search.search_phrase(u"Jakoż hamować")
47 # assert len(books) == 2
49 # b.book_id == self.book.id
50 # a = SearchResult.aggregate(books)
51 # # just one fragment hit.
52 # assert len(a[0].hits) == 1