class TestDownloadStateful(TestCase): def setUp(self): handle_cwd() self.port = 9888 self.httpd = create_http_server(self.port) self.filename = 'nonexistent.ploader' self.link_loader = LinkLoader(self.filename) def tearDown(self): self.httpd.shutdown() os.remove(self.filename) def test_download_unrar_nopw(self): self.link_loader.create_download( 'NoPasswordNeeded', ['http://localhost:' + str(self.port) + '/NoPasswd.rar']) dw = self.link_loader.get_unstarted_download() # download dw.download() # unrar dw.unpack() self.assertCountEqual(os.listdir('downloads/NoPasswordNeeded'), ['NoPasswd.rar', 'happy.file', 'logs']) def test_download_unrar_withpw(self): self.link_loader.create_download( 'IndeedPasswordNeeded', ['http://localhost:' + str(self.port) + '/WithPasswd.rar'], 'supersecret') dw = self.link_loader.get_unstarted_download() # download dw.download() # unrar dw.unpack() self.assertCountEqual(os.listdir('downloads/IndeedPasswordNeeded'), ['WithPasswd.rar', 'unhappy.file', 'logs'])
class TestDownloadStateful(TestCase): def setUp(self): handle_cwd() self.port = 9888 self.httpd = create_http_server(self.port) self.filename = 'nonexistent.ploader' self.link_loader = LinkLoader(self.filename) def tearDown(self): self.httpd.shutdown() os.remove(self.filename) def test_download_unrar_nopw(self): self.link_loader.create_download( 'NoPasswordNeeded', ['http://localhost:' + str(self.port) + '/NoPasswd.rar'] ) dw = self.link_loader.get_unstarted_download() # download dw.download() # unrar dw.unpack() self.assertCountEqual(os.listdir('downloads/NoPasswordNeeded'), ['NoPasswd.rar', 'happy.file', 'logs']) def test_download_unrar_withpw(self): self.link_loader.create_download( 'IndeedPasswordNeeded', ['http://localhost:' + str(self.port) + '/WithPasswd.rar'], 'supersecret' ) dw = self.link_loader.get_unstarted_download() # download dw.download() # unrar dw.unpack() self.assertCountEqual(os.listdir('downloads/IndeedPasswordNeeded'), ['WithPasswd.rar', 'unhappy.file', 'logs'])
class TestLinkLoaderSpecialPloaderFile(TestCase): def setUp(self): handle_cwd() # sample content content = '[{"name": "foo", "links": [{"link": "http://path.to.file/my_file.rar", "status": "success"}], "passwd": "bar"}, {"name": "bla", "links": [{"link": "http://foo.bar.baz/other_stuff.avi", "filename": null, "status": "not started"}, {"link": "http://foo.bar.baz/other_stuff2.avi", "filename": null, "status": "not started"}], "passwd": "blub"}]' self.filename = 'special.ploader' with open(self.filename, 'w') as fd: fd.write(content) self.link_loader = LinkLoader(self.filename) def tearDown(self): os.remove(self.filename) shutil.rmtree('downloads') def test_get_unstarted_download(self): sample_dw = Download('bla', [{ "link": "http://foo.bar.baz/other_stuff.avi", "filename": "", "status": "not started" }, { "link": "http://foo.bar.baz/other_stuff2.avi", "filename": "", "status": "not started" }], 'blub') # TODO: find better way to compare objects self.assertEqual(repr(self.link_loader.get_unstarted_download()), repr(sample_dw)) def test_get_unstarted_downloads(self): # add two downloads to queue containing one already existing download self.link_loader.create_download('bla', [ 'http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi' ], 'blub') self.link_loader.create_download('bla', [ 'http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi' ], 'blub') # acquire all three of them self.link_loader.get_unstarted_download() self.link_loader.get_unstarted_download() self.link_loader.get_unstarted_download() # don't find them anymore self.assertEqual(self.link_loader.get_unstarted_download(), None)
class TestLinkLoaderSpecialPloaderFile(TestCase): def setUp(self): handle_cwd() # sample content content = '[{"name": "foo", "links": [{"link": "http://path.to.file/my_file.rar", "status": "success"}], "passwd": "bar"}, {"name": "bla", "links": [{"link": "http://foo.bar.baz/other_stuff.avi", "filename": null, "status": "not started"}, {"link": "http://foo.bar.baz/other_stuff2.avi", "filename": null, "status": "not started"}], "passwd": "blub"}]' self.filename = 'special.ploader' with open(self.filename, 'w') as fd: fd.write(content) self.link_loader = LinkLoader(self.filename) def tearDown(self): os.remove(self.filename) shutil.rmtree('downloads') def test_get_unstarted_download(self): sample_dw = Download( 'bla', [{"link": "http://foo.bar.baz/other_stuff.avi", "filename": "", "status": "not started"}, {"link": "http://foo.bar.baz/other_stuff2.avi", "filename": "", "status": "not started"}], 'blub' ) # TODO: find better way to compare objects self.assertEqual( repr(self.link_loader.get_unstarted_download()), repr(sample_dw) ) def test_get_unstarted_downloads(self): # add two downloads to queue containing one already existing download self.link_loader.create_download('bla', ['http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi'], 'blub') self.link_loader.create_download('bla', ['http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi'], 'blub') # acquire all three of them self.link_loader.get_unstarted_download() self.link_loader.get_unstarted_download() self.link_loader.get_unstarted_download() # don't find them anymore self.assertEqual( self.link_loader.get_unstarted_download(), None )