예제 #1
0
    def test_query(self):
        """
        If a search query is given, the results should be limited to videos
        that contain any of the terms in their title, description, or user's
        full name.
        """
        VideoFactory.create(title='no match', approved=True)
        VideoFactory.create(description='no match', approved=True)
        user = UserProfileFactory.create(full_name='no match').user
        VideoFactory.create(user=user, approved=True)

        v1 = VideoFactory.create(title='A does match mytitle', approved=True)
        v2 = VideoFactory.create(title='B',
                                 description='does match mydesc',
                                 approved=True)
        user = UserProfileFactory.create(full_name='does match name').user
        v3 = VideoFactory.create(title='C', user=user, approved=True)

        eq_(list(search_videos(query='does')), [v1, v2, v3])

        # ANY term in the query can be used for matching.
        eq_(list(search_videos(query='what does bylaw')), [v1, v2, v3])

        # Search is case-insensitive.
        eq_(list(search_videos(query='DoEs')), [v1, v2, v3])

        # Terms may match only part of a word in the video.
        eq_(list(search_videos(query='floor do')), [v1, v2, v3])

        # Terms only have to match one of the three possible fields.
        eq_(list(search_videos(query='mytitle')), [v1])
        eq_(list(search_videos(query='mydesc')), [v2])
        eq_(list(search_videos(query='name')), [v3])
예제 #2
0
    def test_query(self):
        """
        If a search query is given, the results should be limited to videos
        that contain any of the terms in their title, description, or user's
        full name.
        """
        VideoFactory.create(title='no match', approved=True)
        VideoFactory.create(description='no match', approved=True)
        user = UserProfileFactory.create(full_name='no match').user
        VideoFactory.create(user=user, approved=True)

        v1 = VideoFactory.create(title='A does match mytitle', approved=True)
        v2 = VideoFactory.create(title='B', description='does match mydesc',
                                 approved=True)
        user = UserProfileFactory.create(full_name='does match name').user
        v3 = VideoFactory.create(title='C', user=user, approved=True)

        eq_(set(search_videos(query='does')), set([v1, v2, v3]))

        # ANY term in the query can be used for matching.
        eq_(set(search_videos(query='what does bylaw')), set([v1, v2, v3]))

        # Search is case-insensitive.
        eq_(set(search_videos(query='DoEs')), set([v1, v2, v3]))

        # Terms may match only part of a word in the video.
        eq_(set(search_videos(query='floor do')), set([v1, v2, v3]))

        # Terms only have to match one of the three possible fields.
        eq_(set(search_videos(query='mytitle')), set([v1]))
        eq_(set(search_videos(query='mydesc')), set([v2]))
        eq_(set(search_videos(query='name')), set([v3]))
예제 #3
0
    def test_query(self):
        """
        If a search query is given, the results should be limited to videos
        that contain any of the terms in their title, description, or user's
        full name.
        """
        VideoFactory.create(title="no match", approved=True)
        VideoFactory.create(description="no match", approved=True)
        user = UserProfileFactory.create(full_name="no match").user
        VideoFactory.create(user=user, approved=True)

        v1 = VideoFactory.create(title="A does match mytitle", approved=True)
        v2 = VideoFactory.create(title="B", description="does match mydesc", approved=True)
        user = UserProfileFactory.create(full_name="does match name").user
        v3 = VideoFactory.create(title="C", user=user, approved=True)

        eq_(list(search_videos(query="does")), [v1, v2, v3])

        # ANY term in the query can be used for matching.
        eq_(list(search_videos(query="what does bylaw")), [v1, v2, v3])

        # Search is case-insensitive.
        eq_(list(search_videos(query="DoEs")), [v1, v2, v3])

        # Terms may match only part of a word in the video.
        eq_(list(search_videos(query="floor do")), [v1, v2, v3])

        # Terms only have to match one of the three possible fields.
        eq_(list(search_videos(query="mytitle")), [v1])
        eq_(list(search_videos(query="mydesc")), [v2])
        eq_(list(search_videos(query="name")), [v3])
예제 #4
0
    def setUp(self):
        super(GalleryTests, self).setUp()
        self.us_user = UserProfileFactory.create(country='us').user
        self.fr_user = UserProfileFactory.create(country='fr').user

        self.v1 = VideoFactory.create(user=self.us_user, approved=True)
        self.v2 = VideoFactory.create(user=self.fr_user, approved=True)
예제 #5
0
    def setUp(self):
        super(GalleryTests, self).setUp()
        self.us_user = UserProfileFactory.create(country='us').user
        self.fr_user = UserProfileFactory.create(country='fr').user

        self.v1 = VideoFactory.create(user=self.us_user, approved=True)
        self.v2 = VideoFactory.create(user=self.fr_user, approved=True)
예제 #6
0
    def test_invaid_region(self, get_countries):
        """If the given region is invalid, do not filter by it."""
        get_countries.return_value = None
        user_fr = UserProfileFactory.create(country='fr').user
        user_pt = UserProfileFactory.create(country='pt').user

        video_fr = VideoFactory.create(user=user_fr, approved=True)
        video_pt = VideoFactory.create(user=user_pt, approved=True)

        eq_(list(search_videos(region=1)), [video_fr, video_pt])
        get_countries.assert_called_with(1)
