-
Notifications
You must be signed in to change notification settings - Fork 34
/
tests.py
123 lines (112 loc) · 4.49 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from django.core.exceptions import ImproperlyConfigured
from django.template import TemplateSyntaxError
from django.test import TestCase
from mjml import settings as mjml_settings
from mjml.apps import check_mjml_command
from testprj.tools import safe_change_mjml_settings, render_tpl, MJMLFixtures
class TestMJMLApps(TestCase):
def test_check_mjml_command(self) -> None:
with safe_change_mjml_settings():
mjml_settings.MJML_EXEC_CMD = '/no_mjml_exec_test'
with self.assertRaises(ImproperlyConfigured):
check_mjml_command()
mjml_settings.MJML_EXEC_CMD = ['python', '-c', 'print("wrong result for testing")', '-']
with self.assertRaises(ImproperlyConfigured):
check_mjml_command()
class TestMJMLTemplatetag(MJMLFixtures, TestCase):
def test_simple(self) -> None:
html = render_tpl(self.TPLS['simple'])
self.assertIn('<html ', html)
self.assertIn('<body', html)
self.assertIn('20px ', html)
self.assertIn('Test title', html)
self.assertIn('Test button', html)
def test_with_vars(self) -> None:
context = {
'title': 'Test title',
'title_size': '20px',
'btn_label': 'Test button',
'btn_color': '#ffcc00'
}
html = render_tpl("""
{% mjml %}
<mjml>
<mj-body>
<mj-container>
<mj-section>
<mj-column>
<mj-image src="img/test.png"></mj-image>
<mj-text font-size="{{ title_size }}" align="center">{{ title }}</mj-text>
</mj-column>
</mj-section>
<mj-section>
<mj-column>
<mj-button background-color="{{ btn_color }}" font-size="15px">{{ btn_label }}</mj-button>
</mj-column>
</mj-section>
</mj-container>
</mj-body>
</mjml>
{% endmjml %}
""", context)
self.assertIn('<html ', html)
self.assertIn('<body', html)
for val in context.values():
self.assertIn(val, html)
def test_with_tags(self) -> None:
items = ['test one', 'test two', 'test three']
context = {
'items': items,
}
html = render_tpl("""
{% mjml %}
<mjml>
<mj-body>
<mj-container>
<mj-section>
<mj-column>
<mj-image src="img/test.png"></mj-image>
<mj-text font-size="20px" align="center">Test title</mj-text>
</mj-column>
</mj-section>
<mj-section>
<mj-column>
{# test_comment $}
{% for item in items %}
<mj-text align="center">{{ item }}</mj-text>
{% endfor %}
<mj-button background-color="#ffcc00" font-size="15px">Test button</mj-button>
</mj-column>
</mj-section>
</mj-container>
</mj-body>
</mjml>
{% endmjml %}
""", context)
self.assertIn('<html ', html)
self.assertIn('<body', html)
for item in items:
self.assertIn(item, html)
self.assertNotIn('test_comment', html)
def test_error(self) -> None:
with self.assertRaises(TemplateSyntaxError):
render_tpl("""
{% mjml "var"%}
<mjml><mj-body><mj-container></mj-container></mj-body></mjml>
{% endmjml %}
""")
with self.assertRaises(TemplateSyntaxError):
render_tpl("""
{% mjml var %}
<mjml><mj-body><mj-container></mj-container></mj-body></mjml>
{% endmjml %}
""", {'var': 'test'})
def test_unicode(self) -> None:
html = render_tpl(self.TPLS['with_text_context_and_unicode'], {
'text': self.TEXTS['unicode'],
})
self.assertIn('<html ', html)
self.assertIn('<body', html)
self.assertIn('Український текст', html)
self.assertIn(self.TEXTS['unicode'], html)
self.assertIn('©', html)