Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def setUp(self):
        handle_cwd()

        # sample content
        content = '[{"links": [{"filename": null, "status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
        self.filename = 'test.ploader'
        with open(self.filename, 'w') as fd:
            fd.write(content)

        self.link_loader = LinkLoader(self.filename)
        self.link_loader.settings["multithreading"] = True
Exemplo n.º 4
0
    def setUp(self):
        self.maxDiff = None

        handle_cwd()

        # sample content
        content = '[{"links": [{"status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
        self.filename = 'test.ploader'
        with open(self.filename, 'w') as fd:
            fd.write(content)

        self.link_loader = LinkLoader(self.filename)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
	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)
Exemplo n.º 7
0
	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)
Exemplo n.º 8
0
	def setUp(self):
		handle_cwd()

		# sample content
		content = '[{"links": [{"filename": null, "status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
		self.filename = 'test.ploader'
		with open(self.filename, 'w') as fd:
			fd.write(content)

		self.link_loader = LinkLoader(self.filename)
		self.link_loader.settings["multithreading"] = True
Exemplo n.º 9
0
	def setUp(self):
		self.maxDiff = None

		handle_cwd()

		# sample content
		content = '[{"links": [{"status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
		self.filename = 'test.ploader'
		with open(self.filename, 'w') as fd:
			fd.write(content)

		self.link_loader = LinkLoader(self.filename)
Exemplo n.º 10
0
class TestMultithreading(TestCase):
	def setUp(self):
		handle_cwd()

		# sample content
		content = '[{"links": [{"filename": null, "status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
		self.filename = 'test.ploader'
		with open(self.filename, 'w') as fd:
			fd.write(content)

		self.link_loader = LinkLoader(self.filename)
		self.link_loader.settings["multithreading"] = True

	def tearDown(self):
		os.remove(self.filename)
		shutil.rmtree('downloads')

	def test_multithreading(self):
		self.link_loader.try_download()

		self.assertEqual(threading.active_count(), 2) # not 3 since there is no running server
Exemplo n.º 11
0
class TestLinkLoaderNonexistentPloaderFile(TestCase):
	def setUp(self):
		handle_cwd()

		self.filename = 'nonexistent.ploader'

		self.link_loader = LinkLoader(self.filename)

	def tearDown(self):
		os.remove(self.filename)

	def test_local_data_parser(self):
		# on empty file
		self.assertEqual(self.link_loader.data, [])

	def test_append_download(self):
		# TODO: little hack to reduce amount of work
		self.link_loader.append_download(Download('42', []))
		self.assertEqual(len(self.link_loader.data), 1)

		self.link_loader.append_download([Download('42', [])])
		self.assertEqual(len(self.link_loader.data), 2)

		self.link_loader.append_download([Download('23', []), Download('42', [])])
		self.assertEqual(len(self.link_loader.data), 4)
Exemplo n.º 12
0
class TestLinkLoaderNonexistentPloaderFile(TestCase):
    def setUp(self):
        handle_cwd()

        self.filename = 'nonexistent.ploader'

        self.link_loader = LinkLoader(self.filename)

    def tearDown(self):
        os.remove(self.filename)

    def test_local_data_parser(self):
        # on empty file
        self.assertEqual(self.link_loader.data, [])

    def test_append_download(self):
        # TODO: little hack to reduce amount of work
        self.link_loader.append_download(Download('42', []))
        self.assertEqual(len(self.link_loader.data), 1)

        self.link_loader.append_download([Download('42', [])])
        self.assertEqual(len(self.link_loader.data), 2)

        self.link_loader.append_download(
            [Download('23', []), Download('42', [])])
        self.assertEqual(len(self.link_loader.data), 4)
Exemplo n.º 13
0
class TestMultithreading(TestCase):
    def setUp(self):
        handle_cwd()

        # sample content
        content = '[{"links": [{"filename": null, "status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
        self.filename = 'test.ploader'
        with open(self.filename, 'w') as fd:
            fd.write(content)

        self.link_loader = LinkLoader(self.filename)
        self.link_loader.settings["multithreading"] = True

    def tearDown(self):
        os.remove(self.filename)
        shutil.rmtree('downloads')

    def test_multithreading(self):
        self.link_loader.try_download()

        self.assertEqual(threading.active_count(),
                         2)  # not 3 since there is no running server
Exemplo n.º 14
0
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
		)
