1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
6 from zipfile import ZipFile
7 from ebooklib import epub
9 from librarian import DirDocProvider
10 from librarian.builders import EpubBuilder
11 from librarian.document import WLDocument
12 from tests.utils import get_fixture
15 class EpubTests(unittest.TestCase):
16 def test_transform(self):
17 epub_file = EpubBuilder().build(
19 get_fixture('text', 'asnyk_zbior.xml'),
20 provider=DirDocProvider(get_fixture('text', ''))
23 zipf = ZipFile(epub_file.get_file())
25 # Check contributor list.
26 last = zipf.open('EPUB/last.xhtml')
27 tree = html.parse(last)
28 editors_attribution = False
29 for par in tree.findall("//p"):
30 if par.text.startswith('Opracowanie redakcyjne i przypisy:'):
31 editors_attribution = True
34 'Opracowanie redakcyjne i przypisy: '
35 'Adam Fikcyjny, Aleksandra Sekuła, Olga Sutkowska.')
36 self.assertTrue(editors_attribution)
38 # Check that we have a valid EPUB.
41 'epubcheck', '-quiet', epub_file.get_filename()
46 book = epub.read_epub(epub_file.get_filename())
48 # Check that guide items are there.
52 {'href': 'cover.xhtml', 'title': 'Okładka', 'type': 'cover'},
53 {'href': 'part1.xhtml', 'title': 'Początek', 'type': 'text'},
57 # Check that metadata is there.
58 DC = "http://purl.org/dc/elements/1.1/"
59 OPF = "http://www.idpf.org/2007/opf"
62 book.get_metadata(OPF, "cover"),
63 [(None, {'name': 'cover', 'content': 'cover-img'})]
66 book.get_metadata(DC, "title"),
70 book.get_metadata(DC, "language"),
74 book.get_metadata(DC, "identifier"),
75 [('http://wolnelektury.pl/katalog/lektura/poezye', {
80 book.get_metadata(DC, "creator"),
81 [('Adam Asnyk', {"id": "creator0"})]
84 book.get_metadata(DC, "publisher"),
85 [('Fundacja Wolne Lektury', {})]
88 book.get_metadata(DC, "date"),