def test_approved(self): self.assertEquals(0, Workflow.objects.count()) self.team.workflow_enabled = True self.team.save() Workflow.objects.create(team=self.team, approve_allowed=20) self.assertEquals(1, Workflow.objects.count()) self.assertTrue(self.team.get_workflow().approve_enabled) english = make_subtitle_language(self.video, 'en') spanish = make_subtitle_language(self.video, 'es') for i in range(1, 10): add_subtitles(self.video, english.language_code,[], created=datetime(2012, 1, i, 0, 0, 0), visibility='private', ) # make two versions public to be sure we're selecting the very first one v1_en = SubtitleVersion.objects.get(subtitle_language=english, version_number=3) v2_en = SubtitleVersion.objects.get(subtitle_language=english, version_number=6) v1_en.publish() v1_en.save() v2_en.publish() v2_en.save() b = BillingReport.objects.create( start_date=date(2012, 1, 1), end_date=date(2012, 1, 2)) b.teams.add(self.team) past_date = self.team.created - timedelta(days=5) make_subtitle_version(spanish, created=past_date, note=FROM_YOUTUBE_MARKER) langs = self.video.newsubtitlelanguage_set.all() self.assertEqual(len(langs) , 2) created, imported, _ = b._get_lang_data(langs, datetime(2012, 1, 1, 13, 30, 0), self.team ) self.assertEqual(len(created) , 1) v = created[0][1] self.assertEquals(v.version_number, 3) self.assertEqual(v.subtitle_language , english)
def test_review_subs(self): team = get_team(1, reviewers='peers') author = get_user(1) get_team_member(author, team) reviewer = get_user(2) get_team_member(reviewer, team) video = get_video(1) video.primary_audio_language_code = 'en' video.save() get_team_video(video, team, author) # Make some initial subtitles. # This should create a review task for them. sl_en = make_subtitle_language(video, 'en') sv = make_subtitle_version(sl_en, author=author, complete=True) self._assertFollowers(sl_en, [author]) self.assertEqual(Task.objects.count(), 1) self.assertEqual(Task.objects.incomplete_review().count(), 1) # When you review a set of subtitles, you should follow that language. sv.set_reviewed_by(reviewer) self._assertFollowers(sl_en, [author, reviewer])
def test_create_edit_subs(self): video = get_video(1) sl_en = make_subtitle_language(video, 'en') # Start off with zero followers. self._assertFollowers(video, []) self._assertFollowers(sl_en, []) # Transcriber/translator should follow only the language, not the video. en_author = get_user(1) make_subtitle_version(sl_en, author=en_author) self._assertFollowers(video, []) self._assertFollowers(sl_en, [en_author]) # Create a "translation". sl_ru = make_subtitle_language(video, 'ru') self.assertEqual(sl_ru.followers.count(), 0) ru_author = get_user(2) make_subtitle_version(sl_ru, author=ru_author, parents=[('en', 1)]) # Translation editors should follow only the language, not the video. self.assertEqual(sl_ru.get_translation_source_language_code(), 'en') self._assertFollowers(video, []) self._assertFollowers(sl_en, [en_author]) self._assertFollowers(sl_ru, [ru_author]) # Editors should also follow only the language, not the video. editor = get_user(3) make_subtitle_version(sl_en, author=editor) self._assertFollowers(video, []) self._assertFollowers(sl_en, [en_author, editor]) self._assertFollowers(sl_ru, [ru_author]) make_subtitle_version(sl_ru, author=editor) self._assertFollowers(video, []) self._assertFollowers(sl_en, [en_author, editor]) self._assertFollowers(sl_ru, [ru_author, editor])
def test_upload_respects_lock(self): user1 = get_user(1) user2 = get_user(2) video = get_video() sl_en = make_subtitle_language(video, 'en') request1 = RequestMockup(user1) # Lock the language for user 1. sl_en.writelock(user1, request1.browser_id) self.assertTrue(sl_en.is_writelocked) # Now try to upload subtitles as user 2. self._login(user2) self._upload(video, 'en', 'en', None, True, 'test.srt') # The subtitles should not have been created. # # We can't really tests the response here because the upload_subtitles # view is terrible and always returns a 200 with a horrible mix of HTML # and JSON as a response. So instead we'll just make sure that the # subtitles were not actually created. self.assertFalse(sl_en.subtitleversion_set.full().exists()) # User 1 has the writelock, so uploading subtitles should work for them. self._login(user1) self._upload(video, 'en', 'en', None, True, 'test.srt') self.assertEqual(sl_en.subtitleversion_set.full().count(), 1) # User 1 still has the writelock, so user 2 still can't upload. self._login(user2) self._upload(video, 'en', 'en', None, True, 'test.srt') self.assertEqual(sl_en.subtitleversion_set.full().count(), 1) # Release the writelock. sl_en.release_writelock() # Now user 2 can finally upload their subtitles. self._login(user2) self._upload(video, 'en', 'en', None, True, 'test.srt') self.assertEqual(sl_en.subtitleversion_set.full().count(), 2)
def test_model_rollback(self): video = get_video() sl_en = make_subtitle_language(video, 'en') en1 = make_subtitle_version(sl_en, []) en2 = make_subtitle_version(sl_en, [(1, 2, "foo")]) self._login() def _assert_tip_subs(subs): sl_en.clear_tip_cache() self.assertEqual([(start, end, txt) for start, end, txt, meta in list(sl_en.get_tip().get_subtitles())], subs) # Ensure the rollback works through the view. self.client.get(reverse('videos:rollback', args=[en1.id])) _assert_tip_subs([]) self.client.get(reverse('videos:rollback', args=[en2.id])) _assert_tip_subs([(1, 2, 'foo')]) self.assertEqual(sl_en.subtitleversion_set.full().count(), 4)
def test_dfxp_serializer(self): video = get_video() sl_en = make_subtitle_language(video, 'en') video.primary_audio_language_code = 'en' video.save() self.test_title = "This is a really long title used to make sure we are not truncating file names" self.assertTrue(len(self.test_title) > 60) make_subtitle_version( sl_en, [(100, 200, 'Here we go!')], title=self.test_title, ) content = self._download_subs(sl_en, 'dfxp') serialized = DFXPParser(content) subtitle_set = serialized.to_internal() self.assertEqual(len(subtitle_set), 1) start, end, content, meta = list(subtitle_set)[0] self.assertEqual(start, 100) self.assertEqual(end, 200) self.assertEqual(content, 'Here we go!')
def test_language_url_for_empty_lang(self): v = get_video(1) sl = make_subtitle_language(v, 'en') self.assertIsNotNone(language_url(None, sl))