Exemplo n.º 15
0
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'])
Exemplo n.º 16
0
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'])
Exemplo n.º 17
0
class TestLinkLoader(TestCase):
	def setUp(self):
		self.maxDiff = None

		handle_cwd()

		# sample content
		content = '[{"links": [{"status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
		self.filename = 'test.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_local_data_parser(self):
		# on existing file
		for download in self.link_loader.data:
			self.assertEqual(download.name, 'foo')
			self.assertEqual(download.passwd, 'bar')

			for link in download.links:
				self.assertEqual(link['link'], 'http://path.to.file/my_file.rar')

	def test_create_download(self):
		self.link_loader.create_download('bla', ['http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi'], 'blub')

		download = self.link_loader.data[0]
		self.assertEqual(download.name, 'foo')
		self.assertEqual(download.passwd, 'bar')
		for link in download.links:
			self.assertEqual(link['link'], 'http://path.to.file/my_file.rar')

		download = self.link_loader.data[1]
		self.assertEqual(download.name, 'bla')
		self.assertEqual(download.passwd, 'blub')
		link = download.links[0]
		self.assertEqual(link['link'], 'http://foo.bar.baz/other_stuff.avi')
		link = download.links[1]
		self.assertEqual(link['link'], 'http://foo.bar.baz/other_stuff2.avi')

	def test_link_list_parser(self):
		# must be converted
		link_list = ['http://foo.bar.baz', 'http://www.google.com/']
		links = self.link_loader.parse_link_list(link_list)

		entry = links[0]
		self.assertEqual(entry['link'], 'http://foo.bar.baz')
		self.assertEqual(entry['status'], 'not started')
		self.assertIsNone(entry['filename'])

		entry = links[1]
		self.assertEqual(entry['link'], 'http://www.google.com/')
		self.assertEqual(entry['status'], 'not started')
		self.assertIsNone(entry['filename'])

		# no links available
		link_list = []
		links = self.link_loader.parse_link_list(link_list)

		self.assertEqual(links, [])

		# must not be converted
		link_list = [{'link': 'http://foo.bar.baz', 'status': 'not started', 'filename': None}]
		links = self.link_loader.parse_link_list(link_list)

		self.assertEqual(link_list, links)

	def test_save_data(self):
		self.link_loader.create_download('bla', ['http://foo.bar.baz/other_stuff.avi', 'http://foo.bar.baz/other_stuff2.avi'], 'blub')

		with open(self.filename, 'r') as fd:
			content = json.loads(fd.read())

		self.assertEqual(content, json.loads('[{"name": "foo", "links": [{"link": "http://path.to.file/my_file.rar", "status": "not started"}], "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"}]'))
Exemplo n.º 18
0
class TestLinkLoader(TestCase):
    def setUp(self):
        self.maxDiff = None

        handle_cwd()

        # sample content
        content = '[{"links": [{"status": "not started", "link": "http://path.to.file/my_file.rar"}], "name": "foo", "passwd": "bar"}]'
        self.filename = 'test.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_local_data_parser(self):
        # on existing file
        for download in self.link_loader.data:
            self.assertEqual(download.name, 'foo')
            self.assertEqual(download.passwd, 'bar')

            for link in download.links:
                self.assertEqual(link['link'],
                                 'http://path.to.file/my_file.rar')

    def test_create_download(self):
        self.link_loader.create_download('bla', [
            'http://foo.bar.baz/other_stuff.avi',
            'http://foo.bar.baz/other_stuff2.avi'
        ], 'blub')

        download = self.link_loader.data[0]
        self.assertEqual(download.name, 'foo')
        self.assertEqual(download.passwd, 'bar')
        for link in download.links:
            self.assertEqual(link['link'], 'http://path.to.file/my_file.rar')

        download = self.link_loader.data[1]
        self.assertEqual(download.name, 'bla')
        self.assertEqual(download.passwd, 'blub')
        link = download.links[0]
        self.assertEqual(link['link'], 'http://foo.bar.baz/other_stuff.avi')
        link = download.links[1]
        self.assertEqual(link['link'], 'http://foo.bar.baz/other_stuff2.avi')

    def test_link_list_parser(self):
        # must be converted
        link_list = ['http://foo.bar.baz', 'http://www.google.com/']
        links = self.link_loader.parse_link_list(link_list)

        entry = links[0]
        self.assertEqual(entry['link'], 'http://foo.bar.baz')
        self.assertEqual(entry['status'], 'not started')
        self.assertIsNone(entry['filename'])

        entry = links[1]
        self.assertEqual(entry['link'], 'http://www.google.com/')
        self.assertEqual(entry['status'], 'not started')
        self.assertIsNone(entry['filename'])

        # no links available
        link_list = []
        links = self.link_loader.parse_link_list(link_list)

        self.assertEqual(links, [])

        # must not be converted
        link_list = [{
            'link': 'http://foo.bar.baz',
            'status': 'not started',
            'filename': None
        }]
        links = self.link_loader.parse_link_list(link_list)

        self.assertEqual(link_list, links)

    def test_save_data(self):
        self.link_loader.create_download('bla', [
            'http://foo.bar.baz/other_stuff.avi',
            'http://foo.bar.baz/other_stuff2.avi'
        ], 'blub')

        with open(self.filename, 'r') as fd:
            content = json.loads(fd.read())

        self.assertEqual(
            content,
            json.loads(
                '[{"name": "foo", "links": [{"link": "http://path.to.file/my_file.rar", "status": "not started"}], "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"}]'
            ))
Exemplo n.º 19
0
    def setUp(self):
        handle_cwd()

        self.filename = 'nonexistent.ploader'

        self.link_loader = LinkLoader(self.filename)
Exemplo n.º 20
0
	def setUp(self):
		handle_cwd()

		self.filename = 'nonexistent.ploader'

		self.link_loader = LinkLoader(self.filename)