def test_youtube_video_thumbnail_download(
        self,
        thumbnail_content_data,
        expected_thumbnail_content,
        mocked_request
    ):
        """
        Test that we get highest resolution video thumbnail available from youtube.
        """
        # Mock get youtube thumbnail responses.
        def mocked_youtube_thumbnail_responses(resolutions):
            """
            Returns a list of mocked responses containing youtube thumbnails.
            """
            mocked_responses = []
            for resolution in YOUTUBE_THUMBNAIL_SIZES:
                mocked_content = resolutions.get(resolution, '')
                error_response = False if mocked_content else True
                mocked_responses.append(self.mocked_youtube_thumbnail_response(mocked_content, error_response))
            return mocked_responses

        mocked_request.side_effect = mocked_youtube_thumbnail_responses(thumbnail_content_data)

        thumbnail_content, thumbnail_content_type = download_youtube_video_thumbnail('test-yt-id')

        # Verify that we get the expected thumbnail content.
        self.assertEqual(thumbnail_content, expected_thumbnail_content)
        self.assertEqual(thumbnail_content_type, 'image/jpeg')
Example #2
0
    def test_youtube_video_thumbnail_download(self, thumbnail_content_data,
                                              expected_thumbnail_content,
                                              mocked_request):
        """
        Test that we get highest resolution video thumbnail available from youtube.
        """

        # Mock get youtube thumbnail responses.
        def mocked_youtube_thumbnail_responses(resolutions):
            """
            Returns a list of mocked responses containing youtube thumbnails.
            """
            mocked_responses = []
            for resolution in YOUTUBE_THUMBNAIL_SIZES:
                mocked_content = resolutions.get(resolution, '')
                error_response = False if mocked_content else True
                mocked_responses.append(
                    self.mocked_youtube_thumbnail_response(
                        mocked_content, error_response))
            return mocked_responses

        mocked_request.side_effect = mocked_youtube_thumbnail_responses(
            thumbnail_content_data)

        thumbnail_content, thumbnail_content_type = download_youtube_video_thumbnail(
            'test-yt-id')

        # Verify that we get the expected thumbnail content.
        self.assertEqual(thumbnail_content, expected_thumbnail_content)
        self.assertEqual(thumbnail_content_type, 'image/jpeg')