-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
78 lines (55 loc) · 2.3 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from unittest import TestCase
from xml.etree import ElementTree
import xmltodict
from markdown import Markdown
from mdx_staticfiles import (
DjangoStaticAssetsProcessor, StaticfilesExtension, makeExtension)
class XmlTestCaseMixin(object):
""" Helper class for asserting that XML documents describe the same XML
structures.
"""
def mk_doc(self, s):
return ElementTree.fromstring(
"<div>" + s.strip() + "</div>")
def assert_xml_equal(self, a, b):
self.assertEqual(
xmltodict.parse(ElementTree.tostring(a)),
xmltodict.parse(ElementTree.tostring(b)))
def assert_xmltext_equal(self, a, b):
self.assert_xml_equal(self.mk_doc(a), self.mk_doc(b))
class TestSubstitution(XmlTestCaseMixin, TestCase):
""" Test our substitions of django static paths """
def setUp(self):
self.md = Markdown()
ext = StaticfilesExtension()
ext.extendMarkdown(self.md)
def test_link(self):
xml = self.md.convert('[a]({% static "a.html" %})')
self.assert_xmltext_equal(xml, '<p><a href="/st/a.html">a</a></p>')
def test_image(self):
xml = self.md.convert('![a]({% static "a.jpg" %})')
self.assert_xmltext_equal(xml, '<p><img alt="a" src="/st/a.jpg"/></p>')
def test_inline_html(self):
xml = self.md.convert('<img src="{% static "a.jpg" %}"/>')
self.assert_xmltext_equal(xml, '<p><img src="/st/a.jpg"/></p>')
class TestStaticfilesExtension(TestCase):
""" Test StaticfilesExtension class. """
def mk_markdown(self):
md = Markdown()
return md
def assert_registered(self, md):
postprocessor = md.postprocessors['staticfiles']
self.assertTrue(isinstance(postprocessor, DjangoStaticAssetsProcessor))
def assert_not_registered(self, md):
self.assertFalse('staticfiles' in md.postprocessors)
def test_extend_markdown(self):
md = self.mk_markdown()
ext = StaticfilesExtension()
self.assert_not_registered(md)
ext.extendMarkdown(md)
self.assert_registered(md)
class TestExtensionRegistration(TestCase):
""" Test registration of staticfiles extension. """
def test_make_extension(self):
ext = makeExtension()
self.assertTrue(isinstance(ext, StaticfilesExtension))