Example #1
0
 def _get_version(v):
     return pipeline._get_version(self.video, v)
Example #2
0
    def test_get_version(self):
        def _assert_eq(a, b):
            if (not a) or (not b):
                self.assertTrue((not a) and (not b))
            else:
                self.assertEqual(a.id, b.id)

        def _assert_notfound(l):
            self.assertRaises(SubtitleVersion.DoesNotExist, l)

        def _assert_badtype(l):
            self.assertRaises(ValueError, l)

        def _get_version(v):
            return pipeline._get_version(self.video, v)

        en = SubtitleLanguage.objects.create(video=self.video,
                                             language_code='en')
        fr = SubtitleLanguage.objects.create(video=self.video,
                                             language_code='fr')

        en1 = en.add_version()
        en2 = en.add_version()
        en3 = en.add_version()

        fr1 = fr.add_version()
        fr2 = fr.add_version()
        fr3 = fr.add_version()

        # Test passthrough.
        _assert_eq(en1, _get_version(en1))
        _assert_eq(en2, _get_version(en2))
        _assert_eq(en3, _get_version(en3))
        _assert_eq(fr1, _get_version(fr1))
        _assert_eq(fr2, _get_version(fr2))
        _assert_eq(fr3, _get_version(fr3))

        # Test version IDs (integers).
        _assert_eq(en1, _get_version(en1.id))
        _assert_eq(en2, _get_version(en2.id))
        _assert_eq(en3, _get_version(en3.id))
        _assert_eq(fr1, _get_version(fr1.id))
        _assert_eq(fr2, _get_version(fr2.id))
        _assert_eq(fr3, _get_version(fr3.id))

        # Test language_code, version_number pairs.
        _assert_eq(fr1, _get_version(('fr', 1)))
        _assert_eq(fr2, _get_version(('fr', 2)))
        _assert_eq(fr3, _get_version(('fr', 3)))
        _assert_eq(en1, _get_version(['en', 1]))
        _assert_eq(en2, _get_version(['en', 2]))
        _assert_eq(en3, _get_version(['en', 3]))

        # Test mismatching passthrough.
        _assert_notfound(lambda: pipeline._get_version(self.video2, en1))
        _assert_notfound(lambda: pipeline._get_version(self.video2, fr3))

        # Test bad version ID.
        _assert_notfound(lambda: _get_version(424242))

        # Test bad language_code, version_number pair.
        _assert_notfound(lambda: _get_version(('fr', 0)))
        _assert_notfound(lambda: _get_version(('fr', 4)))
        _assert_notfound(lambda: _get_version(('cats', 1)))

        # Test entirely invalid types.
        _assert_badtype(lambda: _get_version(u'squirrel'))
        _assert_badtype(lambda: _get_version(1.2))