Beispiel #1
0
    def test_context_data__top(self):
        contest = self.create_contest(detail_columns=Contest.TOP,
                                      allow_downvotes=False)
        video1 = self.create_video(name='video1')
        video2 = self.create_video(name='video2')
        video3 = self.create_video(name='video3')
        cv1 = self.create_contestvideo(contest, video1, upvotes=5)
        self.create_contestvideo(contest, video2, upvotes=10)
        self.create_contestvideo(contest, video3, upvotes=3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video1, video3])
        self.assertTrue('random_videos' not in context_data)
        self.assertTrue('new_videos' not in context_data)

        # Downvotes should be ignored if they're disallowed.  By adding 6 down
        # votes to the video with 5 votes, if the down votes are counted at all
        # that video will be in the wrong place.
        self.create_votes(cv1, 6, are_up=False)
        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video1, video3])

        # ... and taken into account otherwise.
        contest.allow_downvotes = True
        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video3, video1])
Beispiel #2
0
    def test_context_data__top(self):
        contest = self.create_contest(detail_columns=Contest.TOP,
                                      allow_downvotes=False)
        video1 = self.create_video(name='video1')
        video2 = self.create_video(name='video2')
        video3 = self.create_video(name='video3')
        cv1 = self.create_contestvideo(contest, video1, upvotes=5)
        self.create_contestvideo(contest, video2, upvotes=10)
        self.create_contestvideo(contest, video3, upvotes=3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video1, video3])
        self.assertTrue('random_videos' not in context_data)
        self.assertTrue('new_videos' not in context_data)

        # Downvotes should be ignored if they're disallowed.  By adding 6 down
        # votes to the video with 5 votes, if the down votes are counted at all
        # that video will be in the wrong place.
        self.create_votes(cv1, 6, are_up=False)
        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video1, video3])

        # ... and taken into account otherwise.
        contest.allow_downvotes = True
        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['top_videos']),
                         [video2, video3, video1])
Beispiel #3
0
    def test_context_data__random(self):
        contest = self.create_contest(detail_columns=Contest.RANDOM)
        video1 = self.create_video(name='video1')
        video2 = self.create_video(name='video2')
        video3 = self.create_video(name='video3')
        self.create_contestvideo(contest, video1)
        self.create_contestvideo(contest, video2)
        self.create_contestvideo(contest, video3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertTrue('random_videos' in context_data)
        self.assertTrue('new_videos' not in context_data)
        self.assertTrue('top_videos' not in context_data)

        # Try to test whether the videos are randomly arranged.
        random = list(context_data['random_videos'])
        contexts = [view.get_context_data(object=contest) for i in xrange(10)]
        self.assertTrue(
            any([random != list(c['random_videos']) for c in contexts]))
Beispiel #4
0
    def test_context_data__new(self):
        contest = self.create_contest(detail_columns=Contest.NEW)
        # MySQL times are only accurate to one second, so make sure the times
        # are different by a whole second.
        now = datetime.datetime.now()
        second = datetime.timedelta(seconds=1)
        video1 = self.create_video(name='video1',
                                   when_approved=now - second * 2)
        video2 = self.create_video(name='video2', when_approved=now - second)
        video3 = self.create_video(name='video3', when_approved=now)
        self.create_contestvideo(contest, video1)
        self.create_contestvideo(contest, video2)
        self.create_contestvideo(contest, video3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['new_videos']),
                         [video3, video2, video1])
        self.assertTrue('random_videos' not in context_data)
        self.assertTrue('top_videos' not in context_data)
