1 # -*- coding: utf-8 -*-
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from __future__ import unicode_literals
9 from zipfile import ZipFile
10 from ebooklib import epub
12 from nose.tools import *
13 from librarian import DirDocProvider
14 from librarian.parser import WLDocument
15 from tests.utils import get_fixture
19 epub_file = WLDocument.from_file(
20 get_fixture('text', 'asnyk_zbior.xml'),
21 provider=DirDocProvider(get_fixture('text', ''))
22 ).as_epub(cover=True, flags=['without_fonts'])
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(u'Opracowanie redakcyjne i przypisy:'):
31 editors_attribution = True
34 u'Opracowanie redakcyjne i przypisy: '
35 u'Adam Fikcyjny, Aleksandra Sekuła, Olga Sutkowska.')
36 assert_true(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': 'part1.xhtml', 'title': 'Początek', 'type': 'text'},
53 {'href': 'cover.xhtml', 'title': 'Okładka', 'type': 'cover'}
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": "creator"})]
84 book.get_metadata(DC, "publisher"),
85 [('Fundacja Nowoczesna Polska', {})]
88 book.get_metadata(DC, "date"),
93 def test_transform_hyphenate():
94 epub = WLDocument.from_file(
95 get_fixture('text', 'asnyk_zbior.xml'),
96 provider=DirDocProvider(get_fixture('text', ''))
98 flags=['without_fonts'],