コード例 #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'
            ]))
    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)
    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']))
    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)
コード例 #5
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)
コード例 #6
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))
    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))
コード例 #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')
    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')
コード例 #10
0
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'),
                thanks_url_name='localtv_submit_thanks',
                form_class=EmbedSubmitVideoForm,
                template_name='localtv/submit_video/embed.html',
                form_fields=('tags', 'contact', 'notes', 'name', 'description',
                             'thumbnail_url', 'embed_code'),
            )),
        name='localtv_submit_embedrequest_video'),
コード例 #11
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)
コード例 #12
0
ファイル: urls.py プロジェクト: bluezone/mirocommunity
                                        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'),
            thanks_url_name='localtv_submit_thanks',
            form_class=EmbedSubmitVideoForm,
            template_name='localtv/submit_video/embed.html',
            form_fields=('tags', 'contact', 'notes', 'name', 'description',
                         'thumbnail_url', 'embed_code'),
        )),
        name='localtv_submit_embedrequest_video'),
    url(r'^directlink/$',