From 48b5829aea007bce620ad3db7bfd1dc25cbf9837 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 16 Aug 2016 14:53:18 +0100 Subject: Fix up preview URL API. Add tests. This includes: - Splitting out methods of a class into stand alone functions, to make them easier to test. - Adding unit tests to split out functions, testing HTML -> preview. - Handle the fact that elements in lxml may have tail text. --- tests/test_preview.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) (limited to 'tests/test_preview.py') diff --git a/tests/test_preview.py b/tests/test_preview.py index 2a801173a0..c8d6525a01 100644 --- a/tests/test_preview.py +++ b/tests/test_preview.py @@ -15,7 +15,9 @@ from . import unittest -from synapse.rest.media.v1.preview_url_resource import summarize_paragraphs +from synapse.rest.media.v1.preview_url_resource import ( + summarize_paragraphs, decode_and_calc_og +) class PreviewTestCase(unittest.TestCase): @@ -137,3 +139,79 @@ class PreviewTestCase(unittest.TestCase): " of old wooden houses in Northern Norway, the oldest house dating from" " 1789. The Arctic Cathedral, a modern church…" ) + + +class PreviewUrlTestCase(unittest.TestCase): + def test_simple(self): + html = """ + + Foo + + Some text. + + + """ + + og = decode_and_calc_og(html, "http://example.com/test.html") + + self.assertEquals(og, { + "og:title": "Foo", + "og:description": "Some text." + }) + + def test_comment(self): + html = """ + + Foo + + + Some text. + + + """ + + og = decode_and_calc_og(html, "http://example.com/test.html") + + self.assertEquals(og, { + "og:title": "Foo", + "og:description": "Some text." + }) + + def test_comment2(self): + html = """ + + Foo + + Some text. + + Some more text. +

Text

+ More text + + + """ + + og = decode_and_calc_og(html, "http://example.com/test.html") + + self.assertEquals(og, { + "og:title": "Foo", + "og:description": "Some text.\n\nSome more text.\n\nText\n\nMore text" + }) + + def test_script(self): + html = """ + + Foo + + + Some text. + + + """ + + og = decode_and_calc_og(html, "http://example.com/test.html") + + self.assertEquals(og, { + "og:title": "Foo", + "og:description": "Some text." + }) -- cgit 1.4.1