Пример #1
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)
Пример #2
0
    def create_video(self,
                     name='Test.',
                     status=Video.ACTIVE,
                     site_id=1,
                     watches=0,
                     categories=None,
                     authors=None,
                     tags=None,
                     update_index=True,
                     **kwargs):
        """
        Factory method for creating videos. Supplies the following defaults:

        * name: 'Test'
        * status: :attr:`Video.ACTIVE`
        * site_id: 1

        In addition to kwargs for the video's fields, which are passed directly
        to :meth:`Video.objects.create`, takes a ``watches`` kwarg (defaults to
        0). If ``watches`` is greater than 0, that many :class:`.Watch`
        instances will be created, each successively one day further in the
        past.

        List of category and author instances may also be passed in as
        ``categories`` and ``authors``, respectively.

        """
        video = Video(name=name, status=status, site_id=site_id, **kwargs)
        video.save(update_index=update_index)

        for i in xrange(watches):
            self.create_watch(video, days=i)

        if categories is not None:
            video.categories.add(*categories)

        if authors is not None:
            video.authors.add(*authors)

        if tags is not None:
            video.tags = tags

        # Update the index here to be sure that the categories and authors get
        # indexed correctly.
        if update_index and status == Video.ACTIVE and site_id == 1:
            index = connections['default'].get_unified_index().get_index(Video)
            index._enqueue_update(video)
        return video
Пример #3
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)
Пример #4
0
    def setUp(self):
        BaseTestCase.setUp(self)
        for i in range(3):
            self.create_video(status=Video.UNAPPROVED,
                              name='video{0}'.format(i),
                              file_url='http://google.com/{0}'.format(i))

        self.prefix = 'pfx'
        default = {
            '{0}-{1}'.format(self.prefix, TOTAL_FORM_COUNT): 4,
            '{0}-{1}'.format(self.prefix, INITIAL_FORM_COUNT): 3
        }
        qs = Video.objects.all()

        for i, v in enumerate(list(qs) + [Video()]):
            default.update(
                dict(('{0}-{1}-{2}'.format(self.prefix, i, k), v)
                     for k, v in model_to_dict(v).iteritems()))
            default['{0}-{1}-{2}'.format(self.prefix, i, 'BULK')] = True

        self.approve_data = {'bulk_action': 'feature'}
        self.feature_data = {'bulk_action': 'approve'}
        self.approve_data.update(default)
        self.feature_data.update(default)
Пример #5
0
 def get_object(self):
     if self.video is not None:
         return Video.from_vidscraper_video(self.video, commit=False)
     return Video()