Beispiel #1
0
    def test_make_oembed_url(self):
        v_urls = [
            'https://vimeo.com/7100569',
            'https://www.youtube.com/watch?v=bDOYN-6gdRE'
        ]
        o_encoded = [
            'https://vimeo.com/api/oembed.json?url=https%3A%2F%2Fvimeo.com%2F7100569&maxwidth=550',
            'https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbDOYN-6gdRE&maxwidth=550&format=json'
        ]

        oembed_url = Sourcefile.make_oembed_url(v_urls[0])
        self.assertEqual(oembed_url, o_encoded[0])
        oembed_url = Sourcefile.make_oembed_url(v_urls[1])
        self.assertEqual(oembed_url, o_encoded[1])
Beispiel #2
0
    def get(self):
        url = self.get_argument('url', None)
        shake_id = self.get_argument('shake_id', "")
        if not url:
            self.render("tools/save-video.html", url=url, shake_id=shake_id)
            return

        url = Sourcefile.make_oembed_url(url.strip())
        if url:
            self.handle_oembed_url(url)
        else:
            self.render("tools/save-video-error.html",
                        message="Invalid URL. We didn't recognize that URL")
Beispiel #3
0
 def post(self):
     url = self.get_argument('url', None)
     if not url:
         self.render("tools/save-video.html",
                     url=url,
                     title=None,
                     description=None)
     url = Sourcefile.make_oembed_url(url.strip())
     if url:
         current_user = self.get_current_user_object()
         shake_id = self.get_argument('shake_id', None)
         if not shake_id:
             self.destination_shake = Shake.get('user_id=%s and type=%s',
                                                current_user.id, 'user')
         else:
             self.destination_shake = Shake.get('id=%s', shake_id)
             if not self.destination_shake:
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "We couldn't save the video to specified shake. Please contact support."
                 )
             if not self.destination_shake.can_update(current_user.id):
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "We couldn't save the video to specified shake. Please contact support."
                 )
             if current_user.email_confirmed != 1:
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "You must confirm your email address before you can post."
                 )
         self.handle_oembed_url(url)
     else:
         self.render(
             "tools/save-video-error.html",
             message=
             "We could not load the embed code. The video server may be down. Please contact support."
         )
Beispiel #4
0
 def test_fail_to_make_oembed_url(self):
     bad_urls = [
         'http://cnn.com/7100569', 'http://www.waxy.org/watch?v=bDOYN-6gdRE'
     ]
     for url in bad_urls:
         self.assertEqual(Sourcefile.make_oembed_url(url), None)