Пример #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_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)
Пример #4
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)