-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest is clearly the preferred tool for testing in Python.
- Loading branch information
1 parent
2107589
commit b57669a
Showing
8 changed files
with
221 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
|
||
from unittest import TestCase | ||
|
||
from mjml.helpers import borderParser | ||
|
||
|
||
class BorderParserTest(TestCase): | ||
def test_can_parse_css_none(self): | ||
self.assertEqual(0, borderParser('none')) | ||
def test_can_parse_css_none(): | ||
assert borderParser('none') == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
|
||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
import pytest | ||
from schwarz.fakefs_helpers import FakeFS | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class IncludesWithUmlautsTest(TestCase): | ||
def test_can_properly_handle_include_umlauts(self): | ||
fs = FakeFS.set_up(test=self) | ||
included_mjml = ( | ||
'<mj-section>' | ||
' <mj-column>' | ||
' <mj-text>äöüß</mj-text>' | ||
' </mj-column>' | ||
'</mj-section>' | ||
) | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-text>foo bar</mj-text>' | ||
' <mj-include path="./footer.mjml" />' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
fs.create_file('footer.mjml', contents=included_mjml.encode('utf8')) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
|
||
assert ('äöüß' in html) | ||
@pytest.fixture | ||
def fs(): | ||
_fs = FakeFS.set_up() | ||
yield _fs | ||
_fs.tear_down() | ||
|
||
|
||
def test_can_properly_handle_include_umlauts(fs): | ||
included_mjml = ( | ||
'<mj-section>' | ||
' <mj-column>' | ||
' <mj-text>äöüß</mj-text>' | ||
' </mj-column>' | ||
'</mj-section>' | ||
) | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-text>foo bar</mj-text>' | ||
' <mj-include path="./footer.mjml" />' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
fs.create_file('footer.mjml', contents=included_mjml.encode('utf8')) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
|
||
assert ('äöüß' in html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
|
||
import re | ||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
import lxml.html | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class MjButtonMailtoLinkTest(TestCase): | ||
def test_no_target_for_mailto_links(self): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-button href="mailto:[email protected]">Click me</mj-button>' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
def test_no_target_for_mailto_links(): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <mj-button href="mailto:[email protected]">Click me</mj-button>' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
|
||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
mailto_match = re.search('<a href="([^"]+?)"[^>]*>', html) | ||
start, end = mailto_match.span() | ||
match_str = html[start:end] | ||
result = mjml_to_html(StringIO(mjml)) | ||
html = result.html | ||
mailto_match = re.search('<a href="([^"]+?)"[^>]*>', html) | ||
start, end = mailto_match.span() | ||
match_str = html[start:end] | ||
|
||
a_el = lxml.html.fragment_fromstring(match_str) | ||
self.assertEqual('mailto:[email protected]', a_el.attrib['href']) | ||
target = a_el.attrib.get('target') | ||
# Thunderbird opens a blank page instead of the new message window if | ||
# the <a> contains 'target="_blank"'. | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1677248 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1589968 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=421310 | ||
assert not target, f'target="{target}"' | ||
a_el = lxml.html.fragment_fromstring(match_str) | ||
assert a_el.attrib['href'] == 'mailto:[email protected]' | ||
target = a_el.attrib.get('target') | ||
# Thunderbird opens a blank page instead of the new message window if | ||
# the <a> contains 'target="_blank"'. | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1677248 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=1589968 | ||
# https://bugzilla.mozilla.org/show_bug.cgi?id=421310 | ||
assert not target, f'target="{target}"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
|
||
from io import StringIO | ||
from unittest import TestCase | ||
|
||
from mjml import mjml_to_html | ||
|
||
|
||
class MJML2HTMLTest(TestCase): | ||
def test_can_handle_comments_in_mjml(self): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <!-- empty -->' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
mjml_to_html(StringIO(mjml)) | ||
def test_can_handle_comments_in_mjml(): | ||
mjml = ( | ||
'<mjml>' | ||
' <mj-body>' | ||
' <!-- empty -->' | ||
' </mj-body>' | ||
'</mjml>' | ||
) | ||
mjml_to_html(StringIO(mjml)) |
Oops, something went wrong.