Esempio n. 1
0
 def test_download_unavailable(self):
     """
     Tests that a non-existent video doesn't result in any new files
     """
     with self.assertRaises(HTTPError):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 2
0
 def test_download_unavailable(self):
     """
     Tests that a non-existent video doesn't result in any new files
     """
     with self.assertRaises(HTTPError):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 3
0
    def test_500_download(self, get_thumbnail_url, get_video_url):
        get_thumbnail_url.return_value = "http://httpstat.us/500"
        get_video_url.return_value = "http://httpstat.us/500"

        with self.assertRaises(HTTPError):
            download_video(self.real_video.youtube_id)

        self.assertFalse(
            os.path.exists(get_video_local_path(self.real_video.youtube_id)))
Esempio n. 4
0
 def test_500_download(self, get_thumbnail_url, get_video_url):
     get_thumbnail_url.return_value = "http://httpstat.us/500"
     get_video_url.return_value = "http://httpstat.us/500"
     
     with self.assertRaises(HTTPError):
         download_video(self.real_video.youtube_id)
     
     self.assertFalse(os.path.exists(
         get_video_local_path(self.real_video.youtube_id)
     ))
Esempio n. 5
0
 def test_connection_error(self, requests_get):
     """
     Tests that a mocked connection error makes the download fail
     """
     requests_get.side_effect = ConnectionError
     with self.assertRaises(ConnectionError):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 6
0
 def test_socket_error(self, requests_get):
     """
     Tests that a mocked socket error makes the download fail
     """
     requests_get.side_effect = socket.timeout
     with self.assertRaises(socket.timeout):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 7
0
 def test_connection_error(self, requests_get):
     """
     Tests that a mocked connection error makes the download fail
     """
     requests_get.side_effect = ConnectionError
     with self.assertRaises(ConnectionError):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 8
0
 def test_socket_error(self, requests_get):
     """
     Tests that a mocked socket error makes the download fail
     """
     requests_get.side_effect = socket.timeout
     with self.assertRaises(socket.timeout):
         download_video(self.content_unavailable_item.youtube_id)
     self.assertFalse(os.path.exists(
         get_video_local_path(self.content_unavailable_item.youtube_id)
     ))
Esempio n. 9
0
    def test_simple_download(self):
        """
        Tests that a real, existing video can be downloaded
        """
        # Download a video that exists for real!
        download_video(self.real_video.youtube_id)
        # Check that file exists
        self.assertTrue(
            os.path.exists(get_video_local_path(self.real_video.youtube_id)))
        # After downloading the video, annotate the database
        annotate_content_models_by_youtube_id(
            youtube_ids=[self.real_video.youtube_id])
        # Check that it's been marked available
        updated = get_content_item(content_id=self.real_video.id)
        logger.error(updated)
        self.assertTrue(updated['available'])

        # Adding in an unrelated test (becase we don't need database etc. for
        # this to be tested.
        self.assertEqual(get_local_video_size("/bogus/path", default=123), 123)
Esempio n. 10
0
    def test_simple_download(self):
        """
        Tests that a real, existing video can be downloaded
        """
        # Download a video that exists for real!
        download_video(self.real_video.youtube_id)
        # Check that file exists
        self.assertTrue(os.path.exists(
            get_video_local_path(self.real_video.youtube_id)
        ))
        # After downloading the video, annotate the database
        annotate_content_models_by_youtube_id(youtube_ids=[self.real_video.youtube_id])
        # Check that it's been marked available
        updated = get_content_item(content_id=self.real_video.id)
        logger.error(updated)
        self.assertTrue(updated['available'])

        # Adding in an unrelated test (becase we don't need database etc. for
        # this to be tested.
        self.assertEqual(
            get_local_video_size("/bogus/path", default=123),
            123
        )