allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 01/01: Handle [[embed]] errors specifically, instead of whole markdown text erroring
Date Thu, 03 Dec 2020 20:56:32 GMT
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/embed_error_handling
in repository https://gitbox.apache.org/repos/asf/allura.git

commit d42a93a1f9c2d8e35e9efe74dd1fae2d47078653
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
AuthorDate: Thu Dec 3 15:52:29 2020 -0500

    Handle [[embed]] errors specifically, instead of whole markdown text erroring
---
 Allura/allura/lib/macro.py          |  3 +++
 Allura/allura/tests/test_globals.py | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index a7197de..3e58278 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -466,6 +466,9 @@ def embed(url=None):
             html = consumer.embed(url)['html']
         except oembed.OEmbedNoEndpoint:
             html = None
+        except oembed.OEmbedError:
+            log.exception('Could not embed: {}'.format(url))
+            return 'Could not embed: {}'.format(url)
         except six.moves.urllib.error.HTTPError as e:
             if e.code == 404:
                 return 'Video not available'
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 7d624ce..a811247 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -25,13 +25,13 @@ import os
 import allura
 import unittest
 import hashlib
-import datetime as dt
 from mock import patch, Mock
 
 from bson import ObjectId
 from nose.tools import with_setup, assert_equal, assert_in, assert_not_in
 from tg import tmpl_context as c, app_globals as g
 import tg
+from oembed import OEmbedError
 
 from ming.orm import ThreadLocalORMSession
 from alluratest.controller import (
@@ -353,6 +353,14 @@ def test_macro_embed_video_gone():
     assert_equal(r, '<div class="markdown_content"><p>Video not available</p></div>')
 
 
+@patch('oembed.OEmbedEndpoint.fetch')
+def test_macro_embed_video_error(oembed_fetch):
+    oembed_fetch.side_effect = OEmbedError('Invalid mime-type in response...')
+    r = g.markdown_wiki.convert('[[embed url=http://www.youtube.com/watch?v=6YbBmqUnoQM]]')
+    assert_equal(r, '<div class="markdown_content"><p>Could not embed: '
+                    'http://www.youtube.com/watch?v=6YbBmqUnoQM</p></div>')
+
+
 def test_macro_embed_notsupported():
     r = g.markdown_wiki.convert('[[embed url=http://vimeo.com/46163090]]')
     assert_equal(


Mime
View raw message