Missing toc items.
[librarian.git] / tests / test_html.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 from __future__ import unicode_literals
7
8 import io
9 from unittest import TestCase
10 from librarian import NoDublinCore
11 from librarian.document import WLDocument
12 from librarian.parser import WLDocument as LegacyWLDocument
13 from nose.tools import *
14 from .utils import get_fixture
15
16
17 class TransformTest(TestCase):
18     maxDiff = None
19
20     def test_transform_legacy(self):
21         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.legacy.html')
22
23         html = LegacyWLDocument.from_file(
24             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
25         ).as_html().get_bytes().decode('utf-8')
26
27         self.assertEqual(html, io.open(expected_output_file_path).read())
28
29     def test_transform(self):
30         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.html')
31         html = WLDocument(
32             filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
33         ).build('html').get_bytes().decode('utf-8')
34
35         self.assertEqual(html, io.open(expected_output_file_path).read())
36
37
38 @raises(NoDublinCore)
39 def test_no_dublincore():
40     LegacyWLDocument.from_file(
41             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
42         ).as_html()
43
44
45 def test_passing_parse_dublincore_to_transform():
46     """Passing parse_dublincore=False to transform omits DublinCore parsing."""
47     LegacyWLDocument.from_file(
48             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
49             parse_dublincore=False,
50         ).as_html()
51
52
53 def test_empty():
54     assert not LegacyWLDocument.from_bytes(
55             b'<utwor />',
56             parse_dublincore=False,
57         ).as_html()