Пример #1
0
    def test_upload_and_rollbacks(self):
        video = get_video()

        self._assertCounts(video, {})

        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._upload(video, 'en', 'en', None, True, 'test_fewer_subs.srt')
        self._upload(video, 'fr', 'en', 'en', True, 'test_fewer_subs.srt')
        self._assertCounts(video, {'en': 2, 'fr': 1})

        # We now have:
        #
        # en fr
        #    1
        #   /
        #  /
        # 2
        # |
        # 1

        # Let's sanity check that we can still upload to English now that it has
        # a dependent language (French).
        self._upload(video, 'en', 'en', None, True, 'test_fewer_subs.srt')
        self._assertCounts(video, {'en': 3, 'fr': 1})

        # The translation should now be forked.
        self.assertTrue(video.subtitle_language('fr').is_forked)

        # Now let's roll English back to v1.
        pipeline.rollback_to(video, 'en', 1)
        self._assertCounts(video, {'en': 4, 'fr': 1})

        # And try uploading something on top of the rollback.
        self._upload(video, 'en', 'en', None, True, 'test_fewer_subs.srt')
        self._assertCounts(video, {'en': 5, 'fr': 1})
Пример #2
0
    def test_upload_origin_on_version(self):
        # Start with a fresh video.
        video = get_video()

        self._upload(video, 'fr', 'en', None, True, 'test.srt')
        sv = video.newsubtitlelanguage_set.get(language_code='fr').get_tip()
        self.assertEqual(sv.origin, ORIGIN_UPLOAD)
Пример #3
0
    def test_upload_subtitles_non_primary_language(self):
        # Start with a fresh video.
        video = get_video()
        self.assertEqual(video.primary_audio_language_code, '')
        self.assertFalse(video.has_original_language())
        self.assertIsNone(video.complete_date)

        # Upload subtitles in a language other than the primary.
        response = self._upload(video, 'fr', 'en', None, True, 'test.srt')
        self.assertEqual(response.status_code, 200)

        video = refresh(video)

        # The writelock should be gone once the subtitles have been uploaded.
        self.assertFalse(video.is_writelocked)

        # The video should now have a primary audio language, since it was set
        # as part of the upload process.
        self.assertEqual(video.primary_audio_language_code, 'en')

        # But it doesn't have a SubtitleLanguage for it.
        self.assertFalse(video.has_original_language())
        self.assertIsNone(video.subtitle_language())
        self.assertIsNone(video.get_primary_audio_subtitle_language())

        # Ensure that the subtitles actually got uploaded too.
        sl_fr = video.subtitle_language('fr')
        self.assertIsNotNone(sl_fr)
        self.assertEqual(sl_fr.subtitleversion_set.full().count(), 1)

        fr1 = sl_fr.get_tip()
        subtitles = fr1.get_subtitles()
        self.assertEqual(fr1.subtitle_count, 32)
        self.assertEqual(len(subtitles), 32)

        # Now that we've uploaded a complete set of subtitles, the video and
        # language should be marked as completed.
        self.assertIsNotNone(video.complete_date)
        self.assertTrue(sl_fr.subtitles_complete)

        # Let's make sure they didn't get mistakenly marked as a translation.
        # They're not in the primary language but are still a transcription.
        self.assertIsNone(sl_fr.get_translation_source_language())

        # Upload another version just to be sure.
        response = self._upload(video, 'fr', 'en', None, True, 'test.srt')
        self.assertEqual(response.status_code, 200)

        video = refresh(video)
        sl_fr = refresh(sl_fr)

        self.assertFalse(video.has_original_language())
        self.assertIsNone(video.subtitle_language())
        self.assertIsNone(video.get_primary_audio_subtitle_language())
        self.assertIsNotNone(video.complete_date)
        self.assertTrue(sl_fr.subtitles_complete)
        self.assertEqual(sl_fr.subtitleversion_set.full().count(), 2)
Пример #4
0
    def test_upload_to_language_with_dependents(self):
        video = get_video()
        self._assertVersionCount(video, 0)

        # You CAN upload subtitles to a language that already has dependents (it
        # will just fork the dependents).
        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._upload(video, 'fr', 'en', 'en', True, 'test.srt')
        self._assertVersionCount(video, 2)

        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._assertVersionCount(video, 3)
Пример #5
0
    def test_upload_translation_over_other_translation(self):
        video = get_video()
        self._assertVersionCount(video, 0)

        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._upload(video, 'de', 'en', None, True, 'test.srt')
        self._upload(video, 'fr', 'en', 'en', True, 'test.srt')
        self._assertVersionCount(video, 3)

        # Now fr is  translated from de, this should fail
        self._upload(video, 'fr', 'en', 'de', True, 'test.srt')
        self._assertVersionCount(video, 3)
Пример #6
0
    def test_upload_translation_over_nontranslation(self):
        video = get_video()
        self._assertVersionCount(video, 0)

        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._upload(video, 'de', 'en', None, True, 'test.srt')
        self._assertVersionCount(video, 2)

        # You can't upload a translation over an existing non-translation
        # language.
        self._upload(video, 'de', 'en', 'en', True, 'test.srt')
        self._assertVersionCount(video, 2)
Пример #7
0
    def test_upload_translation_with_fewer_subs(self):
        video = get_video()
        self._assertVersionCount(video, 0)

        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._assertVersionCount(video, 1)

        # Uploading a translation with a different number of subs than the
        # original language is not allowed.
        self._upload(video, 'is', 'en', 'en', True, 'test_fewer_subs.srt')
        self.assertEqual(video.newsubtitlelanguage_set.count(), 2)

        self._upload(video, 'is', 'en', 'en', True, 'test.srt')
        self.assertEqual(video.newsubtitlelanguage_set.count(), 2)
Пример #8
0
    def test_upload_unsynced_subs(self):
        video = get_video()
        self._upload(video, 'en', 'en', None, True, 'subs-with-unsynced.srt')
        self._assertCounts(video, {'en': 1})

        subs = video.subtitle_language('en').get_tip().get_subtitles()

        fully_synced = len([1 for start, end, _, _ in subs if start and end])
        synced_begin = len([1 for start, _, _, _ in subs if start])
        synced_end = len([1 for _, end, _, _ in subs if end])
        fully_unsynced = len([1 for start, end, _, _ in subs
                              if (not start) and (not end)])
        
        self.assertEqual(fully_synced, 56)
        self.assertEqual(synced_begin, 57)
        self.assertEqual(synced_end, 56)
        self.assertEqual(fully_unsynced, 5)
Пример #9
0
    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)
Пример #10
0
    def test_upload_translation(self):
        video = get_video()
        self._assertVersionCount(video, 0)

        # Try uploading a translation of language that doesn't exist.
        self._upload(video, 'fr', 'en', 'en', True, 'test.srt')

        # This should fail.  Translations need to be based on an existing
        # langauge.
        self._assertVersionCount(video, 0)

        # Let's upload the first language.
        self._upload(video, 'en', 'en', None, True, 'test.srt')
        self._assertVersionCount(video, 1)

        # And now uploading a translation should work.
        self._upload(video, 'fr', 'en', 'en', True, 'test.srt')
        self._assertVersionCount(video, 2)

        # Translations of translations are okay too I guess.
        self._upload(video, 'ru', 'en', 'fr', True, 'test.srt')
        self._assertVersionCount(video, 3)
Пример #11
0
    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)
Пример #12
0
    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!')
Пример #13
0
 def test_language_url_for_empty_lang(self):
     v = get_video(1)
     sl = make_subtitle_language(v, 'en')
     self.assertIsNotNone(language_url(None, sl))