Ejemplo n.º 1
0
    def test_download_thumbnail(self, requests, vimeo):
        video = Video2013Factory.build()
        video.thumbnail = Mock()
        video.save = Mock()

        vimeo.get_thumbnail_urls.return_value = [
            {
                'height': '250',
                '_content': 'http://example.com/qwer.png'
            },
            {
                'height': '150',
                '_content': 'http://example.com/asdf.png'
            },
            {
                'height': '80',
                '_content': 'http://example.com/zxcv.png'
            },
        ]
        requests.get.return_value = Mock(content='asdf',
                                         url='http://example.com/asdf.png')

        video.download_thumbnail()
        requests.get.assert_called_with('http://example.com/asdf.png')
        video.thumbnail.save.assert_called_with('asdf.png', ANY, save=False)
        video.save.assert_called_with()
Ejemplo n.º 2
0
    def test_download_thumbnail_error(self, vimeo):
        """If no medium-sized thumbnail is found, raise a VimeoServiceError."""
        video = Video2013Factory.build()
        vimeo.get_thumbnail_urls.return_value = [
            {'height': '250', '_content': 'http://example.com/qwer.png'},
            {'height': '80', '_content': 'http://example.com/zxcv.png'},
        ]
        vimeo.VimeoServiceError = VimeoServiceError

        with self.assertRaises(VimeoServiceError):
            video.download_thumbnail()
Ejemplo n.º 3
0
    def test_save_process_new(self, send_approval_email):
        """
        Do not call process_approval or send_approval_email if the video is new.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.build(title='blahtest', user=user)
        video.process_approval = Mock()
        video.save()

        ok_(not video.process_approval.called)
        ok_(not send_approval_email.called)
Ejemplo n.º 4
0
    def test_process_approval_unapproved(self, vimeo):
        """
        If the video is not approved, reset the privacy on vimeo to 'password'.
        """
        video = Video2013Factory.build(approved=False)
        video.download_thumbnail = Mock()

        with self.settings(VIMEO_VIDEO_PASSWORD='******'):
            video.process_approval()
        vimeo.set_privacy.assert_called_with(video.vimeo_id, 'password',
                                             password='******')
Ejemplo n.º 5
0
    def test_process_approval(self, vimeo):
        """
        If the video is approved, download the thumbnails and reset the privacy
        on vimeo to 'anybody'.
        """
        video = Video2013Factory.build(approved=True, user_notified=False)
        video.download_thumbnail = Mock()
        video.process_approval()

        video.download_thumbnail.assert_called_with(commit=False)
        vimeo.set_privacy.assert_called_with(video.vimeo_id, 'anybody')
Ejemplo n.º 6
0
    def test_save_process_new(self, send_approval_email):
        """
        Do not call process_approval or send_approval_email if the video is new.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.build(title='blahtest', user=user)
        video.process_approval = Mock()
        video.save()

        ok_(not video.process_approval.called)
        ok_(not send_approval_email.called)
Ejemplo n.º 7
0
    def test_process_approval(self, vimeo):
        """
        If the video is approved, download the thumbnails and reset the privacy
        on vimeo to 'anybody'.
        """
        video = Video2013Factory.build(approved=True, user_notified=False)
        video.download_thumbnail = Mock()
        video.process_approval()

        video.download_thumbnail.assert_called_with(commit=False)
        vimeo.set_privacy.assert_called_with(video.vimeo_id, 'anybody')
Ejemplo n.º 8
0
    def test_process_approval_thumbnail_fail(self, vimeo):
        """
        If a video is approved but downloading thumbnails has failed, continue
        processing the video approval.
        """
        video = Video2013Factory.build(approved=True, user_notified=False)
        video.download_thumbnail = Mock()
        video.download_thumbnail.side_effect = RequestException
        video.process_approval()

        video.download_thumbnail.assert_called_with(commit=False)
        vimeo.set_privacy.assert_called_with(video.vimeo_id, 'anybody')
Ejemplo n.º 9
0
    def test_process_approval_thumbnail_fail(self, vimeo):
        """
        If a video is approved but downloading thumbnails has failed, continue
        processing the video approval.
        """
        video = Video2013Factory.build(approved=True, user_notified=False)
        video.download_thumbnail = Mock()
        video.download_thumbnail.side_effect = RequestException
        video.process_approval()

        video.download_thumbnail.assert_called_with(commit=False)
        vimeo.set_privacy.assert_called_with(video.vimeo_id, 'anybody')
Ejemplo n.º 10
0
    def test_process_approval_unapproved(self, vimeo):
        """
        If the video is not approved, reset the privacy on vimeo to 'password'.
        """
        video = Video2013Factory.build(approved=False)
        video.download_thumbnail = Mock()

        with self.settings(VIMEO_VIDEO_PASSWORD='******'):
            video.process_approval()
        vimeo.set_privacy.assert_called_with(video.vimeo_id,
                                             'password',
                                             password='******')
Ejemplo n.º 11
0
    def test_commit(self, requests, vimeo):
        """If commit is False, do not save the video."""
        video = Video2013Factory.build()
        video.save = Mock()

        vimeo.get_thumbnail_urls.return_value = [
            {'height': '250', '_content': 'http://example.com/qwer.png'},
            {'height': '150', '_content': 'http://example.com/asdf.png'},
            {'height': '80', '_content': 'http://example.com/zxcv.png'},
        ]
        requests.get.return_value = Mock(content='asdf',
                                         url='http://example.com/asdf.png')

        video.download_thumbnail(commit=False)
        ok_(not video.save.called)
Ejemplo n.º 12
0
    def test_download_thumbnail(self, requests, vimeo):
        video = Video2013Factory.build()
        video.thumbnail = Mock()
        video.save = Mock()

        vimeo.get_thumbnail_urls.return_value = [
            {'height': '250', '_content': 'http://example.com/qwer.png'},
            {'height': '150', '_content': 'http://example.com/asdf.png'},
            {'height': '80', '_content': 'http://example.com/zxcv.png'},
        ]
        requests.get.return_value = Mock(content='asdf',
                                         url='http://example.com/asdf.png')

        video.download_thumbnail()
        requests.get.assert_called_with('http://example.com/asdf.png')
        video.thumbnail.save.assert_called_with('asdf.png', ANY, save=False)
        video.save.assert_called_with()
Ejemplo n.º 13
0
    def test_download_thumbnail_error(self, vimeo):
        """If no medium-sized thumbnail is found, raise a VimeoServiceError."""
        video = Video2013Factory.build()
        vimeo.get_thumbnail_urls.return_value = [
            {
                'height': '250',
                '_content': 'http://example.com/qwer.png'
            },
            {
                'height': '80',
                '_content': 'http://example.com/zxcv.png'
            },
        ]
        vimeo.VimeoServiceError = VimeoServiceError

        with self.assertRaises(VimeoServiceError):
            video.download_thumbnail()
Ejemplo n.º 14
0
    def test_commit(self, requests, vimeo):
        """If commit is False, do not save the video."""
        video = Video2013Factory.build()
        video.save = Mock()

        vimeo.get_thumbnail_urls.return_value = [
            {
                'height': '250',
                '_content': 'http://example.com/qwer.png'
            },
            {
                'height': '150',
                '_content': 'http://example.com/asdf.png'
            },
            {
                'height': '80',
                '_content': 'http://example.com/zxcv.png'
            },
        ]
        requests.get.return_value = Mock(content='asdf',
                                         url='http://example.com/asdf.png')

        video.download_thumbnail(commit=False)
        ok_(not video.save.called)