Ejemplo n.º 1
0
    def test_compatible_context(self):
        """
        Tests that the get_context_data method supplies a backwards-compatible
        "data" context variable in addition to adding the form and video to the
        context.

        """
        view = SubmitVideoView(form_class=forms.SubmitVideoFormBase)
        view.request = self.factory.get('/')
        view.request.session[view.get_session_key()] = {
            'url': '',
            'video': VidscraperVideo('')
        }
        view.object = self.create_video()
        view.url = (view.object.website_url or view.object.file_url)
        view.video = VidscraperVideo(view.url)
        form = view.get_form(view.get_form_class())

        context_data = view.get_context_data(form=form)
        self.assertEqual(context_data.get('video'), view.object)
        self.assertIsInstance(context_data.get('form'), view.form_class)
        self.assertTrue('data' in context_data)
        self.assertEqual(
            set(context_data['data']),
            set([
                'link', 'publish_date', 'tags', 'title', 'description',
                'thumbnail_url', 'user', 'user_url'
            ]))
Ejemplo n.º 2
0
    def test_form_valid(self):
        """
        If the submitted form is valid, a :class:`ContestVideo` should be
        created for the newly submitted :class:`Video`.
        """
        self.view.request = self.factory.get('/')
        self.view.object = Video()
        self.view.url = u'http://google.com/'
        self.view.video = VidscraperVideo(self.view.url)
        self.view.video.name = 'Test Video'
        self.view.video.embed_code = 'Test Code'
        self.view.request.session[self.view.get_session_key()] = {
            'url': self.view.url,
            'video': self.view.video
        }

        form = self.view.get_form_class()(data={
            'url':
            self.view.url,
            'name':
            self.view.video.name,
            'embed_code':
            self.view.video.embed_code
        },
                                          **self.view.get_form_kwargs())
        self.assertTrue(form.is_valid(), form.errors.items())
        self.assertTrue(self.view.form_valid(form))
        cv = ContestVideo.objects.get()
        self.assertEqual(cv.video, self.view.object)
        self.assertEqual(cv.contest, self.contest)
Ejemplo n.º 3
0
    def test_form_valid__embedrequest(self):
        """
        Checks that, if the form represents an embedrequest video - i.e. a video
        that vidscraper can't scrape and which doesn't look like a direct link -
        the success_url is set to the url of the embedrequest view, and that the
        session data contains the scraped video (or ``None``) as 'video' and the
        video's url as 'url'.

        """
        embed_url = reverse('localtv_submit_embedrequest_video')
        view = SubmitURLView(embed_url=embed_url)
        video_url = 'http://google.com'
        url = "%s?url=%s" % (reverse('localtv_submit_video'), video_url)
        view.request = self.factory.get(url)
        expected_success_url = "%s?%s" % (embed_url,
                                          view.request.GET.urlencode())
        form = view.get_form(view.get_form_class())

        # Option 1: no video
        form.video_cache = None
        form.cleaned_data = {'url': video_url}

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': None,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)

        # Option two: video missing embed & file_url
        video = VidscraperVideo(video_url)
        form.video_cache = video
        form.cleaned_data = {'url': video_url}

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': video,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)

        # Option three: video with expiring file_url.
        video.file_url = 'hola'
        video.file_url_expires = datetime.datetime.now() + datetime.timedelta(
            1)

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': video,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)
Ejemplo n.º 4
0
    def test_requires_session_data(self):
        # This differs from the functional testing in that it tests the view
        # directly. The inputs given can only result in a 302 response or a 200
        # response, depending on whether there is correct session data or not.
        view = SubmitVideoView(form_class=forms.SubmitVideoFormBase,
                               submit_video_url='http://google.com/')
        request = self.factory.get('/')
        response = view.dispatch(request)
        self.assertEqual(response.status_code, 302)

        request.session[view.get_session_key()] = {
            'url': 'http://google.com',
            'video': VidscraperVideo('http://google.com/')
        }
        response = view.dispatch(request)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 5
0
    def test_get_initial_tags(self):
        """
        Tests that tags are in the initial data only if tags are defined on the
        video, and that the tags in the expected format - at the moment, this
        is the return value of get_or_create_tags(tags).

        """
        view = SubmitVideoView()
        view.video = VidscraperVideo('http://google.com')
        initial = view.get_initial()
        self.assertFalse('tags' in initial)

        tags = ['hello', 'goodbye']
        view.video.tags = tags
        initial = view.get_initial()
        self.assertTrue('tags' in initial)
        # This is perhaps not the best way to test this.
        self.assertEqual(initial['tags'], get_or_create_tags(tags))
