def test_language_number(self): date_maker = CreationDateMaker() user = test_factories.create_team_member(self.team).user video = test_factories.create_video(primary_audio_language_code='en') test_factories.create_team_video(self.team, user, video) self.add_subtitles(video, 'en', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) self.add_subtitles(video, 'fr', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) self.add_subtitles(video, 'de', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) video2 = test_factories.create_video(primary_audio_language_code='en') test_factories.create_team_video(self.team, user, video2) # the english version was added before the date range of the report. # It should still bump the language number though. self.add_subtitles(video2, 'en', make_subtitle_lines(4), created=date_maker.date_before_start(), complete=True) self.add_subtitles(video2, 'fr', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) data = self.get_report_data(self.team, date_maker.start_date(), date_maker.end_date()) self.assertEquals(data['record count'], 4) self.assertEquals(data[video.video_id]['en']['Language number'], 1) self.assertEquals(data[video.video_id]['fr']['Language number'], 2) self.assertEquals(data[video.video_id]['de']['Language number'], 3) self.assertEquals(data[video2.video_id]['fr']['Language number'], 2)
def test_two_languages(self): user = User.objects.all()[0] video = Video.objects.filter(teamvideo__isnull=False)[0] video.user = user video.save() sv_en = add_subtitles(video, 'en', make_subtitle_lines(4), author=user, complete=True) video_changed_tasks(video.pk, sv_en.pk) sv_cs = add_subtitles(video, 'cs', make_subtitle_lines(4), complete=True, author=user) video_changed_tasks(video.pk, sv_cs.pk) self.assertEquals(2, BillingRecord.objects.all().count())
def test_update_source_language(self): """ https://unisubs.sifterapp.com/issues/2225 Create a version not synced. Create a translation. Then later finish the original one """ user = User.objects.all()[0] video = Video.objects.filter(teamvideo__isnull=False)[0] video.user = user video.save() original_version = add_subtitles( video, 'en', make_subtitle_lines(4, is_synced=False), complete=False, author=user ) original_lang = original_version.subtitle_language video_changed_tasks(video.pk, original_version.pk) self.assertEquals(0, BillingRecord.objects.all().count()) translation_version = add_subtitles( video, 'pt', make_subtitle_lines(4, is_synced=False), author=user, parents=[original_version]) translation_language = translation_version.subtitle_language # no billing for this one, because it isn't synced! self.assertEquals(0, BillingRecord.objects.all().count()) # now sync them original_version = add_subtitles( video, 'en', make_subtitle_lines(4, is_synced=True), complete=True, author=user) original_lang = original_version.subtitle_language video_changed_tasks(video.pk, original_version.pk) bl_original = BillingRecord.objects.filter(new_subtitle_language=original_lang) self.assertEquals(1, bl_original.count()) translation_version = add_subtitles( video, 'pt', make_subtitle_lines(5), author=user, parents=[original_version], complete=True) video_changed_tasks(video.pk, translation_version.pk) bl_translation = BillingRecord.objects.filter(new_subtitle_language=translation_language) self.assertEquals(1, bl_translation.count())
def test_record_insertion(self): user = User.objects.all()[0] video = Video.objects.filter(teamvideo__isnull=False)[0] video.primary_audio_language_code = 'en' video.user = user video.save() now = datetime.now() sv = add_subtitles(video, 'en', make_subtitle_lines(4), complete=True, author=user, created=now) sl = sv.subtitle_language video_changed_tasks(video.pk, sv.pk) self.assertEquals(1, BillingRecord.objects.all().count()) br = BillingRecord.objects.all()[0] self.assertEquals(br.video.pk, video.pk) self.assertEquals(br.team.pk, video.get_team_video().team.pk) self.assertEquals(br.created, now) self.assertEquals(br.is_original, sl.is_primary_audio_language()) self.assertEquals(br.user.pk, user.pk) self.assertEquals(br.new_subtitle_language.pk, sl.pk) team = video.get_team_video().team start = datetime(2013, 1, 1, 0, 0) end = datetime.now() + timedelta(days=1) csv_data = BillingRecord.objects.csv_report_for_team(team, start, end) self.assertEquals(2, len(csv_data)) self.assertEquals(10, len(csv_data[1])) # 2 sv = add_subtitles(video, 'en', make_subtitle_lines(4), author=user, created=now) sl = sv.subtitle_language video_changed_tasks(video.pk, sv.pk) # A new one shouldn't be created for the same language self.assertEquals(1, BillingRecord.objects.all().count())
def test_update_language_complete(self): """ https://unisubs.sifterapp.com/issues/2225 Create a version not synced. Then later """ user = User.objects.all()[0] video = Video.objects.filter(teamvideo__isnull=False)[0] video.user = user video.save() first_version = add_subtitles(video, 'en', make_subtitle_lines(4, is_synced=False), complete=False, author=user) # create a transla video_changed_tasks(video.pk, first_version.pk) self.assertEquals(0, BillingRecord.objects.all().count()) second_version = add_subtitles(video, 'en', make_subtitle_lines(4), complete=True, author=user) video_changed_tasks(video.pk, second_version.pk) self.assertEquals(1, BillingRecord.objects.all().count())
def test_missing_records(self): date_maker = CreationDateMaker() user = test_factories.create_team_member(self.team).user video = test_factories.create_video(primary_audio_language_code='en') test_factories.create_team_video(self.team, user, video) # For en and de, we call pipeline.add_subtitles directly, so there's # no BillingRecord in the sytem. This simulates the languages that # were completed before BillingRecords were around. add_subtitles(video, 'en', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) add_subtitles(video, 'de', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) # pt-br has a uncompleted subtitle language. We should not list that # language in the report add_subtitles(video, 'pt-br', make_subtitle_lines(4), created=date_maker.next_date(), complete=False) self.add_subtitles(video, 'fr', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) self.add_subtitles(video, 'es', make_subtitle_lines(4), created=date_maker.next_date(), complete=True) data = self.get_report_data(self.team, date_maker.start_date(), date_maker.end_date()) self.assertEquals(data['record count'], 4) self.assertEquals(data[video.video_id]['en']['Language number'], 0) self.assertEquals(data[video.video_id]['de']['Language number'], 0) self.assertEquals(data[video.video_id]['fr']['Language number'], 1) self.assertEquals(data[video.video_id]['es']['Language number'], 2) self.assertEquals(data[video.video_id]['en']['Minutes'], 0) self.assertEquals(data[video.video_id]['de']['Minutes'], 0)
def test_original_language(self): user = User.objects.all()[0] video = Video.objects.filter(teamvideo__isnull=False)[0] video.user = user video.primary_audio_language_code = '' video.save() sv_en = add_subtitles(video, 'en', make_subtitle_lines(4), complete=True) video_changed_tasks(video.pk, sv_en.pk) self.assertEquals(1, BillingRecord.objects.all().count()) br = BillingRecord.objects.all()[0] self.assertFalse(br.is_original)
def test_non_ascii_text(self): non_ascii_text = u'abcd\xe9' user = test_factories.create_user(username=non_ascii_text) test_factories.create_team_member(self.team, user) self.video.title = non_ascii_text self.video.save() sv = add_subtitles(self.video, 'en', make_subtitle_lines(4), title=non_ascii_text, author=user, description=non_ascii_text, complete=True) video_changed_tasks(self.video.pk, sv.pk) report = BillingReport.objects.create( start_date=sv.created - timedelta(days=1), end_date=sv.created + timedelta(days=1), type=BillingReport.TYPE_NEW, ) report.teams.add(self.team) self.process_report(report)