def make_approve_task(team_video, language_code, user): """Move a video through the tasks process to the approve stage, then return that task. assumptions: - there are no Tasks or SubtitleVersions for this video+language - approve is enabled for the team """ team = team_video.team assert team.get_workflow().approve_allowed != 0 task = Task(team=team, team_video=team_video, assignee=None, language=language_code, type=Task.TYPE_IDS['Translate']) task.save() v = pipeline.add_subtitles(team_video.video, language_code, None, complete=False, visibility='private') task.assignee = user task.new_subtitle_version = v task = task.complete() if task.type == Task.TYPE_IDS['Review']: task.assignee = user task.approved = Task.APPROVED_IDS['Approved'] return task.complete() else: # approve task return task
def test_sent_back(self): self.setup_team() # go through the subtitle task phase task = Task(team=self.team, team_video=self.team_video, language='en', type=Task.TYPE_IDS['Subtitle'], assignee=self.user) lang = self.add_completed_subtitles('en', [ (0, 1000, "Hello, ", { 'new_paragraph': True }), (1500, 2500, "World"), ], visibility='private') task.new_subtitle_version = lang.get_tip(public=False) review_task = task.complete() # have the video get sent back in the review phase self.assertEquals(review_task.type, Task.TYPE_IDS['Review']) review_task.assignee = self.user review_task.approved = Task.APPROVED_IDS['Rejected'] new_subtitle_task = review_task.complete() # now in the approval phase self.assertEquals(new_subtitle_task.type, Task.TYPE_IDS['Subtitle']) self.assertEquals( views.LanguageList(self.video).items, [ ('English', 'needs-review', ['original', 'needs editing' ], lang.get_absolute_url()), ])
def make_review_task(team_video, language_code, user): """Move a video through the tasks process to the review stage, then return that task. assumptions: - there are no Tasks or SubtitleVersions for this video+language - review is enabled for the team """ team = team_video.team task = Task(team=team, team_video=team_video, assignee=None, language=language_code, type=Task.TYPE_IDS['Translate']) task.save() v = pipeline.add_subtitles(team_video.video, language_code, None, complete=False, visibility='private') task.assignee = user task.new_subtitle_version = v return task.complete()
def test_translation_tasks_not_blocked(self): # test that translation tasks are not blocked if the admin unpublishes # the version # make a translation task task = Task(team=self.team, team_video=self.team_video, assignee=self.user, type=Task.TYPE_IDS['Translate'], language='ru') task.save() # complete the translation task to create an approval task lang = self.make_dependent_language('ru', self.versions[-1]) task.new_subtitle_version = lang.get_tip() approve_task = task.complete() # complete the parent subtitles language, so that that's not an issue # for is_blocked(). self.language.subtitles_complete = True self.language.save() # unpublish the last version and check that that doesn't block the # approval task self.versions[-1].visibility_override = 'private' self.versions[-1].save() self.assertEquals(approve_task.is_blocked(), False)
def test_moderated_notifies_only_when_published(self): # TODO: should this use the new visibility settings instead of the old # moderation stuff? """ 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 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): subs = [(0, 1000, 'Hello', {}), (2000, 5000, 'world.', {})] add_subtitles(v, 'en', subs, author=self.author, committer=self.author) subs = [(0, 1000, 'Hello', {}), (3000, 5000, 'world.', {})] return add_subtitles(v, 'en', subs, author=self.author, committer=self.author) 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 = sub_models.SubtitleVersion.objects.get(pk=sv.pk) self.assertFalse(sv.is_public()) # no emails should be sent before the video is approved self.assertEqual(len(mail.outbox), 0) # approve video t = Task(type=40, approved=20, team_video=tv, team=team, language='en', new_subtitle_version=sv, assignee=self.author) t.save() t.complete() self.assertTrue(sv.is_public()) video_changed_tasks(v.pk, sv.pk) # Once the video is approved, we should send out the # team-task-approved-published.html email and the # email_notification_non_editors.html to the author self.assertEqual(len(mail.outbox), 2)