def test_notify_contributor(self): """Subtitle contributor gets an email when new revision added. """ video = VideoUrlFactory().video self.video_pg.open_video_page(video.video_id) self.video_pg.log_in(self.user.username, 'password') rev1 = os.path.join(self.subs_path, 'rev1.dfxp') self.video_pg.open_video_page(video.video_id) self.video_pg.upload_subtitles('English', rev1) sl = video.subtitle_language('en') v1 = sl.get_tip().id sl.clear_tip_cache() user2 = UserFactory.create() self.video_pg.log_in(user2.username, 'password') rev2 = os.path.join(self.subs_path, 'rev2.dfxp') self.video_pg.open_video_page(video.video_id) mail.outbox = [] self.video_pg.upload_subtitles('English', rev2) email_to = mail.outbox[-1].to msg = str(mail.outbox[-1].message()) #self.logger.info("MESSAGE: %s" % msg) v2 = sl.get_tip().id diffing_page = ('videos/diffing/{0}/{1}/'.format(v2, v1)) self.video_pg.open_page(diffing_page) self.assertIn(diffing_page, msg) self.assertIn(self.user.email, email_to)
def test__version__overwrite_existing(self): """On upload, create a new version and replace original transcription. Uploaded subs replace the existing version of original lang text. """ tv = VideoUrlFactory(url='http://www.example.com/4.mp4').video video_list = self.data_utils.create_videos_with_fake_subs() test_file = 'Untimed_text.srt' sub_file = os.path.join(self.subs_data_dir, test_file) self.video_pg.open_video_page(tv.video_id) message = self.video_pg.upload_subtitles('Arabic', sub_file) self.assertEqual(self.video_pg.UPLOAD_SUCCESS_TEXT, message) sub_lang = tv.subtitle_language('ar') self.video_pg.page_refresh() subtitle_lang = tv.subtitle_language('ar') subtitle_lang.clear_tip_cache() self.assertEqual(2, subtitle_lang.get_tip().version_number)
def test_notify__language_follower(self): """Language follower gets an email when new revision added. """ video = VideoUrlFactory().video self.video_pg.open_video_page(video.video_id) self.video_pg.log_in(self.user.username, 'password') rev1 = os.path.join(self.subs_path, 'rev1.dfxp') self.video_pg.open_video_page(video.video_id) self.video_pg.upload_subtitles('English', rev1) follower = UserFactory.create(email='*****@*****.**') self.video_language_pg.open_video_lang_page(video.video_id, 'en') self.video_pg.log_in(follower.username, 'password') self.video_pg.page_refresh() self.video_pg.toggle_follow() mail.outbox = [] self.video_pg.log_in(self.user.username, 'password') rev2 = os.path.join(self.subs_path, 'rev2.dfxp') self.video_pg.open_video_page(video.video_id) self.video_pg.upload_subtitles('English', rev2) email_to = mail.outbox[-1].to msg = str(mail.outbox[-1].message()) self.logger.info("MESSAGE: %s" % msg) self.assertIn(follower.email, email_to) urlstart = 'http://' + Site.objects.get_current().domain lang = video.subtitle_language('en') # combine whitespace and replace it with " " for easier string # comparisons msg = ' '.join(msg.split()) correct_message = string.Template( '<b><a href="${lang_url}">${lang_name} subtitles</a></b> ' 'to video <b><a href="${video_url}">${video_name}</a></b> ' 'were changed by <b><a href="${user_url}">${user_name}</a></b>. ' 'These changes went live immediately. 33% of the timing was ' 'changed.').substitute({ 'lang_url': urlstart + rmlocale(lang.get_absolute_url()), 'lang_name': lang.get_language_code_display(), 'video_url': urlstart + rmlocale(video.get_absolute_url()), 'video_name': video.title_display(), 'user_url': urlstart + rmlocale(self.user.get_absolute_url()), 'user_name': self.user.username, }) self.assertIn(correct_message, msg)
def test_version__existing_translation(self): """On upload, create a new version and replace existing translation. Uploaded subs replace the existing version even if the existing version has subs created from it. """ tv = VideoUrlFactory(url='http://www.example.com/3.mp4').video video_list = self.data_utils.create_videos_with_fake_subs() test_file = 'Untimed_text.srt' sub_file = os.path.join(self.subs_data_dir, test_file) self.video_pg.open_video_page(tv.video_id) message = self.video_pg.upload_subtitles('Russian', sub_file) self.assertEqual(self.video_pg.UPLOAD_SUCCESS_TEXT, message) subtitle_lang = tv.subtitle_language('ru') subtitle_lang.clear_tip_cache() self.assertEqual(2, subtitle_lang.get_tip().version_number)
def test_upload__additional_translation(self): """Uploading a set of subs in a new language. New language is created as a new version. """ tv = VideoUrlFactory().video video_list = self.data_utils.create_videos_with_fake_subs() test_file = 'Untimed_text.srt' sub_file = os.path.join(self.subs_data_dir, test_file) self.video_pg.open_video_page(tv.video_id) message = self.video_pg.upload_subtitles('Swedish', sub_file) self.assertEqual(self.video_pg.UPLOAD_SUCCESS_TEXT, message) self.video_pg.page_refresh() subtitle_lang = tv.subtitle_language('sv') subtitle_lang.clear_tip_cache() self.assertEqual(1, subtitle_lang.get_tip().version_number) self.assertEqual(43, subtitle_lang.get_subtitle_count())