예제 #7
0
    def test_invaid_region(self, get_countries):
        """If the given region is invalid, do not filter by it."""
        get_countries.return_value = None
        user_fr = UserProfileFactory.create(country="fr").user
        user_pt = UserProfileFactory.create(country="pt").user

        video_fr = VideoFactory.create(user=user_fr, approved=True)
        video_pt = VideoFactory.create(user=user_pt, approved=True)

        eq_(list(search_videos(region=1)), [video_fr, video_pt])
        get_countries.assert_called_with(1)
예제 #8
0
    def test_region(self, get_countries):
        """
        If the region filter is given, only return videos from countries in
        that region.
        """
        get_countries.return_value = ["us", "fr"]
        user_fr = UserProfileFactory.create(country="fr").user
        user_pt = UserProfileFactory.create(country="pt").user

        video_fr = VideoFactory.create(user=user_fr, approved=True)
        VideoFactory.create(user=user_pt, approved=True)

        eq_(list(search_videos(region=1)), [video_fr])
        get_countries.assert_called_with(1)
예제 #9
0
    def test_region(self, get_countries):
        """
        If the region filter is given, only return videos from countries in
        that region.
        """
        get_countries.return_value = ['us', 'fr']
        user_fr = UserProfileFactory.create(country='fr').user
        user_pt = UserProfileFactory.create(country='pt').user

        video_fr = VideoFactory.create(user=user_fr, approved=True)
        VideoFactory.create(user=user_pt, approved=True)

        eq_(list(search_videos(region=1)), [video_fr])
        get_countries.assert_called_with(1)
예제 #10
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('*****@*****.**',
                                              '*****@*****.**'))
예제 #11
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('*****@*****.**', '*****@*****.**'))
예제 #12
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())
예제 #13
0
    def test_unicode_name(self):
        """Users with unicode names should be deleted normally."""
        user = UserProfileFactory.create(nickname=u'\u265E').user

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

        ok_(not UserProfile.objects.filter(user=user).exists())
예제 #14
0
    def test_unicode_name(self):
        """Users with unicode names should be deleted normally."""
        user = UserProfileFactory.create(nickname=u'\u265E').user

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

        ok_(not UserProfile.objects.filter(user=user).exists())
예제 #15
0
    def test_delete_process(self, process_deletion):
        """
        When a video is deleted, the process_deletion task should be triggered.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.create(user=user, vimeo_id=123456)
        ok_(not process_deletion.delay.called)

        video.delete()
        process_deletion.delay.assert_called_with(123456, user.id)
예제 #16
0
    def test_delete_process(self, process_deletion):
        """
        When a video is deleted, the process_deletion task should be triggered.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.create(user=user, vimeo_id=123456)
        ok_(not process_deletion.delay.called)

        video.delete()
        process_deletion.delay.assert_called_with(123456, user.id)
예제 #17
0
    def test_save_process_new(self, send_approval_email):
        """
        Do not call process_approval or send_approval_email if the video is new.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.build(title='blahtest', user=user)
        video.process_approval = Mock()
        video.save()

        ok_(not video.process_approval.called)
        ok_(not send_approval_email.called)
예제 #18
0
    def test_save_process_new(self, send_approval_email):
        """
        Do not call process_approval or send_approval_email if the video is new.
        """
        user = UserProfileFactory.create().user
        video = Video2013Factory.build(title='blahtest', user=user)
        video.process_approval = Mock()
        video.save()

        ok_(not video.process_approval.called)
        ok_(not send_approval_email.called)
예제 #19
0
    def test_has_profile(self):
        """
        If the user has a profile, continue to the view.
        """
        @profile_required
        def view(request):
            return HttpResponse('asdf')

        request = self.factory.get('/someurl')
        request.user = UserProfileFactory().user
        response = view(request)
        self.assertContains(response, 'asdf')
예제 #20
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())
예제 #21
0
 def test_valid_user_id(self):
     """If a valid user_id is given, send a rejection email."""
     user = UserProfileFactory.create(user__email='*****@*****.**').user
     send_rejection_email(user.id)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].to, ['*****@*****.**'])
예제 #22
0
 def setUp(self):
     super(TestUpload, self).setUp()
     self.user = UserProfileFactory.create(user__email='*****@*****.**').user
     self.browserid_login(self.user.email)
예제 #23
0
    def setUp(self):
        super(TestUpload, self).setUp()
        Flag.objects.create(name='video-submit', everyone=True)

        self.user = UserProfileFactory.create(user__email='*****@*****.**').user
        self.browserid_login(self.user.email)
예제 #24
0
    def setUp(self):
        super(TestUpload, self).setUp()
        Flag.objects.create(name='video-submit', everyone=True)

        self.user = UserProfileFactory.create(user__email='*****@*****.**').user
        self.browserid_login(self.user.email)
예제 #25
0
 def test_basic(self):
     user = UserProfileFactory.create(user__email='*****@*****.**').user
     video = VideoFactory.create(user=user)
     send_approval_email(video)
     eq_(len(mail.outbox), 1)
     eq_(mail.outbox[0].to, ['*****@*****.**'])
예제 #26
0
 def setUp(self):
     super(TestUpload, self).setUp()
     self.user = UserProfileFactory.create(user__email='*****@*****.**').user
     self.browserid_login(self.user.email)