2020-06-11 00:54:34 +02:00
|
|
|
from typing import Any, Callable, Dict, Optional
|
2020-05-26 07:16:25 +02:00
|
|
|
from unittest import mock
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2016-10-27 12:06:44 +02:00
|
|
|
import ujson
|
|
|
|
from django.test import override_settings
|
2019-05-02 18:58:39 +02:00
|
|
|
from django.utils.html import escape
|
2020-06-11 00:54:34 +02:00
|
|
|
from requests.exceptions import ConnectionError
|
2016-10-27 12:06:44 +02:00
|
|
|
|
2017-11-06 20:48:55 +01:00
|
|
|
from zerver.lib.actions import queue_json_publish
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.cache import NotFoundInCache, cache_set, preview_url_cache_key
|
2016-10-27 12:06:44 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2016-12-13 04:20:33 +01:00
|
|
|
from zerver.lib.test_helpers import MockPythonResponse
|
2019-12-12 09:39:41 +01:00
|
|
|
from zerver.lib.url_preview.oembed import get_oembed_data, strip_cdata
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.url_preview.parsers import GenericParser, OpenGraphParser
|
|
|
|
from zerver.lib.url_preview.preview import get_link_embed_data, link_embed_data_from_cache
|
|
|
|
from zerver.models import Message, Realm, UserProfile
|
|
|
|
from zerver.worker.queue_processors import FetchLinksEmbedData
|
2016-10-27 12:06:44 +02:00
|
|
|
|
2016-12-13 04:20:33 +01:00
|
|
|
TEST_CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
|
|
|
'LOCATION': 'default',
|
|
|
|
},
|
|
|
|
'database': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
|
|
|
'LOCATION': 'url-preview',
|
2019-05-02 17:14:08 +02:00
|
|
|
},
|
|
|
|
'in-memory': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
|
|
|
'LOCATION': 'url-preview',
|
|
|
|
},
|
2016-12-13 04:20:33 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 12:06:44 +02:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
class OembedTestCase(ZulipTestCase):
|
|
|
|
@mock.patch('pyoembed.requests.get')
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_present_provider(self, get: Any) -> None:
|
2016-10-27 12:06:44 +02:00
|
|
|
get.return_value = response = mock.Mock()
|
|
|
|
response.headers = {'content-type': 'application/json'}
|
|
|
|
response.ok = True
|
|
|
|
response_data = {
|
|
|
|
'type': 'rich',
|
|
|
|
'thumbnail_url': 'https://scontent.cdninstagram.com/t51.2885-15/n.jpg',
|
|
|
|
'thumbnail_width': 640,
|
|
|
|
'thumbnail_height': 426,
|
|
|
|
'title': 'NASA',
|
|
|
|
'html': '<p>test</p>',
|
|
|
|
'version': '1.0',
|
|
|
|
'width': 658,
|
2019-05-02 18:58:39 +02:00
|
|
|
'height': 400}
|
2016-10-27 12:06:44 +02:00
|
|
|
response.text = ujson.dumps(response_data)
|
|
|
|
url = 'http://instagram.com/p/BLtI2WdAymy'
|
|
|
|
data = get_oembed_data(url)
|
|
|
|
self.assertIsInstance(data, dict)
|
|
|
|
self.assertIn('title', data)
|
2018-06-16 22:59:39 +02:00
|
|
|
assert data is not None # allow mypy to infer data is indexable
|
2016-10-27 12:06:44 +02:00
|
|
|
self.assertEqual(data['title'], response_data['title'])
|
|
|
|
|
2019-05-26 06:27:01 +02:00
|
|
|
@mock.patch('pyoembed.requests.get')
|
|
|
|
def test_photo_provider(self, get: Any) -> None:
|
|
|
|
get.return_value = response = mock.Mock()
|
|
|
|
response.headers = {'content-type': 'application/json'}
|
|
|
|
response.ok = True
|
|
|
|
response_data = {
|
|
|
|
'type': 'photo',
|
|
|
|
'thumbnail_url': 'https://scontent.cdninstagram.com/t51.2885-15/n.jpg',
|
|
|
|
'url': 'https://scontent.cdninstagram.com/t51.2885-15/n.jpg',
|
|
|
|
'thumbnail_width': 640,
|
|
|
|
'thumbnail_height': 426,
|
|
|
|
'title': 'NASA',
|
|
|
|
'html': '<p>test</p>',
|
|
|
|
'version': '1.0',
|
|
|
|
'width': 658,
|
|
|
|
'height': 400}
|
|
|
|
response.text = ujson.dumps(response_data)
|
|
|
|
url = 'http://imgur.com/photo/158727223'
|
|
|
|
data = get_oembed_data(url)
|
|
|
|
self.assertIsInstance(data, dict)
|
|
|
|
self.assertIn('title', data)
|
|
|
|
assert data is not None # allow mypy to infer data is indexable
|
|
|
|
self.assertEqual(data['title'], response_data['title'])
|
|
|
|
self.assertTrue(data['oembed'])
|
|
|
|
|
2019-05-02 18:58:39 +02:00
|
|
|
@mock.patch('pyoembed.requests.get')
|
|
|
|
def test_video_provider(self, get: Any) -> None:
|
|
|
|
get.return_value = response = mock.Mock()
|
|
|
|
response.headers = {'content-type': 'application/json'}
|
|
|
|
response.ok = True
|
|
|
|
response_data = {
|
|
|
|
'type': 'video',
|
|
|
|
'thumbnail_url': 'https://scontent.cdninstagram.com/t51.2885-15/n.jpg',
|
|
|
|
'thumbnail_width': 640,
|
|
|
|
'thumbnail_height': 426,
|
|
|
|
'title': 'NASA',
|
|
|
|
'html': '<p>test</p>',
|
|
|
|
'version': '1.0',
|
|
|
|
'width': 658,
|
|
|
|
'height': 400}
|
|
|
|
response.text = ujson.dumps(response_data)
|
|
|
|
url = 'http://blip.tv/video/158727223'
|
|
|
|
data = get_oembed_data(url)
|
|
|
|
self.assertIsInstance(data, dict)
|
|
|
|
self.assertIn('title', data)
|
|
|
|
assert data is not None # allow mypy to infer data is indexable
|
|
|
|
self.assertEqual(data['title'], response_data['title'])
|
|
|
|
|
2016-10-27 12:06:44 +02:00
|
|
|
@mock.patch('pyoembed.requests.get')
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_error_request(self, get: Any) -> None:
|
2016-10-27 12:06:44 +02:00
|
|
|
get.return_value = response = mock.Mock()
|
|
|
|
response.ok = False
|
|
|
|
url = 'http://instagram.com/p/BLtI2WdAymy'
|
|
|
|
data = get_oembed_data(url)
|
|
|
|
self.assertIsNone(data)
|
|
|
|
|
2020-04-11 13:24:06 +02:00
|
|
|
@mock.patch('pyoembed.requests.get')
|
|
|
|
def test_invalid_json_in_response(self, get: Any) -> None:
|
|
|
|
get.return_value = response = mock.Mock()
|
|
|
|
response.headers = {'content-type': 'application/json'}
|
|
|
|
response.ok = True
|
|
|
|
response.text = '{invalid json}'
|
|
|
|
url = 'http://instagram.com/p/BLtI2WdAymy'
|
|
|
|
data = get_oembed_data(url)
|
|
|
|
self.assertIsNone(data)
|
|
|
|
|
2019-12-12 09:39:41 +01:00
|
|
|
def test_oembed_html(self) -> None:
|
2019-05-02 18:58:39 +02:00
|
|
|
html = '<iframe src="//www.instagram.com/embed.js"></iframe>'
|
2019-12-12 09:39:41 +01:00
|
|
|
stripped_html = strip_cdata(html)
|
|
|
|
self.assertEqual(html, stripped_html)
|
2019-05-02 18:58:39 +02:00
|
|
|
|
|
|
|
def test_autodiscovered_oembed_xml_format_html(self) -> None:
|
|
|
|
iframe_content = '<iframe src="https://w.soundcloud.com/player"></iframe>'
|
2020-06-09 00:25:09 +02:00
|
|
|
html = f'<![CDATA[{iframe_content}]]>'
|
2019-12-12 09:39:41 +01:00
|
|
|
stripped_html = strip_cdata(html)
|
|
|
|
self.assertEqual(iframe_content, stripped_html)
|
2019-05-02 18:58:39 +02:00
|
|
|
|
2016-10-27 12:06:44 +02:00
|
|
|
|
|
|
|
class OpenGraphParserTestCase(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_page_with_og(self) -> None:
|
2016-10-27 12:06:44 +02:00
|
|
|
html = """<html>
|
|
|
|
<head>
|
|
|
|
<meta property="og:title" content="The Rock" />
|
|
|
|
<meta property="og:type" content="video.movie" />
|
|
|
|
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
|
|
|
|
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
|
|
|
|
<meta property="og:description" content="The Rock film" />
|
|
|
|
</head>
|
|
|
|
</html>"""
|
|
|
|
|
|
|
|
parser = OpenGraphParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertIn('title', result)
|
|
|
|
self.assertEqual(result['title'], 'The Rock')
|
|
|
|
self.assertEqual(result.get('description'), 'The Rock film')
|
|
|
|
|
2019-12-12 02:10:50 +01:00
|
|
|
def test_page_with_evil_og_tags(self) -> None:
|
|
|
|
html = """<html>
|
|
|
|
<head>
|
|
|
|
<meta property="og:title" content="The Rock" />
|
|
|
|
<meta property="og:type" content="video.movie" />
|
|
|
|
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
|
|
|
|
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
|
|
|
|
<meta property="og:description" content="The Rock film" />
|
|
|
|
<meta property="og:html" content="<script>alert(window.location)</script>" />
|
|
|
|
<meta property="og:oembed" content="True" />
|
|
|
|
</head>
|
|
|
|
</html>"""
|
|
|
|
|
|
|
|
parser = OpenGraphParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertIn('title', result)
|
|
|
|
self.assertEqual(result['title'], 'The Rock')
|
|
|
|
self.assertEqual(result.get('description'), 'The Rock film')
|
|
|
|
self.assertEqual(result.get('oembed'), None)
|
|
|
|
self.assertEqual(result.get('html'), None)
|
2016-10-27 12:06:44 +02:00
|
|
|
|
|
|
|
class GenericParserTestCase(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_parser(self) -> None:
|
2016-10-27 12:06:44 +02:00
|
|
|
html = """
|
|
|
|
<html>
|
|
|
|
<head><title>Test title</title></head>
|
|
|
|
<body>
|
|
|
|
<h1>Main header</h1>
|
|
|
|
<p>Description text</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
parser = GenericParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertEqual(result.get('title'), 'Test title')
|
|
|
|
self.assertEqual(result.get('description'), 'Description text')
|
2016-12-13 04:20:33 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_extract_image(self) -> None:
|
2016-12-13 04:20:33 +01:00
|
|
|
html = """
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<h1>Main header</h1>
|
|
|
|
<img src="http://test.com/test.jpg">
|
|
|
|
<div>
|
|
|
|
<p>Description text</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
parser = GenericParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertEqual(result.get('title'), 'Main header')
|
|
|
|
self.assertEqual(result.get('description'), 'Description text')
|
|
|
|
self.assertEqual(result.get('image'), 'http://test.com/test.jpg')
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_extract_description(self) -> None:
|
2016-12-13 04:20:33 +01:00
|
|
|
html = """
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<p>Description text</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
parser = GenericParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertEqual(result.get('description'), 'Description text')
|
|
|
|
|
|
|
|
html = """
|
|
|
|
<html>
|
|
|
|
<head><meta name="description" content="description 123"</head>
|
|
|
|
<body></body>
|
|
|
|
</html>
|
|
|
|
"""
|
|
|
|
parser = GenericParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertEqual(result.get('description'), 'description 123')
|
|
|
|
|
|
|
|
html = "<html><body></body></html>"
|
|
|
|
parser = GenericParser(html)
|
|
|
|
result = parser.extract_data()
|
|
|
|
self.assertIsNone(result.get('description'))
|
|
|
|
|
|
|
|
|
|
|
|
class PreviewTestCase(ZulipTestCase):
|
2017-02-23 06:17:16 +01:00
|
|
|
open_graph_html = """
|
2016-12-13 04:20:33 +01:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test title</title>
|
|
|
|
<meta property="og:title" content="The Rock" />
|
|
|
|
<meta property="og:type" content="video.movie" />
|
|
|
|
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
|
|
|
|
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
|
2019-12-12 02:10:50 +01:00
|
|
|
<meta http-equiv="refresh" content="30" />
|
|
|
|
<meta property="notog:extra-text" content="Extra!" />
|
2016-12-13 04:20:33 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Main header</h1>
|
|
|
|
<p>Description text</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""
|
2017-02-23 06:17:16 +01:00
|
|
|
|
2019-05-31 04:45:02 +02:00
|
|
|
def setUp(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
super().setUp()
|
2019-05-31 04:45:02 +02:00
|
|
|
Realm.objects.all().update(inline_url_embed_preview=True)
|
|
|
|
|
2019-05-05 06:41:34 +02:00
|
|
|
@classmethod
|
2019-05-04 17:54:18 +02:00
|
|
|
def create_mock_response(cls, url: str, relative_url: bool=False,
|
2019-06-23 13:36:58 +02:00
|
|
|
headers: Optional[Dict[str, str]]=None,
|
|
|
|
html: Optional[str]=None) -> Callable[..., MockPythonResponse]:
|
|
|
|
if html is None:
|
|
|
|
html = cls.open_graph_html
|
2019-05-05 06:41:34 +02:00
|
|
|
if relative_url is True:
|
|
|
|
html = html.replace('http://ia.media-imdb.com', '')
|
2019-05-04 17:54:18 +02:00
|
|
|
response = MockPythonResponse(html, 200, headers)
|
|
|
|
return lambda k, **kwargs: {url: response}.get(k, MockPythonResponse('', 404, headers))
|
2019-05-05 06:41:34 +02:00
|
|
|
|
2017-02-23 06:16:30 +01:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_edit_message_history(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland",
|
2017-10-28 17:07:36 +02:00
|
|
|
topic_name="editing", content="original")
|
2017-02-23 06:20:01 +01:00
|
|
|
|
|
|
|
url = 'http://test.org/'
|
2019-05-05 06:41:34 +02:00
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url))
|
2017-02-23 06:20:01 +01:00
|
|
|
|
2020-06-22 22:57:01 +02:00
|
|
|
with mock.patch('zerver.views.message_edit.queue_json_publish') as patched:
|
2017-02-23 06:20:01 +01:00
|
|
|
result = self.client_patch("/json/messages/" + str(msg_id), {
|
|
|
|
'message_id': msg_id, 'content': url,
|
|
|
|
})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
|
2020-06-09 00:25:09 +02:00
|
|
|
embedded_link = f'<a href="{url}" title="The Rock">The Rock</a>'
|
2017-02-23 06:20:01 +01:00
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertIn(embedded_link, msg.rendered_content)
|
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
2020-03-07 11:43:05 +01:00
|
|
|
def _send_message_with_test_org_url(self, sender: UserProfile, queue_should_run: bool=True,
|
2017-11-17 07:00:53 +01:00
|
|
|
relative_url: bool=False) -> Message:
|
2016-12-13 04:20:33 +01:00
|
|
|
url = 'http://test.org/'
|
2017-02-23 06:16:30 +01:00
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2017-10-28 17:07:36 +02:00
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
sender,
|
|
|
|
self.example_user('cordelia'),
|
2017-10-28 17:07:36 +02:00
|
|
|
content=url,
|
|
|
|
)
|
2017-02-23 06:16:30 +01:00
|
|
|
if queue_should_run:
|
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
else:
|
|
|
|
patched.assert_not_called()
|
|
|
|
# If we nothing was put in the queue, we don't need to
|
|
|
|
# run the queue processor or any of the following code
|
|
|
|
return Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
|
|
|
|
# Verify the initial message doesn't have the embedded links rendered
|
2017-01-22 05:55:30 +01:00
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertNotIn(
|
2020-06-09 00:25:09 +02:00
|
|
|
f'<a href="{url}" title="The Rock">The Rock</a>',
|
2017-01-22 05:55:30 +01:00
|
|
|
msg.rendered_content)
|
|
|
|
|
2017-02-23 06:16:30 +01:00
|
|
|
# Mock the network request result so the test can be fast without Internet
|
2019-05-05 06:41:34 +02:00
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url, relative_url=relative_url))
|
2017-02-23 06:16:30 +01:00
|
|
|
|
|
|
|
# Run the queue processor to potentially rerender things
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
2016-12-13 04:20:33 +01:00
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
2017-01-22 05:55:30 +01:00
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
2017-02-03 23:28:26 +01:00
|
|
|
return msg
|
|
|
|
|
2017-11-06 20:48:55 +01:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_message_update_race_condition(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2017-11-06 20:48:55 +01:00
|
|
|
original_url = 'http://test.org/'
|
|
|
|
edited_url = 'http://edited.org/'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland",
|
2017-11-06 20:48:55 +01:00
|
|
|
topic_name="foo", content=original_url)
|
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def wrapped_queue_json_publish(*args: Any, **kwargs: Any) -> None:
|
2017-11-06 20:48:55 +01:00
|
|
|
# Mock the network request result so the test can be fast without Internet
|
2019-05-05 06:41:34 +02:00
|
|
|
mocked_response_original = mock.Mock(side_effect=self.create_mock_response(original_url))
|
|
|
|
mocked_response_edited = mock.Mock(side_effect=self.create_mock_response(edited_url))
|
|
|
|
|
2017-11-06 20:48:55 +01:00
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response_original):
|
|
|
|
# Run the queue processor. This will simulate the event for original_url being
|
|
|
|
# processed after the message has been edited.
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
# The content of the message has changed since the event for original_url has been created,
|
|
|
|
# it should not be rendered. Another, up-to-date event will have been sent (edited_url).
|
2020-06-09 00:25:09 +02:00
|
|
|
self.assertNotIn(f'<a href="{original_url}" title="The Rock">The Rock</a>',
|
2017-11-06 20:48:55 +01:00
|
|
|
msg.rendered_content)
|
|
|
|
mocked_response_edited.assert_not_called()
|
|
|
|
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response_edited):
|
|
|
|
# Now proceed with the original queue_json_publish and call the
|
|
|
|
# up-to-date event for edited_url.
|
|
|
|
queue_json_publish(*args, **kwargs)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
2020-06-09 00:25:09 +02:00
|
|
|
self.assertIn(f'<a href="{edited_url}" title="The Rock">The Rock</a>',
|
2017-11-06 20:48:55 +01:00
|
|
|
msg.rendered_content)
|
|
|
|
|
2020-06-22 22:57:01 +02:00
|
|
|
with mock.patch('zerver.views.message_edit.queue_json_publish', wraps=wrapped_queue_json_publish) as patched:
|
2017-11-06 20:48:55 +01:00
|
|
|
result = self.client_patch("/json/messages/" + str(msg_id), {
|
|
|
|
'message_id': msg_id, 'content': edited_url,
|
|
|
|
})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_get_link_embed_data(self) -> None:
|
2017-02-03 23:28:26 +01:00
|
|
|
url = 'http://test.org/'
|
2020-06-09 00:25:09 +02:00
|
|
|
embedded_link = f'<a href="{url}" title="The Rock">The Rock</a>'
|
2017-02-03 23:28:26 +01:00
|
|
|
|
|
|
|
# When humans send, we should get embedded content.
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('hamlet'))
|
2017-02-03 23:28:26 +01:00
|
|
|
self.assertIn(embedded_link, msg.rendered_content)
|
|
|
|
|
|
|
|
# We don't want embedded content for bots.
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('webhook_bot'),
|
2017-02-23 06:16:30 +01:00
|
|
|
queue_should_run=False)
|
2017-02-03 23:28:26 +01:00
|
|
|
self.assertNotIn(embedded_link, msg.rendered_content)
|
|
|
|
|
|
|
|
# Try another human to make sure bot failure was due to the
|
|
|
|
# bot sending the message and not some other reason.
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('prospero'))
|
2017-02-03 23:28:26 +01:00
|
|
|
self.assertIn(embedded_link, msg.rendered_content)
|
2016-12-13 04:20:33 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_inline_url_embed_preview(self) -> None:
|
2020-05-09 03:44:56 +02:00
|
|
|
with_preview = '<p><a href="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://ia.media-imdb.com/images/rock.jpg)"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>'
|
|
|
|
without_preview = '<p><a href="http://test.org/">http://test.org/</a></p>'
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('hamlet'))
|
2017-03-13 14:42:03 +01:00
|
|
|
self.assertEqual(msg.rendered_content, with_preview)
|
|
|
|
|
|
|
|
realm = msg.get_realm()
|
|
|
|
setattr(realm, 'inline_url_embed_preview', False)
|
|
|
|
realm.save()
|
|
|
|
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('prospero'), queue_should_run=False)
|
2017-03-13 14:42:03 +01:00
|
|
|
self.assertEqual(msg.rendered_content, without_preview)
|
|
|
|
|
2018-02-23 21:17:29 +01:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_inline_relative_url_embed_preview(self) -> None:
|
|
|
|
# Relative urls should not be sent for url preview.
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
|
|
|
self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('prospero'),
|
|
|
|
self.example_user('cordelia'),
|
2018-02-23 21:17:29 +01:00
|
|
|
content="http://zulip.testserver/api/",
|
|
|
|
)
|
|
|
|
patched.assert_not_called()
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_inline_url_embed_preview_with_relative_image_url(self) -> None:
|
2020-05-09 03:44:56 +02:00
|
|
|
with_preview_relative = '<p><a href="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://test.org/images/rock.jpg)"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>'
|
2017-05-04 01:41:35 +02:00
|
|
|
# Try case where the opengraph image is a relative url.
|
2020-03-07 11:43:05 +01:00
|
|
|
msg = self._send_message_with_test_org_url(sender=self.example_user('prospero'), relative_url=True)
|
2017-05-04 01:41:35 +02:00
|
|
|
self.assertEqual(msg.rendered_content, with_preview_relative)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_http_error_get_data(self) -> None:
|
2016-12-13 04:20:33 +01:00
|
|
|
url = 'http://test.org/'
|
2017-10-28 17:07:36 +02:00
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('hamlet'),
|
|
|
|
self.example_user('cordelia'),
|
2017-10-28 17:07:36 +02:00
|
|
|
content=url,
|
|
|
|
)
|
2017-01-22 05:55:30 +01:00
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
2016-12-13 04:20:33 +01:00
|
|
|
event = {
|
|
|
|
'message_id': msg_id,
|
|
|
|
'urls': [url],
|
2017-01-22 05:55:30 +01:00
|
|
|
'message_realm_id': msg.sender.realm_id,
|
2016-12-13 04:20:33 +01:00
|
|
|
'message_content': url}
|
|
|
|
with self.settings(INLINE_URL_EMBED_PREVIEW=True, TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mock.Mock(side_effect=ConnectionError())):
|
2019-02-05 22:44:40 +01:00
|
|
|
FetchLinksEmbedData().consume(event)
|
2016-12-13 04:20:33 +01:00
|
|
|
msg = Message.objects.get(id=msg_id)
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
'<p><a href="http://test.org/">http://test.org/</a></p>',
|
2016-12-13 04:20:33 +01:00
|
|
|
msg.rendered_content)
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_invalid_link(self) -> None:
|
2016-12-13 04:20:33 +01:00
|
|
|
with self.settings(INLINE_URL_EMBED_PREVIEW=True, TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
self.assertIsNone(get_link_embed_data('com.notvalidlink'))
|
2020-04-09 21:51:58 +02:00
|
|
|
self.assertIsNone(get_link_embed_data('μένει.com.notvalidlink'))
|
2018-03-18 20:58:13 +01:00
|
|
|
|
|
|
|
def test_link_embed_data_from_cache(self) -> None:
|
|
|
|
url = 'http://test.org/'
|
|
|
|
link_embed_data = 'test data'
|
|
|
|
|
|
|
|
with self.assertRaises(NotFoundInCache):
|
|
|
|
link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
with self.settings(CACHES=TEST_CACHES):
|
2018-10-14 14:41:15 +02:00
|
|
|
key = preview_url_cache_key(url)
|
|
|
|
cache_set(key, link_embed_data, 'database')
|
2018-03-18 20:58:13 +01:00
|
|
|
self.assertEqual(link_embed_data, link_embed_data_from_cache(url))
|
2019-05-04 17:54:18 +02:00
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_link_preview_non_html_data(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2019-05-04 17:54:18 +02:00
|
|
|
url = 'http://test.org/audio.mp3'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland", topic_name="foo", content=url)
|
2019-05-04 17:54:18 +02:00
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
|
|
|
headers = {'content-type': 'application/octet-stream'}
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url, headers=headers))
|
|
|
|
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
|
|
|
|
cached_data = link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
self.assertIsNone(cached_data)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
('<p><a href="http://test.org/audio.mp3">'
|
2019-05-04 17:54:18 +02:00
|
|
|
'http://test.org/audio.mp3</a></p>'),
|
|
|
|
msg.rendered_content)
|
|
|
|
|
2019-06-23 13:36:58 +02:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_link_preview_no_open_graph_image(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2019-06-23 13:36:58 +02:00
|
|
|
url = 'http://test.org/foo.html'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland", topic_name="foo", content=url)
|
2019-06-23 13:36:58 +02:00
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
|
|
|
# HTML without the og:image metadata
|
|
|
|
html = '\n'.join(line for line in self.open_graph_html.splitlines() if 'og:image' not in line)
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url, html=html))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
cached_data = link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
self.assertIn('title', cached_data)
|
|
|
|
self.assertNotIn('image', cached_data)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
('<p><a href="http://test.org/foo.html">'
|
2019-06-23 13:36:58 +02:00
|
|
|
'http://test.org/foo.html</a></p>'),
|
|
|
|
msg.rendered_content)
|
|
|
|
|
2019-05-04 17:54:18 +02:00
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
2019-12-12 02:10:50 +01:00
|
|
|
def test_link_preview_open_graph_image_missing_content(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2019-12-12 02:10:50 +01:00
|
|
|
url = 'http://test.org/foo.html'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland", topic_name="foo", content=url)
|
2019-12-12 02:10:50 +01:00
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
|
|
|
# HTML without the og:image metadata
|
|
|
|
html = '\n'.join(line if 'og:image' not in line else '<meta property="og:image"/>'
|
|
|
|
for line in self.open_graph_html.splitlines())
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url, html=html))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
cached_data = link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
self.assertIn('title', cached_data)
|
|
|
|
self.assertNotIn('image', cached_data)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
('<p><a href="http://test.org/foo.html">'
|
2019-12-12 02:10:50 +01:00
|
|
|
'http://test.org/foo.html</a></p>'),
|
|
|
|
msg.rendered_content)
|
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
2019-05-04 17:54:18 +02:00
|
|
|
def test_link_preview_no_content_type_header(self) -> None:
|
2020-03-07 11:43:05 +01:00
|
|
|
user = self.example_user('hamlet')
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2019-05-04 17:54:18 +02:00
|
|
|
url = 'http://test.org/'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
|
2020-03-07 11:43:05 +01:00
|
|
|
msg_id = self.send_stream_message(user, "Scotland", topic_name="foo", content=url)
|
2019-05-04 17:54:18 +02:00
|
|
|
patched.assert_called_once()
|
|
|
|
queue = patched.call_args[0][0]
|
|
|
|
self.assertEqual(queue, "embed_links")
|
|
|
|
event = patched.call_args[0][1]
|
|
|
|
|
|
|
|
headers = {'content-type': ''} # No content type header
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url, headers=headers))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
data = link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
self.assertIn('title', data)
|
|
|
|
self.assertIn('image', data)
|
|
|
|
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
self.assertIn(data['title'], msg.rendered_content)
|
|
|
|
self.assertIn(data['image'], msg.rendered_content)
|
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_valid_content_type_error_get_data(self) -> None:
|
|
|
|
url = 'http://test.org/'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish'):
|
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('hamlet'),
|
|
|
|
self.example_user('cordelia'),
|
2019-05-04 17:54:18 +02:00
|
|
|
content=url,
|
|
|
|
)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
event = {
|
|
|
|
'message_id': msg_id,
|
|
|
|
'urls': [url],
|
|
|
|
'message_realm_id': msg.sender.realm_id,
|
|
|
|
'message_content': url}
|
|
|
|
|
2019-05-07 13:32:44 +02:00
|
|
|
with mock.patch('zerver.lib.url_preview.preview.get_oembed_data', side_effect=lambda *args, **kwargs: None):
|
|
|
|
with mock.patch('zerver.lib.url_preview.preview.valid_content_type', side_effect=lambda k: True):
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mock.Mock(side_effect=ConnectionError())):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
2019-05-04 17:54:18 +02:00
|
|
|
|
2019-05-10 14:29:33 +02:00
|
|
|
with self.assertRaises(NotFoundInCache):
|
|
|
|
link_embed_data_from_cache(url)
|
|
|
|
|
2019-05-04 17:54:18 +02:00
|
|
|
msg.refresh_from_db()
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
'<p><a href="http://test.org/">http://test.org/</a></p>',
|
2019-05-04 17:54:18 +02:00
|
|
|
msg.rendered_content)
|
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_invalid_url(self) -> None:
|
|
|
|
url = 'http://test.org/'
|
|
|
|
error_url = 'http://test.org/x'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish'):
|
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('hamlet'),
|
|
|
|
self.example_user('cordelia'),
|
2019-05-04 17:54:18 +02:00
|
|
|
content=error_url,
|
|
|
|
)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
event = {
|
|
|
|
'message_id': msg_id,
|
|
|
|
'urls': [error_url],
|
|
|
|
'message_realm_id': msg.sender.realm_id,
|
|
|
|
'message_content': error_url}
|
|
|
|
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
cached_data = link_embed_data_from_cache(error_url)
|
|
|
|
|
|
|
|
# FIXME: Should we really cache this, especially without cache invalidation?
|
|
|
|
self.assertIsNone(cached_data)
|
|
|
|
msg.refresh_from_db()
|
|
|
|
self.assertEqual(
|
2020-05-09 03:44:56 +02:00
|
|
|
'<p><a href="http://test.org/x">http://test.org/x</a></p>',
|
2019-05-04 17:54:18 +02:00
|
|
|
msg.rendered_content)
|
2019-05-02 18:58:39 +02:00
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_safe_oembed_html_url(self) -> None:
|
|
|
|
url = 'http://test.org/'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish'):
|
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('hamlet'),
|
|
|
|
self.example_user('cordelia'),
|
2019-05-02 18:58:39 +02:00
|
|
|
content=url,
|
|
|
|
)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
event = {
|
|
|
|
'message_id': msg_id,
|
|
|
|
'urls': [url],
|
|
|
|
'message_realm_id': msg.sender.realm_id,
|
|
|
|
'message_content': url}
|
|
|
|
|
2020-06-09 00:25:09 +02:00
|
|
|
mocked_data = {'html': f'<iframe src="{url}"></iframe>',
|
|
|
|
'oembed': True, 'type': 'video', 'image': f'{url}/image.png'}
|
2019-05-02 18:58:39 +02:00
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
|
|
|
with mock.patch('zerver.lib.url_preview.preview.get_oembed_data',
|
|
|
|
lambda *args, **kwargs: mocked_data):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
data = link_embed_data_from_cache(url)
|
|
|
|
|
|
|
|
self.assertEqual(data, mocked_data)
|
|
|
|
msg.refresh_from_db()
|
|
|
|
self.assertIn('a data-id="{}"'.format(escape(mocked_data['html'])), msg.rendered_content)
|
2019-03-21 21:08:26 +01:00
|
|
|
|
|
|
|
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
|
|
|
|
def test_youtube_url_title_replaces_url(self) -> None:
|
|
|
|
url = 'https://www.youtube.com/watch?v=eSJTXC7Ixgg'
|
|
|
|
with mock.patch('zerver.lib.actions.queue_json_publish'):
|
|
|
|
msg_id = self.send_personal_message(
|
2020-03-07 11:43:05 +01:00
|
|
|
self.example_user('hamlet'),
|
|
|
|
self.example_user('cordelia'),
|
2019-03-21 21:08:26 +01:00
|
|
|
content=url,
|
|
|
|
)
|
|
|
|
msg = Message.objects.select_related("sender").get(id=msg_id)
|
|
|
|
event = {
|
|
|
|
'message_id': msg_id,
|
|
|
|
'urls': [url],
|
|
|
|
'message_realm_id': msg.sender.realm_id,
|
|
|
|
'message_content': url}
|
|
|
|
|
|
|
|
mocked_data = {'title': 'Clearer Code at Scale - Static Types at Zulip and Dropbox'}
|
|
|
|
mocked_response = mock.Mock(side_effect=self.create_mock_response(url))
|
|
|
|
with self.settings(TEST_SUITE=False, CACHES=TEST_CACHES):
|
|
|
|
with mock.patch('requests.get', mocked_response):
|
2020-06-25 15:00:33 +02:00
|
|
|
with mock.patch('zerver.lib.markdown.link_preview.link_embed_data_from_cache',
|
2019-03-21 21:08:26 +01:00
|
|
|
lambda *args, **kwargs: mocked_data):
|
|
|
|
FetchLinksEmbedData().consume(event)
|
|
|
|
|
|
|
|
msg.refresh_from_db()
|
2020-05-09 03:44:56 +02:00
|
|
|
expected_content = '<p><a href="https://www.youtube.com/watch?v=eSJTXC7Ixgg">YouTube - Clearer Code at Scale - Static Types at Zulip and Dropbox</a></p>\n<div class="youtube-video message_inline_image"><a data-id="eSJTXC7Ixgg" href="https://www.youtube.com/watch?v=eSJTXC7Ixgg"><img src="https://i.ytimg.com/vi/eSJTXC7Ixgg/default.jpg"></a></div>'
|
2019-03-21 21:08:26 +01:00
|
|
|
self.assertEqual(expected_content, msg.rendered_content)
|