Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ok_(url.startswith('https://'))
if 'style1.css' in url:
return MockResponse(
"h1 { color: brown }"
)
if 'style2.css' in url:
return MockResponse(
"h2 { color: pink }"
)
if 'style3.css' in url:
return MockResponse(
"h3 { color: red }", gzip=True
)
urlopen = mocked_urlopen
p = Premailer(
html,
base_url='https://www.peterbe.com'
)
result_html = p.transform()
compare_html(expect_html, result_html)
expect_html = """
<title>Title</title>
<style type="text/css">a:hover {color:purple !important}</style>
<h1 style="color:orange">Hello</h1>
<h2 style="color:green">World</h2>
<h3 style="color:yellow">Test</h3>
<a style="color:pink" href="#">Link</a>
"""
p = Premailer(
html,
strip_important=False
)
result_html = p.transform()
compare_html(expect_html, result_html)
<a href="#">Hi!</a>
"""
expect_html = """
<title>Title</title>
<style type="text/css">a:hover {color:green !important}
a:focus {color:blue !important}</style>
<a style="color:red" href="#">Hi!</a>
"""
p = Premailer(html,
keep_style_tags=True,
strip_important=False)
result_html = p.transform()
compare_html(expect_html, result_html)
def test_broken_xml(self):
"""Test the simplest case with xml"""
html = """
<title>Title
<style type="text/css">
img { border: none; }
</style>
</head>
<body>
<img src="test.png" alt="test"/>
</body>
"""
p = Premailer(html, method="xml")
assert_raises(
XMLSyntaxError,
p.transform,
)</title>
<div class="example"></div>
"""
expect_html = """
<div style="color:green"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
<div class="example"></div>
"""
expect_html = """
<div style="color:green"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
<div id="identified" class="example"></div>
"""
expect_html = """
<div style="color:green" id="identified"></div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
expect_html = """
<p style="text-align:center">Text</p>
<table style="height:300px; width:200px">
<tbody><tr>
<td bgcolor="red" style="background-color:red">Cell 1</td>
<td bgcolor="red" style="background-color:red">Cell 2</td>
</tr>
</tbody></table>
"""
p = Premailer(
html,
exclude_pseudoclasses=True,
disable_basic_attributes=['align', 'width', 'height']
)
result_html = p.transform()
expect_html = re.sub('}\s+', '}', expect_html)
result_html = result_html.replace('}\n', '}')
compare_html(expect_html, result_html)
<div>First div</div>
"""
expect_html = """
<div align="right" style="text-align:right">First div</div>
"""
p = Premailer(html)
result_html = p.transform()
compare_html(expect_html, result_html)
<h1>Hello</h1>
<h2>World</h2>
<h3>Test</h3>
<a href="#">Link</a>
"""
p = Premailer(
html,
strip_important=False
)
assert_raises(
ExternalNotFoundError,
p.transform,
)