Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for processing slide url in video #190

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions hgtv/views/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from urlparse import urlparse, parse_qs
from socket import gaierror
import requests
import urllib2
import bleach
from werkzeug import secure_filename

from flask import abort, redirect, request, jsonify, g, json, url_for, make_response
from flask import abort, redirect, request, jsonify, json, url_for
from coaster.auth import current_auth
from coaster.views import load_models, render_with
from coaster.gfm import markdown
Expand Down Expand Up @@ -155,9 +154,8 @@ def process_slides(video):
raise DataProcessingError("Unable to resolve the URL")
elif parsed.netloc in ['speakerdeck.com', 'www.speakerdeck.com']:
try:
r = urllib2.urlopen('https://speakerdeck.com/oembed.json?url=%s' % video.slides_url)
jsondata = json.loads(r.read())
r.close()
r = requests.get('https://speakerdeck.com/oembed.json?url=%s' % video.slides_url)
jsondata = r.json()
if jsondata:
video.slides_source = u'speakerdeck'
pattern = u'\Wsrc="//speakerdeck.com/player/([^\s^"]+)' # pattern to extract slideid from speakerdeck
Expand Down
10 changes: 9 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ def setUp(self):
db.session.add(playlist1)

video1 = Video(playlist=playlist1, name=u"test-video-1", title=u"Test Video 1",
video_url=u"https://www.youtube.com/watch?v=testvideo1")
video_url=u"https://www.youtube.com/watch?v=testvideo1",
slides_url=u"https://speakerdeck.com/jackerhack/understanding-open-source")
playlist1.videos.append(video1)

video2 = Video(playlist=playlist1, name=u"test-video-2", title=u"Test Video 2",
video_url=u"https://www.youtube.com/watch?v=testvideo2",
slides_url=u"https://www.slideshare.net/kwhinnery/write-better-javascript")
playlist1.videos.append(video2)

db.session.add(video1)
db.session.add(video2)

# Commit objects
db.session.commit()
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from hgtv.models import Video
from hgtv.views.video import process_slides
from ..fixtures import TestCaseBase


class VideoUnitTest(TestCaseBase):
def test_new_video(self):
test_video1 = Video.query.filter_by(name=u"test-video-1").first()
self.assertEqual(test_video1.title, u"Test Video 1")

def test_slides_process_speakerdeck(self):
test_video1 = Video.query.filter_by(name=u"test-video-1").first()
self.assertEqual(test_video1.slides_source, u'')
self.assertEqual(test_video1.slides_sourceid, u'')
process_slides(test_video1)
self.assertEqual(test_video1.slides_source, u'speakerdeck')
self.assertNotEqual(test_video1.slides_sourceid, u'')

def test_slides_process_slideshare(self):
test_video2 = Video.query.filter_by(name=u"test-video-2").first()
self.assertEqual(test_video2.slides_source, u'')
self.assertEqual(test_video2.slides_sourceid, u'')
process_slides(test_video2)
self.assertEqual(test_video2.slides_source, u'slideshare')
self.assertNotEqual(test_video2.slides_sourceid, u'')