Ejemplo n.º 6
0
    def test_form_valid(self):
        """
        Tests that when the form_valid method is run, the session information
        is cleared, and the submit_finished signal is sent.

        """
        view = SubmitVideoView(form_class=forms.SubmitVideoFormBase,
                               form_fields=(
                                   'tags',
                                   'contact',
                                   'notes',
                               ),
                               thanks_url_name='localtv_submit_thanks')
        view.request = self.factory.get('/')
        view.object = Video()
        view.url = u'http://google.com/'
        view.video = VidscraperVideo(view.url)
        view.video.embed_code = 'Test Code'
        view.request.session[view.get_session_key()] = {
            'url': view.url,
            'video': view.video
        }

        submit_dict = {'hit': False}

        def test_submit_finished(sender, **kwargs):
            submit_dict['hit'] = True

        submit_finished.connect(test_submit_finished)
        form = view.get_form_class()(data={
            'url': view.url,
            'name': 'Test Video',
            'embed_code': 'Test Code',
            'contact': '*****@*****.**'
        },
                                     **view.get_form_kwargs())
        self.assertTrue(form.is_valid(), form.errors.items())
        self.assertTrue(view.form_valid(form))

        self.assertEqual(submit_dict['hit'], True)
        self.assertFalse(view.get_session_key() in view.request.session)
        submit_finished.disconnect(test_submit_finished)
Ejemplo n.º 7
0
    def test_form_valid__directlink(self):
        """
        Checks that, if the form represents a direct link to a video file, the
        success_url is the url of the direct_link view, and that the session
        data contains the video (or ``None``) as 'video' and the video's url
        as 'url'.

        NOTE:: Direct link videos will probably not actually result in the
        creation of VidscraperVideo instances; this is tested only to maintain
        the exact behavior which previously existed.

        """
        direct_url = reverse('localtv_submit_directlink_video')
        view = SubmitURLView(direct_url=direct_url)
        video_url = "http://google.com/file.mov"
        url = "%s?url=%s" % (reverse('localtv_submit_video'), video_url)
        view.request = self.factory.get(url)
        expected_success_url = "%s?%s" % (direct_url,
                                          view.request.GET.urlencode())
        form = view.get_form(view.get_form_class())

        # Option one: No video, but a video file url.
        form.video_cache = None
        form.cleaned_data = {'url': video_url}

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': None,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)

        # Option two: A video missing embed_code and file_url data, but a video
        # file url.
        video = VidscraperVideo(video_url)
        form.video_cache = video
        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': video,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)
Ejemplo n.º 8
0
    def test_get_object(self):
        """
        Tests that the view's get_object method returns a Video instance,
        populated with data from a vidscraper video if available.

        """
        view = SubmitVideoView()
        view.video = None
        obj = view.get_object()
        self.assertIsInstance(obj, Video)
        self.assertEqual(obj.name, '')
        self.assertEqual(obj.embed_code, '')

        view.video = VidscraperVideo('')
        view.video.title = 'Title'
        view.video.embed_code = 'embed_code'
        obj = view.get_object()
        self.assertIsInstance(view.get_object(), Video)
        self.assertEqual(obj.name, 'Title')
        self.assertEqual(obj.embed_code, 'embed_code')
Ejemplo n.º 9
0
 def setUp(self):
     self.url = reverse('localtv_submit_scraped_video')
     self.template_name = 'localtv/submit_video/scraped.html'
     self.session_url = ('http://blip.tv/searching-for-mike/'
                         'fixing-otter-267')
     self.session_video = VidscraperVideo(self.session_url)
     self.session_video.title = 'Fixing Otter'
     self.session_video.embed_code = 'hi'
     self.session_video.description = (u"<p>In my first produced vlog, I "
                                       u"talk a bit about breaking blip.tv,"
                                       u" and fixing it. The audio's "
                                       u"pretty bad, sorry about that.</p>")
     self.session_video.thumbnail_url = (
         'http://a.images.blip.tv/11156136631.95334664852457-424.jpg')
     self.POST_data = {
         'tags': 'tag1, tag2',
         'contact': 'Foo <*****@*****.**>',
         'notes': "here's a note!"
     }
     SubmitVideoViewFunctionalTestCase.setUp(self)
Ejemplo n.º 10
0
    def test_form_valid__scraped(self):
        """
        Checks that, if the form represents a scraped video, the success_url is
        the url of the scraped_video view, and that the session data contains
        the scraped video as 'video' and the video's url as 'url'.

        """
        scraped_url = reverse('localtv_submit_scraped_video')
        view = SubmitURLView(scraped_url=scraped_url)
        video_url = "http://google.com"
        url = "%s?url=%s" % (reverse('localtv_submit_video'), video_url)
        view.request = self.factory.get(url)
        expected_success_url = "%s?%s" % (scraped_url,
                                          view.request.GET.urlencode())
        form = view.get_form(view.get_form_class())

        # Option one: Video with embed code
        video = VidscraperVideo(video_url)
        video.embed_code = "blink"
        form.video_cache = video
        form.cleaned_data = {'url': video_url}

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': video,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)

        # Option two: Video with non-expiring file_url.
        video.embed_code = None
        video.file_url = "blink"

        view.form_valid(form)
        self.assertEqual(view.request.session[view.get_session_key()], {
            'video': video,
            'url': video_url
        })
        self.assertEqual(view.success_url, expected_success_url)