Example #1
0
 def setUp(self):
     self.tv = TeamVideo.objects.all()[0]
     self.sl = SubtitleLanguage.objects.exclude(language='')[0]
     self.team = Team.objects.all()[0]
     tv = TeamVideo(team=self.team,
                    video=self.sl.video,
                    added_by=self.team.users.all()[:1].get())
     tv.save()
Example #2
0
def _create_team_videos(team, videos, users):
    tvs = []
    for video in videos:
        shuffle(users)
        team_video = TeamVideo(team=team, video=video)
        member, created = CustomUser.objects.get_or_create(user_ptr=users[0])
        team_video.added_by = member
        team_video.save()
        tvs.append(team_video)
    return tvs
Example #3
0
    def save(self, *args, **kwargs):
        videos = super(AddTeamVideosFromFeedForm, self).save(*args, **kwargs)

        team_videos = []
        for video, video_created in videos:
            try:
                tv = TeamVideo.objects.get(video=video, team=self.team)
                tv_created = False
            except TeamVideo.DoesNotExist:
                tv = TeamVideo(video=video, team=self.team, added_by=self.user)
                tv.save()
                tv_created = True
            team_videos.append((tv, tv_created))

        return team_videos
Example #4
0
    def setUp(self):
        self.team = Team(name='test', slug='test')
        self.team.save()
        
        self.user = User.objects.all()[:1].get()
        self.user.is_active = True
        self.user.changes_notification = True
        self.user.email = '*****@*****.**'
        self.user.save()
        
        self.tm = TeamMember(team=self.team, user=self.user)
        self.tm.save()

        v1 = Video.objects.all()[:1].get()
        self.tv1 = TeamVideo(team=self.team, video=v1, added_by=self.user)
        self.tv1.save()
        
        v2 = Video.objects.exclude(pk=v1.pk)[:1].get()
        self.tv2 = TeamVideo(team=self.team, video=v2, added_by=self.user)
        self.tv2.save()
Example #5
0
    def test_moderated_notifies_only_when_published(self):
        """
        Set up a public team, add new video and new version.
        Notification should be sent.
        Setup  a team with moderated videos
        """
        from teams.moderation_const import WAITING_MODERATION, APPROVED

        def video_with_two_followers():
            v, c = Video.get_or_create_for_url(
                "http://blip.tv/file/get/Miropcf-AboutUniversalSubtitles847.ogv"
            )
            f1 = User.objects.all()[0]
            f2 = User.objects.all()[1]
            f1.notify_by_email = f2.notify_by_email = True
            f1.save()
            f2.save()
            v.followers.add(f1, f2)
            return v

        def new_version(v):

            language, created = SubtitleLanguage.objects.get_or_create(
                video=v, language='en', is_original=True)
            prev = language.version(public_only=False)
            version_no = 0
            if prev:
                version_no = prev.version_no + 1
            sv = SubtitleVersion(language=language,
                                 user=User.objects.all()[2],
                                 version_no=version_no,
                                 datetime_started=datetime.now())
            sv.save()
            s = Subtitle(version=sv,
                         subtitle_text=str(version_no + random.random()),
                         subtitle_order=1,
                         subtitle_id=str(version_no),
                         start_time=random.random())
            s.save()
            return sv

        v = video_with_two_followers()
        mail.outbox = []
        from videos.tasks import video_changed_tasks
        v = video_with_two_followers()
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # notifications are only sent on the second version of a video
        # as optimization
        sv = new_version(v)
        video_changed_tasks(v.pk, sv.pk)
        # video is public , followers should be notified
        self.assertEquals(len(mail.outbox), 2)
        mail.outbox = []
        # add to a moderated video
        team = Team.objects.create(slug='my-team',
                                   name='myteam',
                                   workflow_enabled=True)
        workflow = Workflow(team=team, review_allowed=20, approve_allowed=20)
        workflow.save()

        tv = TeamVideo(team=team, video=v, added_by=User.objects.all()[2])
        tv.save()
        sv = new_version(v)
        # with the widget, this would set up correctly
        sv.moderation_status = WAITING_MODERATION
        sv.save()

        video_changed_tasks(v.pk, sv.pk)
        sv = SubtitleVersion.objects.get(pk=sv.pk)
        self.assertFalse(sv.is_public)
        # approve video
        t = Task(type=40,
                 approved=20,
                 team_video=tv,
                 team=team,
                 language='en',
                 subtitle_version=sv)
        t.save()
        t.complete()
        video_changed_tasks(v.pk, sv.pk)

        self.assertEqual(len(mail.outbox), 2)