Beispiel #5
0
    def test_context_data__random(self):
        contest = self.create_contest(detail_columns=Contest.RANDOM)
        video1 = self.create_video(name='video1')
        video2 = self.create_video(name='video2')
        video3 = self.create_video(name='video3')
        self.create_contestvideo(contest, video1)
        self.create_contestvideo(contest, video2)
        self.create_contestvideo(contest, video3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertTrue('random_videos' in context_data)
        self.assertTrue('new_videos' not in context_data)
        self.assertTrue('top_videos' not in context_data)

        # Try to test whether the videos are randomly arranged.
        random = list(context_data['random_videos'])
        contexts = [view.get_context_data(object=contest)
                    for i in xrange(10)]
        self.assertTrue(any([random != list(c['random_videos'])
                             for c in contexts]))
Beispiel #6
0
    def test_context_data__new(self):
        contest = self.create_contest(detail_columns=Contest.NEW)
        # MySQL times are only accurate to one second, so make sure the times
        # are different by a whole second.
        now = datetime.datetime.now()
        second = datetime.timedelta(seconds=1)
        video1 = self.create_video(name='video1',
                                   when_approved=now - second * 2)
        video2 = self.create_video(name='video2',
                                   when_approved=now - second)
        video3 = self.create_video(name='video3',
                                   when_approved=now)
        self.create_contestvideo(contest, video1)
        self.create_contestvideo(contest, video2)
        self.create_contestvideo(contest, video3)

        view = ContestDetailView()
        view.object = contest

        context_data = view.get_context_data(object=contest)
        self.assertEqual(list(context_data['new_videos']),
                         [video3, video2, video1])
        self.assertTrue('random_videos' not in context_data)
        self.assertTrue('top_videos' not in context_data)
Beispiel #7
0
                                                   DirectLinkSubmitVideoForm)
from localtv.contrib.contests.submit_views import (can_submit_video,
                                                   SubmitURLView,
                                                   SubmitVideoView,
                                                   submit_thanks)
from localtv.decorators import require_site_admin
from localtv.listing.views import SiteListView


urlpatterns = patterns('localtv.contrib.voting.views',
    url(r'^contests/$',
        SiteListView.as_view(model=Contest,
                             template_name='contests/list.html'),
        name='contests_contest_list'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/?$',
    	ContestDetailView.as_view(),
        name='contests_contest_detail'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/videos/?$',
    	ContestListingView.as_view(),
        name='contests_contest_listing'),
    url(r'^admin/contests/?$',
        require_site_admin(ContestAdminListView.as_view()),
    	name='localtv_admin_contests'),
    url(r'^admin/contests/add/?$',
        require_site_admin(ContestAdminCreateView.as_view()),
        name='localtv_admin_contests_create'),
    url(r'^admin/contests/edit/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminUpdateView.as_view()),
        name='localtv_admin_contests_update'),
    url(r'^admin/contests/delete/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminDeleteView.as_view()),
Beispiel #8
0
                                        DirectLinkSubmitVideoForm)
from localtv.contrib.contests.submit_views import (can_submit_video,
                                                   SubmitURLView,
                                                   SubmitVideoView,
                                                   submit_thanks)
from localtv.decorators import require_site_admin
from localtv.listing.views import SiteListView

urlpatterns = patterns(
    'localtv.contrib.voting.views',
    url(r'^contests/$',
        SiteListView.as_view(model=Contest,
                             template_name='contests/list.html'),
        name='contests_contest_list'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/?$',
        ContestDetailView.as_view(),
        name='contests_contest_detail'),
    url(r'^contests/(?P<pk>[0-9]+)(?:/(?P<slug>[\w-]+))?/videos/?$',
        ContestListingView.as_view(),
        name='contests_contest_listing'),
    url(r'^admin/contests/?$',
        require_site_admin(ContestAdminListView.as_view()),
        name='localtv_admin_contests'),
    url(r'^admin/contests/add/?$',
        require_site_admin(ContestAdminCreateView.as_view()),
        name='localtv_admin_contests_create'),
    url(r'^admin/contests/edit/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminUpdateView.as_view()),
        name='localtv_admin_contests_update'),
    url(r'^admin/contests/delete/(?P<pk>[\d]+)/?$',
        require_site_admin(ContestAdminDeleteView.as_view()),