def test_fake_url(self): """ Imposter gfycat URLs should fail """ _task, _prog, _file = mock_handler_request( self.dir, 'https://gfycat.com.fake.com/ripemadintermediateegret') res = gfycat.handle(_task, _prog) self.assertIs(res, False, "Invalid response after failed download!") self.assertFalse(_file.exists(), "A file was created for an invalid URL!")
def test_missing_id(self): """ Gfycat URLs missing UIDs should fail """ _task, _prog, _file = mock_handler_request(self.dir, 'https://gfycat.com/') res = gfycat.handle(_task, _prog) self.assertIs(res, False, "Invalid response after failed download!") self.assertFalse(_file.exists(), "A file was created for an invalid URL!")
def test_text_post(self): """ Test invalid post parsing """ _task, _prog, _file = mock_handler_request( self.dir, 'http://theshadowmoose.tumblr.com/post/184562766360/test-text-post-rmd' ) res = tumblr.handle(_task, _prog) self.assertFalse(res, "Tumblr downloaded something from a text post!") self.assertFalse(_file.exists(), "Tumblr downloaded a file from a text post!")
def test_non_media(self): """ Links to non-media should be skipped """ _task, _prog, _file = mock_handler_request( self.dir, 'https://raw.githubusercontent.com/shadowmoose/RedditDownloader/master/README.md' ) res = direct_link.handle(_task, _prog) self.assertFalse(res, "A non-media file was not skipped!") self.assertFalse(_file.exists(), "A file was created for an invalid URL!")
def test_direct_reddit(self): """ Simple direct link download """ _task, _prog, _file = mock_handler_request( self.dir, 'https://gfycat.com/heftyinnocentelephantbeetle') res = gfycat.handle(_task, _prog) self.assertTrue(res, "gfycat webm download failed!") self.assertTrue( _file.exists(), "gfycat webm was not downloaded! %s" % res.failure_reason) self.assertIn('.webm', _file.relative(), "gfycat webm is missing extension!")
def test_gallery(self): """ Attempt Imgur gallery Download """ _task, _prog, _file = mock_handler_request( self.dir, 'https://theshadowmoose.tumblr.com/post/184562233420/test-rmd-image-upload' ) res = tumblr.handle(_task, _prog) self.assertTrue( res, "Tumblr gallery search failed! %s" % res.failure_reason) self.assertEqual(len(res.album_urls), 2, "Handler didn't find all gallery URLS!")
def test_direct_reddit(self): """ Simple direct image download """ _task, _prog, _file = mock_handler_request( self.dir, 'https://i.redd.it/lasm5nl33o4x.png') res = direct_link.handle(_task, _prog) self.assertTrue(res, "redd.it png download failed!") self.assertTrue( _file.exists(), "redd.it png was not downloaded! %s" % res.failure_reason) self.assertIn('.png', _file.relative(), "redd.it png is missing extension!")
def test_404_download(self): """ Invalid URLs should fail """ _task, _prog, _file = mock_handler_request( self.dir, 'https://i.redd.it/lasm5nl33o4asdfx.png') res = direct_link.handle(_task, _prog) self.assertTrue(res, "Invalid response after failed download!") self.assertFalse(_file.exists(), "A file was created for an invalid URL!") self.assertFalse(res.success, "This invalid URL was supposed to fail!") self.assertIn('404', res.failure_reason, "The handler did not include the HTTP error code!")
def test_decorated(self): """ A Gfycat link with extra social string should work """ _task, _prog, _file = mock_handler_request( self.dir, 'https://gfycat.com/ripemadintermediateegret-hi-bye-sad-nba') res = gfycat.handle(_task, _prog) self.assertTrue(res, "gfycat webm download failed!") self.assertTrue( _file.exists(), "gfycat webm was not downloaded! %s" % res.failure_reason) self.assertIn('.webm', _file.relative(), "gfycat webm is missing extension!")
def test_direct_url(self): """ Direct gfycat URLs should work """ _task, _prog, _file = mock_handler_request( self.dir, 'https://zippy.gfycat.com/DampAltruisticGangesdolphin.webm') res = gfycat.handle(_task, _prog) self.assertTrue(res, "gfycat webm download failed!") self.assertTrue( _file.exists(), "gfycat webm was not downloaded! %s" % res.failure_reason) self.assertIn('.webm', _file.relative(), "gfycat webm is missing extension!")
def test_video(self): """ Test embedded video download """ _task, _prog, _file = mock_handler_request( self.dir, 'theshadowmoose.tumblr.com/post/184562318724/another-test-post-with-video' ) res = tumblr.handle(_task, _prog) self.assertTrue(res, "Tumblr video download failed!") self.assertTrue( _file.exists(), "Tumblr video was not downloaded! %s" % res.failure_reason) self.assertTrue(_file.relative().endswith('.mp4'), 'Failed to use .mp4 extension for video file!')