Example #6
0
class TestCommands(TestCase):
    
    fixtures = ["test.json"]
    
    def setUp(self):
        self.team = Team(name='test', slug='test')
        self.team.save()
        
        self.user = User.objects.all()[:1].get()
        self.user.is_active = True
        self.user.changes_notification = True
        self.user.email = '*****@*****.**'
        self.user.save()
        
        self.tm = TeamMember(team=self.team, user=self.user)
        self.tm.save()

        v1 = Video.objects.all()[:1].get()
        self.tv1 = TeamVideo(team=self.team, video=v1, added_by=self.user)
        self.tv1.save()
        
        v2 = Video.objects.exclude(pk=v1.pk)[:1].get()
        self.tv2 = TeamVideo(team=self.team, video=v2, added_by=self.user)
        self.tv2.save()
        
    def test_new_team_video_notification(self):
        #mockup for send_templated_email to test context of email
        import utils
        
        send_templated_email = utils.send_templated_email
        
        def send_templated_email_mockup(to, subject, body_template, body_dict, *args, **kwargs):
            send_templated_email_mockup.context = body_dict
            send_templated_email(to, subject, body_template, body_dict, *args, **kwargs)
        
        utils.send_templated_email = send_templated_email_mockup
        
        #check initial data
        self.assertEqual(self.team.teamvideo_set.count(), 2)
        self.assertEqual(self.team.users.count(), 1)
        
        today = datetime.today()
        date = today - timedelta(hours=24)
        
        #test notification about two new videos
        TeamVideo.objects.filter(pk__in=[self.tv1.pk, self.tv2.pk]).update(created=datetime.today())
        self.assertEqual(TeamVideo.objects.filter(created__gte=date).count(), 2)
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [self.user.email])
        self.assertEqual(len(send_templated_email_mockup.context['team_videos']), 2)
        
        #test if user turn off notification
        self.user.is_active = False
        self.user.save()
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 0)
        
        self.user.is_active = True
        self.user.changes_notification = False
        self.user.save()
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 0)        

        self.user.changes_notification = True
        self.user.save()
        self.tm.changes_notification = False
        self.tm.save()
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 0)    

        self.tm.changes_notification = True
        self.tm.save()
        
        #test notification if one video is new
        past_date = today - timedelta(days=2)
        TeamVideo.objects.filter(pk=self.tv1.pk).update(created=past_date)
        self.assertEqual(TeamVideo.objects.filter(created__gte=date).count(), 1)
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(send_templated_email_mockup.context['team_videos']), 1)
        self.assertEqual(send_templated_email_mockup.context['team_videos'][0], self.tv2)
        
        #test notification if all videos are old
        TeamVideo.objects.filter(pk__in=[self.tv1.pk, self.tv2.pk]).update(created=past_date)
        self.assertEqual(TeamVideo.objects.filter(created__gte=date).count(), 0)
        mail.outbox = []
        call_command('new_team_video_notification')
        self.assertEqual(len(mail.outbox), 0)
Example #7
0
 def setUp(self):
     self.tv = TeamVideo.objects.all()[0]
     self.sl = SubtitleLanguage.objects.exclude(language='')[0]
     self.team = Team.objects.all()[0]
     tv = TeamVideo(team=self.team, video=self.sl.video, added_by=self.team.users.all()[:1].get())
     tv.save()