Esempio n. 1
0
    def test_assume_utf8_encoded_content(self):
        # Universal Subtitles API returns utf-8
        # u'\xc4\xd0' is unicode for the utf-8 byte string '\xc3\x84\xc3\x90'
        utf8_str = '\xc3\x84\xc3\x90'
        unicode_str = u'\xc4\xd0'

        self._set_responses_xrange(1, content=utf8_str)

        _task_handler('UUID')
        self.assertEqual(VideoSubtitles.all().count(), 1)
        subs = VideoSubtitles.all().get()
        self.assertEqual(subs.json, unicode_str)
Esempio n. 2
0
    def test_assume_utf8_encoded_content(self):
        # Universal Subtitles API returns utf-8
        # u'\xc4\xd0' is unicode for the utf-8 byte string '\xc3\x84\xc3\x90'
        utf8_str = '\xc3\x84\xc3\x90'
        unicode_str = u'\xc4\xd0'

        self._set_responses_xrange(1, content=utf8_str)

        _task_handler('UUID')
        self.assertEqual(VideoSubtitles.all().count(), 1)
        subs = VideoSubtitles.all().get()
        self.assertEqual(subs.json, unicode_str)
Esempio n. 3
0
    def test_process_next_batch_on_nonempty_cursor(self):
        offset = 3

        # these should be skipped, they'll DownloadError
        for i in xrange(0, offset):
            Video(youtube_id=str(i)).put()

        # these should be downloaded
        self._set_responses_xrange(offset, BATCH_SIZE + offset)

        query = Video.all()
        query.fetch(offset)
        cursor = query.cursor()

        _task_handler('UUID', cursor=cursor)
        self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)
Esempio n. 4
0
    def test_process_next_batch_on_nonempty_cursor(self):
        offset = 3

        # these should be skipped, they'll DownloadError
        for i in xrange(0, offset):
            Video(youtube_id=str(i)).put()

        # these should be downloaded
        self._set_responses_xrange(offset, BATCH_SIZE + offset)

        query = Video.all()
        query.fetch(offset)
        cursor = query.cursor()

        _task_handler('UUID', cursor=cursor)
        self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)
Esempio n. 5
0
    def test_should_not_put_duplicate_subtitles(self, info):
        self._set_responses_xrange(BATCH_SIZE, content="some json")

        # first fetch
        _task_handler('UUID', 0)
        self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)
        self.assertEqual(info.call_count, 0)

        with patch('unisubs.VideoSubtitles') as MockVideoSubtitles:
            MockVideoSubtitles.get_key_name = VideoSubtitles.get_key_name
            MockVideoSubtitles.get_by_key_name = VideoSubtitles.get_by_key_name
            # second fetch, same content
            _task_handler('UUID', 1)
            self.assertEqual(MockVideoSubtitles.return_value.put.call_count, 0,
                             'duplicate subtitles should not be put()')
            self.assertEqual(info.call_count, BATCH_SIZE,
                             'skipped put should be logged')
Esempio n. 6
0
    def test_should_not_put_duplicate_subtitles(self, info):
        self._set_responses_xrange(BATCH_SIZE, content="some json")

        # first fetch
        _task_handler('UUID', 0)
        self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)
        self.assertEqual(info.call_count, 0)

        with patch('unisubs.VideoSubtitles') as MockVideoSubtitles:
            MockVideoSubtitles.get_key_name = VideoSubtitles.get_key_name
            MockVideoSubtitles.get_by_key_name = VideoSubtitles.get_by_key_name
            # second fetch, same content
            _task_handler('UUID', 1)
            self.assertEqual(MockVideoSubtitles.return_value.put.call_count, 0,
                             'duplicate subtitles should not be put()')
            self.assertEqual(info.call_count, BATCH_SIZE,
                             'skipped put should be logged')
Esempio n. 7
0
 def test_process_first_batch_on_empty_cursor(self):
     self._set_responses_xrange(BATCH_SIZE)
     _task_handler('UUID')
     self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)
Esempio n. 8
0
 def test_process_first_batch_on_empty_cursor(self):
     self._set_responses_xrange(BATCH_SIZE)
     _task_handler('UUID')
     self.assertEqual(VideoSubtitles.all().count(), BATCH_SIZE)