Merge branch 'reflow'
[wolnelektury.git] / src / dictionary / tests.py
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.
4 #
5 from django.core.files.base import ContentFile
6 from catalogue.test_utils import *
7 from catalogue.models import Book
8
9
10 class DictionaryTests(WLTestCase):
11
12     def setUp(self):
13         WLTestCase.setUp(self)
14         self.book_info = BookInfoStub(
15             author=PersonStub(("Jim",), "Lazy"),
16             kind="X-Kind",
17             genre="X-Genre",
18             epoch="X-Epoch",
19             **info_args(u"Default Book")
20         )
21
22     def test_book_with_footnote(self):
23         book_text = """<utwor>
24         <opowiadanie>
25             <akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
26             <akap><pe><slowo_obce>rose</slowo_obce> --- kind of a flower.</pe></akap>
27             <akap><pe><slowo_obce>rose</slowo_obce> (techn.) --- #FF007F.</pe></akap>
28         </opowiadanie></utwor>
29         """
30
31         book = Book.from_text_and_meta(ContentFile(book_text), self.book_info)
32
33         self.assertEqual(
34             len(self.client.get('/przypisy/').context['object_list']),
35             2,
36             'There should be two notes on the note list.')
37
38         self.assertEqual(
39             len(self.client.get('/przypisy/?ltr=a').context['object_list']),
40             0,
41             'There should not be a note for the letter A.')
42
43         self.assertEqual(
44             len(self.client.get('/przypisy/?ltr=r').context['object_list']),
45             2,
46             'Both notes start with the letter R.')
47
48         self.assertEqual(
49             len(self.client.get('/przypisy/?qual=techn.').context['object_list']),
50             1,
51             'There should be a note qualified with \'techn.\' qualifier.')