Images: image@src is a URL, and image sizes are limited.
[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.builders import builders
12 from librarian.document import WLDocument
13 from librarian.parser import WLDocument as LegacyWLDocument
14 from nose.tools import *
15 from .utils import get_fixture
16
17
18 class TransformTest(TestCase):
19     maxDiff = None
20
21     def test_transform_legacy(self):
22         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.legacy.html')
23
24         html = LegacyWLDocument.from_file(
25             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
26         ).as_html().get_bytes().decode('utf-8')
27
28         self.assertEqual(html, io.open(expected_output_file_path).read())
29
30     def test_transform(self):
31         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.html')
32         html = WLDocument(
33             filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
34         ).build(builders['html']).get_bytes().decode('utf-8')
35
36         self.assertEqual(html, io.open(expected_output_file_path).read())
37
38
39 @raises(NoDublinCore)
40 def test_no_dublincore():
41     LegacyWLDocument.from_file(
42             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
43         ).as_html()
44
45
46 def test_passing_parse_dublincore_to_transform():
47     """Passing parse_dublincore=False to transform omits DublinCore parsing."""
48     LegacyWLDocument.from_file(
49             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
50             parse_dublincore=False,
51         ).as_html()
52
53
54 def test_empty():
55     assert not LegacyWLDocument.from_bytes(
56             b'<utwor />',
57             parse_dublincore=False,
58         ).as_html()