Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_html_entities(self):
frame_html = '<p>test %s</p><p><a href="foo">%s</a></p>'
for url, expected in self.data_pairs.items():
esc_url = url.replace('&', '&')
html = frame_html % (esc_url, esc_url)
all_urls, extracted = test_pr.extract_html(html)
self.assertEqual(all_urls, [url])
if 'url' not in expected:
expected['url'] = url
if 'title' not in expected:
expected['title'] = expected['url']
self.assertEqual(extracted, {url: expected})
rendered = test_pr.parse_html('<p>%s</p>' % esc_url)
self.assertHTMLEqual(rendered, '<p>%s</p>' % self.full_pairs[url])
expected_inline = self.inline_pairs[url]
frame = '%s\nthis is inline: %s\n%s'
test_str = frame % (url, url, url)
parsed = test_pr.parse_text(test_str)
self.assertHTMLEqual(parsed, frame % (expected, expected_inline, expected))
# test mixing multiline with p tags
for url, expected in self.full_pairs.items():
expected_inline = self.inline_pairs[url]
frame = '<p>%s</p>\n<p>this is inline: %s</p>\n<p>\n%s\n</p><p>last test\n%s\n</p>'
test_str = frame % (url, url, url, url)
parsed = test_pr.parse_html(test_str)
self.assertHTMLEqual(parsed, frame % (expected, expected_inline, expected, expected_inline))
for url, expected in self.full_pairs.items():
expected_inline = self.inline_pairs[url]
frame = '<p><a href="#foo">%s</a></p>\n<p>this is inline: %s</p>\n<p>last test\n%s\n</p>'
test_str = frame % (url, url, url)
parsed = test_pr.parse_html(test_str)
self.assertHTMLEqual(parsed, frame % (url, expected_inline, expected_inline))
def test_provider_loading(self):
from micawber.contrib.mcdjango import providers
self.assertEqual(providers, test_pr)
def test_extract(self):
blank = 'http://fapp.io/foo/'
frame = 'test %s\n%s\n%s\n%s at last'
frame_html = '<p>test %s</p><p><a href="foo">%s</a> %s</p><p>%s</p>'
for url, expected in self.data_pairs.items():
text = frame % (url, blank, url, blank)
all_urls, extracted = test_pr.extract(text)
self.assertEqual(all_urls, [url, blank])
if 'url' not in expected:
expected['url'] = url
if 'title' not in expected:
expected['title'] = expected['url']
self.assertEqual(extracted, {url: expected})
html = frame_html % (url, url, blank, blank)
all_urls, extracted = test_pr.extract_html(html)
self.assertEqual(all_urls, [url, blank])
if 'url' not in expected:
expected['url'] = url
self.assertEqual(extracted, {url: expected})