예제 #1
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)
예제 #2
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)