def test_valid_video(self, send_mail, mock_vimeo):
        """If a valid video id is given, update the Vimeo metadata."""
        # Many to many makes this super-verbose. Essentially, create two
        # moderators, one who is part of a moderator group and the other who
        # has the change_video2013 permission directly.
        perm = Permission.objects.get(codename='change_video2013')
        group = GroupFactory()
        group.permissions = [perm]
        group.save()
        moderator1 = UserFactory(email='*****@*****.**')
        moderator1.user_permissions = [perm]
        moderator1.save()
        moderator2 = UserFactory.create(email='*****@*****.**')
        moderator2.groups = [group]
        moderator2.save()

        user = UserProfileFactory.create(nickname='name', country='us').user
        video = VideoFactory.create(user=user, title='blah', description='asdf',
                                    vimeo_id=7)

        with self.settings(VIMEO_REGION_CHANNELS={regions.NORTH_AMERICA: 18},
                           DEFAULT_FROM_EMAIL='*****@*****.**'):
            process_video(video.id)

        mock_vimeo.set_title.assert_called_with(7, 'blah')
        mock_vimeo.set_description.assert_called_with(7, 'blah by name\n\nasdf')
        mock_vimeo.add_to_channel.assert_called_with(7, 18)
        mock_vimeo.add_tags.assert_called_with(7, ['us'])

        send_mail.assert_called_with(ANY, ANY, '*****@*****.**',
                                     CONTAINS('*****@*****.**',
                                              '*****@*****.**'))
Exemple #2
0
    def test_valid_video(self, send_mail, mock_vimeo):
        """If a valid video id is given, update the Vimeo metadata."""
        # Many to many makes this super-verbose. Essentially, create two
        # moderators, one who is part of a moderator group and the other who
        # has the change_video2013 permission directly.
        perm = Permission.objects.get(codename='change_video2013')
        group = GroupFactory()
        group.permissions = [perm]
        group.save()
        moderator1 = UserFactory(email='*****@*****.**')
        moderator1.user_permissions = [perm]
        moderator1.save()
        moderator2 = UserFactory.create(email='*****@*****.**')
        moderator2.groups = [group]
        moderator2.save()

        user = UserProfileFactory.create(nickname='name', country='us').user
        video = VideoFactory.create(user=user,
                                    title='blah',
                                    description='asdf',
                                    vimeo_id=7)

        with self.settings(VIMEO_REGION_CHANNELS={regions.NORTH_AMERICA: 18},
                           DEFAULT_FROM_EMAIL='*****@*****.**'):
            process_video(video.id)

        mock_vimeo.set_title.assert_called_with(7, 'blah')
        mock_vimeo.set_description.assert_called_with(7,
                                                      'blah by name\n\nasdf')
        mock_vimeo.add_to_channel.assert_called_with(7, 18)
        mock_vimeo.add_tags.assert_called_with(7, ['us'])

        send_mail.assert_called_with(
            ANY, ANY, '*****@*****.**',
            CONTAINS('*****@*****.**', '*****@*****.**'))
Exemple #3
0
    def test_no_vote(self):
        """If the user hasn't voted for the given video, return a 404."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()

        response = self._unvote_ajax(video.id)
        eq_(response.status_code, 404)
    def test_command(self):
        """If a user has not uploaded any videos, their profile should be deleted."""
        user_with_profile_no_videos = UserProfileFactory.create().user
        user_no_profile_no_videos = UserFactory.create()
        user_with_profile_with_videos = UserProfileFactory.create().user
        user_no_profile_with_videos = UserFactory.create()  # Shouldn't exist, but we'll test.

        Video2013Factory.create(user=user_with_profile_with_videos)
        Video2013Factory.create(user=user_no_profile_with_videos)

        command = wipe_spectator_personal_info.Command()
        command.handle()

        ok_(not UserProfile.objects.filter(user=user_with_profile_no_videos).exists())
        ok_(not UserProfile.objects.filter(user=user_no_profile_no_videos).exists())
        ok_(UserProfile.objects.filter(user=user_with_profile_with_videos).exists())
        ok_(not UserProfile.objects.filter(user=user_no_profile_with_videos).exists())
    def test_no_vote(self):
        """If the user hasn't voted for the given video, return a 404."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()

        response = self._unvote_ajax(video.id)
        eq_(response.status_code, 404)
    def test_vote_exists(self):
        """If the user has voted for the given video, delete the vote."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()
        Vote.objects.create(user=user, video=video)

        response = self._unvote_ajax(video.id)
        eq_(response.status_code, 200)
        ok_(not Vote.objects.filter(user=user, video=video).exists())
Exemple #7
0
    def test_vote_exists(self):
        """If the user has voted for the given video, delete the vote."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()
        Vote.objects.create(user=user, video=video)

        response = self._unvote_ajax(video.id)
        eq_(response.status_code, 200)
        ok_(not Vote.objects.filter(user=user, video=video).exists())
    def setUp(self):
        super(VerifyTests, self).setUp()
        Flag.objects.create(name='voting', everyone=True)

        self.factory = RequestFactory()
        self.request = self.factory.post('/')
        self.user = UserFactory.create()

        self.request.user = self.user
        SessionMiddleware().process_request(self.request)
        self.verify = Verify(request=self.request)
Exemple #9
0
    def setUp(self):
        super(VerifyTests, self).setUp()
        Flag.objects.create(name='voting', everyone=True)

        self.factory = RequestFactory()
        self.request = self.factory.post('/')
        self.user = UserFactory.create()

        self.request.user = self.user
        SessionMiddleware().process_request(self.request)
        self.verify = Verify(request=self.request)
