def test_GET_submission(self):
        """
        Form data should be captured from the GET parameters.

        """
        view = SubmitURLView()
        url = "%s?%s" % (reverse('localtv_submit_video'),
                         "url=http://google.com")
        view.request = self.factory.get(url)
        form = view.get_form(view.get_form_class())
        self.assertEqual(form.data, view.request.GET)
    def test_GET_submission(self):
        """
        Form data should be captured from the GET parameters.

        """
        view = SubmitURLView()
        url = "%s?%s" % (reverse('localtv_submit_video'),
                         "url=http://google.com")
        view.request = self.factory.get(url)
        form = view.get_form(view.get_form_class())
        self.assertEqual(form.data, view.request.GET)
    def test_form_valid__scraped__embed(self):
        """
        Checks that, if the form represents a scraped video with embed code,
        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())

        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)
    def test_form_valid__scraped__embed(self):
        """
        Checks that, if the form represents a scraped video with embed code,
        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())

        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)
    def test_get_context_data(self):
        """
        Makes sure that ``was_duplicate`` and ``video`` are context variables
        taken from attributes on the form instance. The setting of those
        attributes is tested in the form unit tests.

        """
        video = self.create_video()
        url = video.website_url or video.file_url or video.guid
        view = SubmitURLView()
        form = view.form_class(data={'url': url})

        form.was_duplicate = True
        form.duplicate_video = video
        context = view.get_context_data(form=form)
        self.assertTrue('was_duplicate' in context)
        self.assertTrue('video' in context)
        self.assertEqual(context['was_duplicate'], True)
        self.assertEqual(context['video'], video)
    def test_get_context_data(self):
        """
        Makes sure that ``was_duplicate`` and ``video`` are context variables
        taken from attributes on the form instance. The setting of those
        attributes is tested in the form unit tests.

        """
        video = self.create_video()
        url = video.website_url or video.file_url or video.guid
        view = SubmitURLView()
        form = view.form_class(data={'url': url})

        form.was_duplicate = True
        form.duplicate_video = video
        context = view.get_context_data(form=form)
        self.assertTrue('was_duplicate' in context)
        self.assertTrue('video' in context)
        self.assertEqual(context['was_duplicate'], True)
        self.assertEqual(context['video'], video)
    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)
    def test_form_valid__vidscraper_urlerror(self):
        """
        If ``vidscraper.auto_scrape()`` raises a URLError, we should not have a
        video_cache and the user should be redirected to the embedrequest page.
        """
        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())

        self.assertTrue(form.is_valid())

        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)
    def test_form_valid__vidscraper_urlerror(self):
        """
        If ``vidscraper.auto_scrape()`` raises a URLError, we should not have a
        video_cache and the user should be redirected to the embedrequest page.
        """
        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())

        self.assertTrue(form.is_valid())

        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)
Example #10
0
from django.conf.urls.defaults import patterns, url
from django.core.urlresolvers import reverse_lazy

from localtv.submit_video.forms import (ScrapedSubmitVideoForm,
                                        EmbedSubmitVideoForm,
                                        DirectLinkSubmitVideoForm)
from localtv.submit_video.views import (can_submit_video, SubmitURLView,
                                        SubmitVideoView, submit_thanks)

urlpatterns = patterns(
    '',
    url(r'^$',
        can_submit_video(
            SubmitURLView.as_view(
                scraped_url=reverse_lazy('localtv_submit_scraped_video'),
                direct_url=reverse_lazy('localtv_submit_directlink_video'),
                embed_url=reverse_lazy('localtv_submit_embedrequest_video'),
            )),
        name='localtv_submit_video'),
    url(r'^scraped/$',
        can_submit_video(
            SubmitVideoView.as_view(
                submit_video_url=reverse_lazy('localtv_submit_video'),
                thanks_url_name='localtv_submit_thanks',
                form_class=ScrapedSubmitVideoForm,
                template_name='localtv/submit_video/scraped.html',
                form_fields=('tags', 'contact', 'notes'),
            )),
        name='localtv_submit_scraped_video'),
    url(r'^embed/$',
        can_submit_video(
    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)
    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)
Example #13
0
from django.conf.urls.defaults import patterns, url
from django.core.urlresolvers import reverse_lazy

from localtv.submit_video.forms import (ScrapedSubmitVideoForm,
                                        EmbedSubmitVideoForm,
                                        DirectLinkSubmitVideoForm)
from localtv.submit_video.views import (can_submit_video,
                                        SubmitURLView,
                                        SubmitVideoView,
                                        submit_thanks)

urlpatterns = patterns('',
    url(r'^$',
        can_submit_video(SubmitURLView.as_view(
            scraped_url=reverse_lazy('localtv_submit_scraped_video'),
            direct_url=reverse_lazy('localtv_submit_directlink_video'),
            embed_url=reverse_lazy('localtv_submit_embedrequest_video'),
        )),
    	name='localtv_submit_video'),
    url(r'^scraped/$',
        can_submit_video(SubmitVideoView.as_view(
            submit_video_url=reverse_lazy('localtv_submit_video'),
            thanks_url_name='localtv_submit_thanks',
            form_class=ScrapedSubmitVideoForm,
            template_name='localtv/submit_video/scraped.html',
            form_fields=('tags', 'contact', 'notes'),
        )),
        name='localtv_submit_scraped_video'),
    url(r'^embed/$',
        can_submit_video(SubmitVideoView.as_view(
            submit_video_url=reverse_lazy('localtv_submit_video'),
    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)