diff options
-rw-r--r-- | module/common/APIExerciser.py | 4 | ||||
-rw-r--r-- | module/network/HTTPRequest.py | 15 | ||||
-rw-r--r-- | module/plugins/Hoster.py | 1 | ||||
-rw-r--r-- | module/web/api_app.py | 4 | ||||
-rw-r--r-- | tests/CrypterPluginTester.py | 6 | ||||
-rw-r--r-- | tests/HosterPluginTester.py | 3 | ||||
-rwxr-xr-x | tests/clonedigger.sh | 2 | ||||
-rw-r--r-- | tests/config/db.version | 1 | ||||
-rw-r--r-- | tests/config/plugin.conf | 138 | ||||
-rw-r--r-- | tests/config/pyload.conf.org | 75 | ||||
-rw-r--r-- | tests/config/pyload.db.org | bin | 0 -> 13312 bytes | |||
-rwxr-xr-x | tests/nosetests.sh | 5 | ||||
-rwxr-xr-x | tests/pyflakes.sh | 2 | ||||
-rwxr-xr-x | tests/quit_pyload.sh | 4 | ||||
-rwxr-xr-x | tests/run_pyload.sh | 17 | ||||
-rwxr-xr-x | tests/sloccount.sh | 2 | ||||
-rw-r--r-- | tests/stubs/__init__.py | 1 | ||||
-rw-r--r-- | tests/test_api.py | 8 | ||||
-rw-r--r-- | tests/test_json.py | 5 | ||||
-rw-r--r-- | tests/test_syntax.py | 45 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/testlinks.txt (renamed from testlinks.txt) | 0 |
21 files changed, 319 insertions, 19 deletions
diff --git a/module/common/APIExerciser.py b/module/common/APIExerciser.py index 96f5ce9cf..657e83c78 100644 --- a/module/common/APIExerciser.py +++ b/module/common/APIExerciser.py @@ -114,7 +114,7 @@ class APIExerciser(Thread): name = "".join(sample(string.ascii_letters, 10)) urls = createURLs() - self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector])) + self.api.addPackage(name, urls, choice([Destination.Queue, Destination.Collector]), "") def deleteFiles(self): @@ -154,4 +154,4 @@ class APIExerciser(Thread): self.api.getAccounts(False) def getCaptchaTask(self): - self.api.getCaptchaTask(False)
\ No newline at end of file + self.api.getCaptchaTask(False) diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index 8d65b025f..4684397d9 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -39,7 +39,7 @@ bad_headers = range(400, 404) + range(405, 418) + range(500, 506) class BadHeader(Exception): def __init__(self, code, content=""): - Exception.__init__(self, "Bad server response: %s %s" % (code, responses[int(code)])) + Exception.__init__(self, "Bad server response: %s %s" % (code, responses.get(int(code), "Unknown Header"))) self.code = code self.content = content @@ -200,12 +200,13 @@ class HTTPRequest(): else: self.c.setopt(pycurl.CUSTOMREQUEST, "GET") - self.c.perform() - rep = self.header - - self.c.setopt(pycurl.FOLLOWLOCATION, 1) - self.c.setopt(pycurl.NOBODY, 0) - self.c.setopt(pycurl.CUSTOMREQUEST, 0) + try: + self.c.perform() + rep = self.header + finally: + self.c.setopt(pycurl.FOLLOWLOCATION, 1) + self.c.setopt(pycurl.NOBODY, 0) + self.c.setopt(pycurl.CUSTOMREQUEST, 0) else: self.c.perform() diff --git a/module/plugins/Hoster.py b/module/plugins/Hoster.py index bef4b1949..7c43c6444 100644 --- a/module/plugins/Hoster.py +++ b/module/plugins/Hoster.py @@ -28,7 +28,6 @@ if os.name != "nt": from grp import getgrnam from Base import Base, Fail, Retry -from module.utils import chunks #legacy import from module.utils.fs import save_join, save_filename, fs_encode, fs_decode,\ remove, makedirs, chmod, stat, exists, join diff --git a/module/web/api_app.py b/module/web/api_app.py index 1629c1677..160a984df 100644 --- a/module/web/api_app.py +++ b/module/web/api_app.py @@ -11,6 +11,7 @@ from utils import toDict, set_session from webinterface import PYLOAD from module.common.json_layer import json +from module.utils import remove_chars from module.lib.SafeEval import const_eval as literal_eval from module.Api import BaseObject @@ -33,7 +34,8 @@ def call_api(func, args=""): s = request.environ.get('beaker.session') if 'session' in request.POST: - s = s.get_by_id(request.POST['session']) + # removes "' so it works on json strings + s = s.get_by_id(remove_chars(request.POST['session'], "'\"")) if not s or not s.get("authenticated", False): return HTTPError(403, json.dumps("Forbidden")) diff --git a/tests/CrypterPluginTester.py b/tests/CrypterPluginTester.py new file mode 100644 index 000000000..124cb4d0a --- /dev/null +++ b/tests/CrypterPluginTester.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase + +class DecryptPluginTester(TestCase): + pass
\ No newline at end of file diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py new file mode 100644 index 000000000..faaaf799c --- /dev/null +++ b/tests/HosterPluginTester.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + + diff --git a/tests/clonedigger.sh b/tests/clonedigger.sh new file mode 100755 index 000000000..69b1c13fa --- /dev/null +++ b/tests/clonedigger.sh @@ -0,0 +1,2 @@ +#!/bin/bash +clonedigger -o cpd.xml --cpd-output --ignore-dir=module/lib . diff --git a/tests/config/db.version b/tests/config/db.version new file mode 100644 index 000000000..bf0d87ab1 --- /dev/null +++ b/tests/config/db.version @@ -0,0 +1 @@ +4
\ No newline at end of file diff --git a/tests/config/plugin.conf b/tests/config/plugin.conf new file mode 100644 index 000000000..5e7ee3858 --- /dev/null +++ b/tests/config/plugin.conf @@ -0,0 +1,138 @@ +version: 2 + +[MultiuploadCom] +preferedHoster = multiupload +ignoredHoster = + +[SerienjunkiesOrg] +preferredHoster = RapidshareCom,UploadedTo,NetloadIn,FilefactoryCom,FreakshareNet,FilebaseTo,MegauploadCom,HotfileCom,DepositfilesCom,EasyshareCom,KickloadCom +changeName = True + +[EmbeduploadCom] +preferedHoster = embedupload +ignoredHoster = + +[MultiloadCz] +usedHoster = +ignoredHoster = + +[WiiReloadedOrg] +changeName = True + +[Xdcc] +nick = pyload +ident = pyloadident +realname = pyloadreal + +[UlozTo] +reuseCaptcha = True +captchaUser = +captchaNb = + +[YoutubeCom] +quality = hd +fmt = 0 +.mp4 = True +.flv = True +.webm = False +.3gp = False + +[RapidshareCom] +server = None + +[VeehdCom] +filename_spaces = False +replacement_char = _ + +[RealdebridCom] +https = False + +[ClickAndLoad] +activated = True +extern = False + +[ExtractArchive] +activated = True +fullpath = True +overwrite = True +passwordfile = unrar_passwords.txt +deletearchive = False +subfolder = False +destination = +queue = True +renice = 0 + +[CaptchaTrader] +activated = True +username = +force = False +passkey = + +[MergeFiles] +activated = False + +[IRCInterface] +activated = False +host = Enter your server here! +port = 6667 +ident = pyload-irc +realname = pyload-irc +nick = pyLoad-IRC +owner = Enter your nick here! +info_file = False +info_pack = True +captcha = True + +[Ev0InFetcher] +activated = False +interval = 10 +queue = False +shows = +quality = xvid +hoster = NetloadIn,RapidshareCom,MegauploadCom,HotfileCom + +[EasybytezCom] +activated = False +includeHoster = +excludeHoster = + +[XMPPInterface] +activated = False +jid = user@exmaple-jabber-server.org +pw = +tls = False +owners = me@icq-gateway.org;some@msn-gateway.org +info_file = False +info_pack = True +captcha = True + +[RehostTo] +activated = False + +[MultiHoster] +activated = True + +[MultiHome] +activated = False +interfaces = None + +[MultishareCz] +activated = False +includeHoster = +excludeHoster = rapidshare.com|uloz.to + +[HotFolder] +activated = False +folder = container +watch_file = False +keep = True +file = links.txt + +[ExternalScripts] +activated = True + +[UpdateManager] +activated = True +interval = 360 +debug = False + diff --git a/tests/config/pyload.conf.org b/tests/config/pyload.conf.org new file mode 100644 index 000000000..7fb1c8c87 --- /dev/null +++ b/tests/config/pyload.conf.org @@ -0,0 +1,75 @@ +version: 2 + +[remote] +nolocalauth = False +activated = True +port = 7227 +listenaddr = 127.0.0.1 + +[log] +log_size = 100 +log_folder = Logs +file_log = False +log_count = 5 +log_rotate = True + +[permission] +group = users +change_dl = False +change_file = False +user = user +file = 0644 +change_group = False +folder = 0755 +change_user = False + +[general] +language = en +download_folder = Downloads +checksum = False +folder_per_package = True +debug_mode = True +min_free_space = 200 +renice = 0 + +[ssl] +cert = ssl.crt +activated = False +key = ssl.key + +[webinterface] +template = default +activated = True +prefix = +server = builtin +host = 127.0.0.1 +https = False +port = 8001 + +[proxy] +username = +proxy = False +address = localhost +password = +type = http +port = 7070 + +[reconnect] +endTime = 0:00 +activated = False +method = ./reconnect.sh +startTime = 0:00 + +[download] +max_downloads = 3 +limit_speed = False +interface = +skip_existing = False +max_speed = -1 +ipv6 = False +chunks = 3 + +[downloadTime] +start = 0:00 +end = 0:00 + diff --git a/tests/config/pyload.db.org b/tests/config/pyload.db.org Binary files differnew file mode 100644 index 000000000..d340531c5 --- /dev/null +++ b/tests/config/pyload.db.org diff --git a/tests/nosetests.sh b/tests/nosetests.sh new file mode 100755 index 000000000..c68861b90 --- /dev/null +++ b/tests/nosetests.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +NS=nosetests +which nosetests2 > /dev/null && NS=nosetests2 +$NS tests/ --with-coverage --with-xunit --cover-package=module --cover-erase +coverage xml diff --git a/tests/pyflakes.sh b/tests/pyflakes.sh new file mode 100755 index 000000000..cdfc11319 --- /dev/null +++ b/tests/pyflakes.sh @@ -0,0 +1,2 @@ +#!/bin/bash +find -name '*.py' |egrep -v '^.(/tests/|/module/lib)'|xargs pyflakes > pyflakes.log || : diff --git a/tests/quit_pyload.sh b/tests/quit_pyload.sh new file mode 100755 index 000000000..a8f81984a --- /dev/null +++ b/tests/quit_pyload.sh @@ -0,0 +1,4 @@ +#!/bin/bash +PYTHON=python +which python2 > /dev/null && PYTHON=python2 +$PYTHON pyLoadCore.py --configdir=tests/config --quit diff --git a/tests/run_pyload.sh b/tests/run_pyload.sh new file mode 100755 index 000000000..66498cd10 --- /dev/null +++ b/tests/run_pyload.sh @@ -0,0 +1,17 @@ +#/usr/bin/env bash +cp tests/config/pyload.db.org tests/config/pyload.db +cp tests/config/pyload.conf.org tests/config/pyload.conf + +PYTHON=python +which python2 > /dev/null && PYTHON=python2 + +touch pyload.out +$PYTHON pyLoadCore.py -d --configdir=tests/config > pyload.out 2> pyload.err & + +for i in {1..30}; do + grep 8001 pyload.out > /dev/null && echo "pyLoad started" && break + sleep 1 +done + +echo "pyLoad start script finished" + diff --git a/tests/sloccount.sh b/tests/sloccount.sh new file mode 100755 index 000000000..98423b4f8 --- /dev/null +++ b/tests/sloccount.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sloccount . --duplicates --wide --details > sloccount.sc diff --git a/tests/stubs/__init__.py b/tests/stubs/__init__.py new file mode 100644 index 000000000..4b31e848b --- /dev/null +++ b/tests/stubs/__init__.py @@ -0,0 +1 @@ +__author__ = 'christian' diff --git a/tests/test_api.py b/tests/test_api.py index f8901f731..76b3e1b40 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -7,14 +7,12 @@ from nose.tools import nottest class TestApi: def __init__(self): - self.api = APIExerciser.APIExerciser(None, True, "TestUser", "pwhere") + self.api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw") def test_login(self): assert self.api.api.login("crapp", "wrong pw") is False - #takes really long, only test when needed - @nottest + #@nottest def test_random(self): - - for i in range(0, 100): + for i in range(0, 1000): self.api.testAPI() diff --git a/tests/test_json.py b/tests/test_json.py index ff56e8f5a..4e8fb0e1f 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -5,7 +5,6 @@ from urllib2 import urlopen, HTTPError from json import loads from logging import log - url = "http://localhost:8001/api/%s" class TestJson: @@ -17,7 +16,7 @@ class TestJson: return loads(u.read()) def setUp(self): - u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "pwhere"})) + u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"})) self.key = loads(u.read()) assert self.key is not False @@ -45,4 +44,4 @@ class TestJson: except HTTPError, e: assert e.code == 404 else: - assert False
\ No newline at end of file + assert False diff --git a/tests/test_syntax.py b/tests/test_syntax.py new file mode 100644 index 000000000..82c4194da --- /dev/null +++ b/tests/test_syntax.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import __builtin__ +from os import walk +from os.path import abspath, dirname, join + +from unittest import TestCase + +PATH = abspath(join(dirname(abspath(__file__)), "..", "")) + +# gettext +__builtin__._ = lambda x: x +__builtin__.hookManager = _ + +class TestSyntax(TestCase): + pass + + +for path, dirs, files in walk(join(PATH, "module")): + + for f in files: + if not f.endswith(".py") or f.startswith("__"): continue + fpath = join(path, f) + pack = fpath.replace(PATH, "")[1:-3] #replace / and .py + imp = pack.replace("/", ".") + packages = imp.split(".") + #__import__(imp) + + # to much sideeffect when importing + if "web" in packages or "lib" in packages: continue + if "ThriftTest" in packages: continue + + # currying + def meta(imp, sig): + def _test(self=None): + __import__(imp) + + _test.func_name = sig + return _test + + # generate test methods + sig = "test_%s_%s" % (packages[-2], packages[-1]) + + + setattr(TestSyntax, sig, meta(imp, sig))
\ No newline at end of file diff --git a/testlinks.txt b/tests/testlinks.txt index 428cf63ea..428cf63ea 100644..100755 --- a/testlinks.txt +++ b/tests/testlinks.txt |