Exemple #10
0
 def test_no_profile(self, use_lang):
     """
     If the user has no profile, use the installation's default language
     code for the email locale.
     """
     user = UserFactory.create(email='*****@*****.**')
     video = VideoFactory.create(user=user)
     send_approval_email(video)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].to, ['*****@*****.**'])
     use_lang.assert_called_with('fr')
Exemple #11
0
    def test_command(self):
        """If a user has not uploaded any videos, their profile should be deleted."""
        user_with_profile_no_videos = UserProfileFactory.create().user
        user_no_profile_no_videos = UserFactory.create()
        user_with_profile_with_videos = UserProfileFactory.create().user
        user_no_profile_with_videos = UserFactory.create(
        )  # Shouldn't exist, but we'll test.

        Video2013Factory.create(user=user_with_profile_with_videos)
        Video2013Factory.create(user=user_no_profile_with_videos)

        command = wipe_spectator_personal_info.Command()
        command.handle()

        ok_(not UserProfile.objects.filter(
            user=user_with_profile_no_videos).exists())
        ok_(not UserProfile.objects.filter(
            user=user_no_profile_no_videos).exists())
        ok_(
            UserProfile.objects.filter(
                user=user_with_profile_with_videos).exists())
        ok_(not UserProfile.objects.filter(
            user=user_no_profile_with_videos).exists())
    def test_authed_user_video_exists(self):
        """If the user is authed and the video exists, add a vote for it."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()

        response = self._vote_ajax(video.id)
        eq_(response.status_code, 200)
        ok_(Vote.objects.filter(user=user, video=video).exists())

        # If the vote already exists, don't add a new one.
        response = self._vote_ajax(video.id)
        eq_(response.status_code, 200)
        eq_(Vote.objects.filter(user=user, video=video).count(), 1)
Exemple #13
0
    def test_authed_user_video_exists(self):
        """If the user is authed and the video exists, add a vote for it."""
        user = UserFactory.create()
        self.browserid_login(user.email)
        video = VideoFactory.create()

        response = self._vote_ajax(video.id)
        eq_(response.status_code, 200)
        ok_(Vote.objects.filter(user=user, video=video).exists())

        # If the vote already exists, don't add a new one.
        response = self._vote_ajax(video.id)
        eq_(response.status_code, 200)
        eq_(Vote.objects.filter(user=user, video=video).count(), 1)
Exemple #14
0
    def test_empty(self, video_list):
        """
        If a user hasn't voted for any videos, my_voted_videos should be empty.
        """
        video_list.return_value = HttpResponse()

        user = UserFactory.create()
        for _ in range(14):
            VideoFactory.create(approved=True)

        response = self._my_voted_videos(user)
        eq_(response, video_list.return_value)

        videos = video_list.call_args[0][1]
        eq_(list(videos), [])
    def test_empty(self, video_list):
        """
        If a user hasn't voted for any videos, my_voted_videos should be empty.
        """
        video_list.return_value = HttpResponse()

        user = UserFactory.create()
        for _ in range(14):
            VideoFactory.create(approved=True)

        response = self._my_voted_videos(user)
        eq_(response, video_list.return_value)

        videos = video_list.call_args[0][1]
        eq_(list(videos), [])
    def test_basic(self, video_list):
        """
        my_voted_videos should list all the videos a user has voted for in the
        reverse order that they voted for them.
        """
        video_list.return_value = HttpResponse()

        user = UserFactory.create()
        v1 = VideoFactory.create(approved=True)
        v2 = VideoFactory.create(approved=True)
        Vote.objects.create(user=user, video=v1)
        Vote.objects.create(user=user, video=v2)
        for _ in range(14):
            VideoFactory.create(approved=True)

        response = self._my_voted_videos(user)
        eq_(response, video_list.return_value)

        videos = video_list.call_args[0][1]
        eq_(list(videos), [v2, v1])  # Also asserts the order of the votes.
Exemple #17
0
    def test_basic(self, video_list):
        """
        my_voted_videos should list all the videos a user has voted for in the
        reverse order that they voted for them.
        """
        video_list.return_value = HttpResponse()

        user = UserFactory.create()
        v1 = VideoFactory.create(approved=True)
        v2 = VideoFactory.create(approved=True)
        Vote.objects.create(user=user, video=v1)
        Vote.objects.create(user=user, video=v2)
        for _ in range(14):
            VideoFactory.create(approved=True)

        response = self._my_voted_videos(user)
        eq_(response, video_list.return_value)

        videos = video_list.call_args[0][1]
        eq_(list(videos), [v2, v1])  # Also asserts the order of the votes.
Exemple #18
0
 def setUp(self):
     super(ProfileTests, self).setUp()
     self.user = UserFactory.create()
     self.browserid_login(self.user.email)
 def vote_count(self, create, extracted, **kwargs):
     if create and extracted:
         for k in range(extracted):
             models.Vote.objects.create(video=self,
                                        user=UserFactory.create())
Exemple #20
0
 def vote_count(self, create, extracted, **kwargs):
     if create and extracted:
         for k in range(extracted):
             models.Vote.objects.create(video=self,
                                        user=UserFactory.create())
 def setUp(self):
     super(ProfileTests, self).setUp()
     self.user = UserFactory.create()
     self.browserid_login(self.user.email)
Exemple #22
0
 def test_authed_user_no_video(self):
     """If the user is authed but the video is invalid, return a 404."""
     user = UserFactory.create()
     self.browserid_login(user.email)
     response = self._vote_ajax(99999)
     eq_(response.status_code, 404)
 def test_authed_user_no_video(self):
     """If the user is authed but the video is invalid, return a 404."""
     user = UserFactory.create()
     self.browserid_login(user.email)
     response = self._vote_ajax(99999)
     eq_(response.status_code, 404)