From 692d015627ecf03fbc23cfdb4afcf398b9a09a51 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 12 Jan 2012 17:26:28 +0100 Subject: scripts for testing and syntax unit test --- tests/CrypterPluginTester.py | 6 ++ tests/HosterPluginTester.py | 3 + tests/clonedigger.sh | 2 + tests/config/db.version | 1 + tests/config/plugin.conf | 138 +++++++++++++++++++++++++++++++++++++++++++ tests/config/pyload.conf.org | 75 +++++++++++++++++++++++ tests/config/pyload.db.org | Bin 0 -> 13312 bytes tests/nosetests.sh | 5 ++ tests/pyflakes.sh | 2 + tests/quit_pyload.sh | 4 ++ tests/run_pyload.sh | 17 ++++++ tests/sloccount.sh | 2 + tests/stubs/__init__.py | 1 + tests/test_api.py | 8 +-- tests/test_json.py | 5 +- tests/test_syntax.py | 45 ++++++++++++++ tests/testlinks.txt | 26 ++++++++ 17 files changed, 332 insertions(+), 8 deletions(-) create mode 100644 tests/CrypterPluginTester.py create mode 100644 tests/HosterPluginTester.py create mode 100755 tests/clonedigger.sh create mode 100644 tests/config/db.version create mode 100644 tests/config/plugin.conf create mode 100644 tests/config/pyload.conf.org create mode 100644 tests/config/pyload.db.org create mode 100755 tests/nosetests.sh create mode 100755 tests/pyflakes.sh create mode 100755 tests/quit_pyload.sh create mode 100755 tests/run_pyload.sh create mode 100755 tests/sloccount.sh create mode 100644 tests/stubs/__init__.py create mode 100644 tests/test_syntax.py create mode 100755 tests/testlinks.txt (limited to 'tests') 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 new file mode 100644 index 000000000..d340531c5 Binary files /dev/null and b/tests/config/pyload.db.org differ 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/tests/testlinks.txt b/tests/testlinks.txt new file mode 100755 index 000000000..428cf63ea --- /dev/null +++ b/tests/testlinks.txt @@ -0,0 +1,26 @@ +sha1: + 961486646bf3c1d5d7a45ec32bb62e1bc4f2d894 random.bin +md5: + d76505d0869f9f928a17d42d66326307 random.bin + +please save bandwith on our server, +use this link only for remote uploads to new hoster +http://get.pyload.org/static/random.bin +--------------------------------------- +http://netload.in/datei9XirAJZs79/random.bin.htm +http://ul.to/file/o41isx +http://rapidshare.com/files/445996776/random.bin +http://dl.free.fr/d4aL5dyXY +http://www.duckload.com/dl/QggW2 +http://files.mail.ru/32EW66 +http://www.fileserve.com/file/MxjZXjX +http://www.4shared.com/file/-O5CBhQV/random.html +http://hotfile.com/dl/101569859/2e01f04/random.bin.html +http://www.megaupload.com/?d=1JZLOP3B +http://www.share.cx/files/235687689252/random.bin.html +http://www.share-online.biz/download.php?id=PTCOX1GL6XAH +http://www.shragle.com/files/f899389b/random.bin +http://www10.zippyshare.com/v/76557688/file.html +http://yourfiles.to/?d=312EC6E911 +http://depositfiles.com/files/k8la98953 +http://uploading.com/files/3896f5a1/random.bin/ -- cgit v1.2.3 From fc80bdf246994fdff9d848c43111d57054806f6a Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 12 Jan 2012 18:17:27 +0100 Subject: cpd fix --- tests/clonedigger.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/clonedigger.sh b/tests/clonedigger.sh index 69b1c13fa..8ac9f2657 100755 --- a/tests/clonedigger.sh +++ b/tests/clonedigger.sh @@ -1,2 +1,2 @@ #!/bin/bash -clonedigger -o cpd.xml --cpd-output --ignore-dir=module/lib . +clonedigger -o cpd.xml --cpd-output --ignore-dir=lib module -- cgit v1.2.3 From 9d3684d3db48fa240c8bd115306a66082f70cdaa Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 12 Jan 2012 19:24:27 +0100 Subject: changed some test parameters --- tests/clonedigger.sh | 2 +- tests/sloccount.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/clonedigger.sh b/tests/clonedigger.sh index 8ac9f2657..93c1cb323 100755 --- a/tests/clonedigger.sh +++ b/tests/clonedigger.sh @@ -1,2 +1,2 @@ #!/bin/bash -clonedigger -o cpd.xml --cpd-output --ignore-dir=lib module +clonedigger -o cpd.xml --cpd-output --fast --ignore-dir=lib --ignore-dir=remote module diff --git a/tests/sloccount.sh b/tests/sloccount.sh index 98423b4f8..cdb629f7f 100755 --- a/tests/sloccount.sh +++ b/tests/sloccount.sh @@ -1,2 +1,2 @@ #!/bin/bash -sloccount . --duplicates --wide --details > sloccount.sc +sloccount module --duplicates --wide --details > sloccount.sc -- cgit v1.2.3 From 5cd5c4f4a14f406640708a471e86a37e9132c6b9 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 12 Jan 2012 19:42:53 +0100 Subject: pyflakes fix --- tests/pyflakes.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/pyflakes.sh b/tests/pyflakes.sh index cdfc11319..1ed61d2ee 100755 --- a/tests/pyflakes.sh +++ b/tests/pyflakes.sh @@ -1,2 +1,3 @@ #!/bin/bash find -name '*.py' |egrep -v '^.(/tests/|/module/lib)'|xargs pyflakes > pyflakes.log || : +cat pyflakes.log | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' > pyflakes.txt -- cgit v1.2.3 From f890926cf9fa9f6c36e503008f28daf0f1951084 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 13 Jan 2012 18:02:58 +0100 Subject: fixed pyflakes and sloccount --- tests/pyflakes.sh | 4 +++- tests/sloccount.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/pyflakes.sh b/tests/pyflakes.sh index 1ed61d2ee..0c7e03891 100755 --- a/tests/pyflakes.sh +++ b/tests/pyflakes.sh @@ -1,3 +1,5 @@ #!/bin/bash find -name '*.py' |egrep -v '^.(/tests/|/module/lib)'|xargs pyflakes > pyflakes.log || : -cat pyflakes.log | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' > pyflakes.txt +# Filter warnings and strip ./ from path +cat pyflakes.log | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' | grep -i -E -v "'_'|pypath|webinterface|pyreq|hookmanager" > pyflakes.txt +sed -i 's/^.\///g' pyflakes.txt diff --git a/tests/sloccount.sh b/tests/sloccount.sh index cdb629f7f..70150501e 100755 --- a/tests/sloccount.sh +++ b/tests/sloccount.sh @@ -1,2 +1,2 @@ #!/bin/bash -sloccount module --duplicates --wide --details > sloccount.sc +sloccount --duplicates --wide --details . > sloccount.sc -- cgit v1.2.3 From c7ad1cc5b4a5d190a060e3ddd9274c3065da6708 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 13 Jan 2012 23:24:21 +0100 Subject: plugin unit test, closed #499, #500 --- tests/CrypterPluginTester.py | 71 ++++++++++++++++++++++++-- tests/HosterPluginTester.py | 115 +++++++++++++++++++++++++++++++++++++++++ tests/crypterlinks.txt | 4 ++ tests/helper/PluginTester.py | 52 +++++++++++++++++++ tests/helper/Stubs.py | 119 +++++++++++++++++++++++++++++++++++++++++++ tests/helper/__init__.py | 0 tests/hosterlinks.txt | 24 +++++++++ tests/plugin_tests.sh | 5 ++ tests/stubs/__init__.py | 1 - tests/test_syntax.py | 5 +- tests/testlinks.txt | 26 ---------- 11 files changed, 389 insertions(+), 33 deletions(-) create mode 100644 tests/crypterlinks.txt create mode 100644 tests/helper/PluginTester.py create mode 100644 tests/helper/Stubs.py create mode 100644 tests/helper/__init__.py create mode 100755 tests/hosterlinks.txt create mode 100755 tests/plugin_tests.sh delete mode 100644 tests/stubs/__init__.py delete mode 100755 tests/testlinks.txt (limited to 'tests') diff --git a/tests/CrypterPluginTester.py b/tests/CrypterPluginTester.py index 124cb4d0a..27013ede7 100644 --- a/tests/CrypterPluginTester.py +++ b/tests/CrypterPluginTester.py @@ -1,6 +1,71 @@ # -*- coding: utf-8 -*- -from unittest import TestCase +from os.path import dirname, join +from nose.tools import nottest -class DecryptPluginTester(TestCase): - pass \ No newline at end of file +from logging import log, DEBUG + +from helper.Stubs import Core +from helper.PluginTester import PluginTester + +from module.plugins.Base import Fail +from module.utils import accumulate, to_int + +class CrypterPluginTester(PluginTester): + + @nottest + def test_plugin(self, name, url, flag): + + log(DEBUG, "%s: %s", name, url) + + plugin = self.core.pluginManager.getPluginClass(name) + p = plugin(self.core, None, "") + self.thread.plugin = p + + try: + result = p._decrypt([url]) + + if to_int(flag): + assert to_int(flag) == len(result) + + except Exception, e: + if isinstance(e, Fail) and flag == "fail": + pass + else: + raise + + +# setup methods + +c = Core() + +f = open(join(dirname(__file__), "crypterlinks.txt")) +links = [x.strip() for x in f.readlines()] +urls = [] +flags = {} + +for l in links: + if not l or l.startswith("#"): continue + if l.startswith("http"): + if "||" in l: + l, flag = l.split("||") + flags[l] = flag + + urls.append(l) + +h, crypter = c.pluginManager.parseUrls(urls) +plugins = accumulate(crypter) +for plugin, urls in plugins.iteritems(): + + for i, url in enumerate(urls): + + + def meta(plugin, url, flag, sig): + def _test(self): + self.test_plugin(plugin, url, flag) + + _test.func_name = sig + return _test + + sig = "test_%s_LINK%d" % (plugin, i) + setattr(CrypterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index faaaf799c..e4738ad5e 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -1,3 +1,118 @@ # -*- coding: utf-8 -*- +from os import remove +from os.path import dirname +from logging import log, DEBUG +from hashlib import md5 +from time import time +from nose.tools import nottest + +from helper.Stubs import Core +from helper.PluginTester import PluginTester + +from module.PyFile import PyFile +from module.plugins.Base import Fail +from module.utils import accumulate +from module.utils.fs import save_join, join, exists + +DL_DIR = join("Downloads", "tmp") + +class HosterPluginTester(PluginTester): + + files = {} + + def setUp(self): + PluginTester.setUp(self) + for f in self.files: + pass + if exists(join(DL_DIR, f)): remove(join(DL_DIR, f)) + + @nottest + def test_plugin(self, name, url, flag): + + # Print to stdout to see whats going on + print "%s: %s" % (name, url) + log(DEBUG, "%s: %s", name, url) + + # url and plugin should be only important thing + pyfile = PyFile(self.core, -1, url, url, 0, 0, "", name, 0, 0) + pyfile.initPlugin() + + self.thread.pyfile = pyfile + self.thread.plugin = pyfile.plugin + + try: + a = time() + pyfile.plugin.preprocessing(self.thread) + + + log(DEBUG, "downloading took %ds" % (time()-a)) + log(DEBUG, "size %d kb" % (pyfile.size / 1024)) + + if pyfile.name not in self.files: + raise Exception("Filename %s wrong." % pyfile.name) + + if not exists(save_join(DL_DIR, pyfile.name)): + raise Exception("File %s does not exists." % pyfile.name) + + hash = md5() + f = open(save_join(DL_DIR, pyfile.name)) + while True: + buf = f.read(4096) + if not buf: break + hash.update(buf) + + if hash.hexdigest() != self.files[pyfile.name]: + raise Exception("Hash does not match.") + + + + except Exception, e: + if isinstance(e, Fail) and flag == "fail": + pass + elif isinstance(e, Fail) and flag == "offline" and e.message == "offline": + pass + else: + raise + + +# setup methods + +c = Core() + +f = open(join(dirname(__file__), "hosterlinks.txt")) +links = [x.strip() for x in f.readlines()] +urls = [] +flags = {} + +for l in links: + if not l or l.startswith("#"): continue + if l.startswith("http"): + if "||" in l: + l, flag = l.split("||") + flags[l] = flag + urls.append(l) + + elif len(l.split(" ")) == 2: + name, hash = l.split(" ") + HosterPluginTester.files[name] = hash + + +hoster, c = c.pluginManager.parseUrls(urls) + +plugins = accumulate(hoster) +for plugin, urls in plugins.iteritems(): + + for i, url in enumerate(urls): + + + def meta(plugin, url, flag, sig): + def _test(self): + self.test_plugin(plugin, url, flag) + + _test.func_name = sig + return _test + + sig = "test_%s_LINK%d" % (plugin, i) + setattr(HosterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file diff --git a/tests/crypterlinks.txt b/tests/crypterlinks.txt new file mode 100644 index 000000000..38692c756 --- /dev/null +++ b/tests/crypterlinks.txt @@ -0,0 +1,4 @@ + +# Crypter links, append ||fail or ||#N to mark error or number of expected results (single links+packages) + +http://www.filesonic.com/folder/19906605||2 diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py new file mode 100644 index 000000000..997a0923f --- /dev/null +++ b/tests/helper/PluginTester.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase +from os.path import abspath +from sys import exc_clear, exc_info +from logging import log, DEBUG +from time import sleep, time + +from Stubs import Thread, Core, noop + +from module.plugins.Hoster import Hoster, Abort, Fail + +def _wait(self): + """ waits the time previously set """ + self.waiting = True + + waittime = self.pyfile.waitUntil - time() + log(DEBUG, "waiting %ss" % waittime) + + if self.wantReconnect: + raise Fail("Would wait for reconnect %ss" % waittime ) + if self.wantReconnect or waittime > 300: + raise Fail("Would wait %ss" % waittime ) + + while self.pyfile.waitUntil > time(): + sleep(1) + if self.pyfile.abort: raise Abort + + self.waiting = False + self.pyfile.setStatus("starting") + +Hoster.wait = _wait + +Hoster.checkForSameFiles = noop + +class PluginTester(TestCase): + + @classmethod + def setUpClass(cls): + cls.core = Core() + + def setUp(self): + self.thread = Thread(self.core) + exc_clear() + + def tearDown(self): + exc = exc_info() + if exc != (None, None, None): + debug = self.thread.writeDebugReport() + log(DEBUG, debug) + # generate attachment + print "\n[[ATTACHMENT|%s]]\n" % abspath(debug) \ No newline at end of file diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py new file mode 100644 index 000000000..eb3cc98c1 --- /dev/null +++ b/tests/helper/Stubs.py @@ -0,0 +1,119 @@ +# -*- coding: utf-8 -*- + +import sys +from os.path import abspath, dirname, join +from time import strftime + +sys.path.append(abspath(join(dirname(__file__), "..", "..", "module", "lib"))) +sys.path.append(abspath(join(dirname(__file__), "..", ".."))) + +import __builtin__ + +from module.PyPackage import PyPackage +from module.threads.BaseThread import BaseThread +from module.config.ConfigParser import ConfigParser +from module.network.RequestFactory import RequestFactory +from module.plugins.PluginManager import PluginManager +from module.common.JsEngine import JsEngine + +from logging import log, DEBUG, INFO, WARN, ERROR + + +# Do nothing +def noop(*args, **kwargs): + pass + +ConfigParser.save = noop + +class LogStub: + def debug(self, *args): + log(DEBUG, *args) + + def info(self, *args): + log(INFO, *args) + + def error(self, *args): + log(ERROR, *args) + + def warning(self, *args): + log(WARN, *args) + + +class NoLog: + def debug(self, *args): + pass + + def info(self, *args): + pass + + def error(self, *args): + log(ERROR, *args) + + def warning(self, *args): + log(WARN, *args) + + +class Core: + def __init__(self): + self.log = NoLog() + + self.api = self + self.core = self + self.debug = True + self.captcha = True + self.config = ConfigParser() + self.pluginManager = PluginManager(self) + self.requestFactory = RequestFactory(self) + __builtin__.pyreq = self.requestFactory + self.accountManager = AccountManager() + self.hookManager = self.eventManager = self.interActionManager = NopClass() + self.js = JsEngine() + self.cache = {} + self.packageCache = {} + + self.log = LogStub() + + def getServerVersion(self): + return "TEST_RUNNER on %s" % strftime("%d %h %Y") + + def path(self, path): + return path + + def updateLink(self, *args): + pass + + def updatePackage(self, *args): + pass + + def getPackage(self, id): + return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0) + + + +class NopClass: + def __getattr__(self, item): + return noop + +class AccountManager: + + def getAccountForPlugin(self, name): + return None + +class Thread(BaseThread): + def __init__(self, core): + BaseThread.__init__(self, core) + self.plugin = None + + + def writeDebugReport(self): + if hasattr(self, "pyfile"): + dump = BaseThread.writeDebugReport(self, self.plugin.__name__, pyfile=self.pyfile) + else: + dump = BaseThread.writeDebugReport(self, self.plugin.__name__, plugin=self.plugin) + + return dump + +__builtin__._ = lambda x: x +__builtin__.pypath = "" +__builtin__.hookManager = NopClass() +__builtin__.pyreq = None \ No newline at end of file diff --git a/tests/helper/__init__.py b/tests/helper/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt new file mode 100755 index 000000000..0da4074dc --- /dev/null +++ b/tests/hosterlinks.txt @@ -0,0 +1,24 @@ + +# Valid files, with md5 hash +# Please only use files around 5-15 MB +random.bin d76505d0869f9f928a17d42d66326307 + +# Hoster links, append ||offline or ||fail to mark your expectation + +http://netload.in/datei9XirAJZs79/random.bin.htm +http://ul.to/file/o41isx||offline +http://rapidshare.com/files/445996776/random.bin +http://dl.free.fr/d4aL5dyXY||offline +http://www.duckload.com/dl/QggW2 +http://files.mail.ru/32EW66||offline +http://www.fileserve.com/file/MxjZXjX||offline +http://www.4shared.com/file/-O5CBhQV/random.html +http://hotfile.com/dl/101569859/2e01f04/random.bin.html +http://www.megaupload.com/?d=1JZLOP3B +http://www.share.cx/files/235687689252/random.bin.html +http://www.share-online.biz/download.php?id=PTCOX1GL6XAH||offline +http://www.shragle.com/files/f899389b/random.bin +http://www10.zippyshare.com/v/76557688/file.html +http://yourfiles.to/?d=312EC6E911 +http://depositfiles.com/files/k8la98953 +http://uploading.com/files/3896f5a1/random.bin/ diff --git a/tests/plugin_tests.sh b/tests/plugin_tests.sh new file mode 100755 index 000000000..a0260b5bb --- /dev/null +++ b/tests/plugin_tests.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +NS=nosetests +which nosetests2 > /dev/null && NS=nosetests2 +$NS tests/HosterPluginTester.py tests/CrypterPluginTester.py -s --with-xunit --with-coverage --cover-erase --cover-package=module.plugins +coverage xml diff --git a/tests/stubs/__init__.py b/tests/stubs/__init__.py deleted file mode 100644 index 4b31e848b..000000000 --- a/tests/stubs/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'christian' diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 82c4194da..4a131ef6f 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -8,9 +8,8 @@ from unittest import TestCase PATH = abspath(join(dirname(abspath(__file__)), "..", "")) -# gettext -__builtin__._ = lambda x: x -__builtin__.hookManager = _ +# needed to register globals +from helper import Stubs class TestSyntax(TestCase): pass diff --git a/tests/testlinks.txt b/tests/testlinks.txt deleted file mode 100755 index 428cf63ea..000000000 --- a/tests/testlinks.txt +++ /dev/null @@ -1,26 +0,0 @@ -sha1: - 961486646bf3c1d5d7a45ec32bb62e1bc4f2d894 random.bin -md5: - d76505d0869f9f928a17d42d66326307 random.bin - -please save bandwith on our server, -use this link only for remote uploads to new hoster -http://get.pyload.org/static/random.bin ---------------------------------------- -http://netload.in/datei9XirAJZs79/random.bin.htm -http://ul.to/file/o41isx -http://rapidshare.com/files/445996776/random.bin -http://dl.free.fr/d4aL5dyXY -http://www.duckload.com/dl/QggW2 -http://files.mail.ru/32EW66 -http://www.fileserve.com/file/MxjZXjX -http://www.4shared.com/file/-O5CBhQV/random.html -http://hotfile.com/dl/101569859/2e01f04/random.bin.html -http://www.megaupload.com/?d=1JZLOP3B -http://www.share.cx/files/235687689252/random.bin.html -http://www.share-online.biz/download.php?id=PTCOX1GL6XAH -http://www.shragle.com/files/f899389b/random.bin -http://www10.zippyshare.com/v/76557688/file.html -http://yourfiles.to/?d=312EC6E911 -http://depositfiles.com/files/k8la98953 -http://uploading.com/files/3896f5a1/random.bin/ -- cgit v1.2.3 From 069503da5106fd2fcf7fa2d3a8462ab109b44adb Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 13 Jan 2012 23:42:10 +0100 Subject: cosmetic fixes --- tests/HosterPluginTester.py | 8 ++++---- tests/helper/PluginTester.py | 3 ++- tests/hosterlinks.txt | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index e4738ad5e..eeb895295 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -32,8 +32,8 @@ class HosterPluginTester(PluginTester): def test_plugin(self, name, url, flag): # Print to stdout to see whats going on - print "%s: %s" % (name, url) - log(DEBUG, "%s: %s", name, url) + print "%s: %s, %s" % (name, url, flag) + log(DEBUG, "%s: %s, %s", name, url, flag) # url and plugin should be only important thing pyfile = PyFile(self.core, -1, url, url, 0, 0, "", name, 0, 0) @@ -51,7 +51,7 @@ class HosterPluginTester(PluginTester): log(DEBUG, "size %d kb" % (pyfile.size / 1024)) if pyfile.name not in self.files: - raise Exception("Filename %s wrong." % pyfile.name) + raise Exception("Filename %s not recognized." % pyfile.name) if not exists(save_join(DL_DIR, pyfile.name)): raise Exception("File %s does not exists." % pyfile.name) @@ -114,5 +114,5 @@ for plugin, urls in plugins.iteritems(): _test.func_name = sig return _test - sig = "test_%s_LINK%d" % (plugin, i) + sig = "test_%s_LINK%d_%s" % (plugin, i, flag) setattr(HosterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index 997a0923f..d0c1cdd3c 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -7,6 +7,7 @@ from logging import log, DEBUG from time import sleep, time from Stubs import Thread, Core, noop +from sys import stderr from module.plugins.Hoster import Hoster, Abort, Fail @@ -49,4 +50,4 @@ class PluginTester(TestCase): debug = self.thread.writeDebugReport() log(DEBUG, debug) # generate attachment - print "\n[[ATTACHMENT|%s]]\n" % abspath(debug) \ No newline at end of file + stderr.write("\n[[ATTACHMENT|%s]]\n" % abspath(debug)) \ No newline at end of file diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index 0da4074dc..153252626 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -9,7 +9,6 @@ http://netload.in/datei9XirAJZs79/random.bin.htm http://ul.to/file/o41isx||offline http://rapidshare.com/files/445996776/random.bin http://dl.free.fr/d4aL5dyXY||offline -http://www.duckload.com/dl/QggW2 http://files.mail.ru/32EW66||offline http://www.fileserve.com/file/MxjZXjX||offline http://www.4shared.com/file/-O5CBhQV/random.html -- cgit v1.2.3 From 828cc89cc9b7a2ecacf98fc73928d988e15f0b98 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 14 Jan 2012 15:49:08 +0100 Subject: captcha and attachments for plugin tester --- tests/HosterPluginTester.py | 18 +++++-- tests/helper/PluginTester.py | 118 +++++++++++++++++++++++++++++++++++++++---- tests/hosterlinks.txt | 19 ++++--- tests/quit_pyload.sh | 3 ++ tests/test_syntax.py | 1 - 5 files changed, 137 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index eeb895295..2972e28fe 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -28,6 +28,7 @@ class HosterPluginTester(PluginTester): pass if exists(join(DL_DIR, f)): remove(join(DL_DIR, f)) + @nottest def test_plugin(self, name, url, flag): @@ -46,10 +47,13 @@ class HosterPluginTester(PluginTester): a = time() pyfile.plugin.preprocessing(self.thread) - log(DEBUG, "downloading took %ds" % (time()-a)) log(DEBUG, "size %d kb" % (pyfile.size / 1024)) + if flag == "offline": + raise Exception("No offline Exception raised.") + + if pyfile.name not in self.files: raise Exception("Filename %s not recognized." % pyfile.name) @@ -64,6 +68,7 @@ class HosterPluginTester(PluginTester): hash.update(buf) if hash.hexdigest() != self.files[pyfile.name]: + log(DEBUG, "Hash is %s" % hash.hexdigest()) raise Exception("Hash does not match.") @@ -91,7 +96,7 @@ for l in links: if l.startswith("http"): if "||" in l: l, flag = l.split("||") - flags[l] = flag + flags[l] = flag.strip() urls.append(l) elif len(l.split(" ")) == 2: @@ -106,7 +111,6 @@ for plugin, urls in plugins.iteritems(): for i, url in enumerate(urls): - def meta(plugin, url, flag, sig): def _test(self): self.test_plugin(plugin, url, flag) @@ -114,5 +118,11 @@ for plugin, urls in plugins.iteritems(): _test.func_name = sig return _test - sig = "test_%s_LINK%d_%s" % (plugin, i, flag) + tmp_flag = flags.get(url, None) + if flags.get(url, None): + sig = "test_%s_LINK%d_%s" % (plugin, i, tmp_flag) + else: + sig = "test_%s_LINK%d" % (plugin, i) + + setattr(HosterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index d0c1cdd3c..e0ce8f354 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -1,14 +1,21 @@ # -*- coding: utf-8 -*- from unittest import TestCase -from os.path import abspath +from os import makedirs, remove +from os.path import exists, join, expanduser +from shutil import move from sys import exc_clear, exc_info from logging import log, DEBUG from time import sleep, time +from random import randint +from glob import glob + +from pycurl import LOW_SPEED_TIME, FORM_FILE +from json import loads from Stubs import Thread, Core, noop -from sys import stderr +from module.network.RequestFactory import getRequest, getURL from module.plugins.Hoster import Hoster, Abort, Fail def _wait(self): @@ -18,10 +25,10 @@ def _wait(self): waittime = self.pyfile.waitUntil - time() log(DEBUG, "waiting %ss" % waittime) - if self.wantReconnect: - raise Fail("Would wait for reconnect %ss" % waittime ) - if self.wantReconnect or waittime > 300: - raise Fail("Would wait %ss" % waittime ) + if self.wantReconnect and waittime > 300: + raise Fail("Would wait for reconnect %ss" % waittime) + elif waittime > 300: + raise Fail("Would wait %ss" % waittime) while self.pyfile.waitUntil > time(): sleep(1) @@ -32,13 +39,106 @@ def _wait(self): Hoster.wait = _wait + +def decryptCaptcha(self, url, get={}, post={}, cookies=False, forceUser=False, imgtype='jpg', + result_type='textual'): + img = self.load(url, get=get, post=post, cookies=cookies) + + id = ("%.2f" % time())[-6:].replace(".", "") + temp_file = open(join("tmp", "tmpCaptcha_%s_%s.%s" % (self.__name__, id, imgtype)), "wb") + temp_file.write(img) + temp_file.close() + + Ocr = self.core.pluginManager.loadClass("captcha", self.__name__) + + if Ocr: + log(DEBUG, "Using tesseract for captcha") + sleep(randint(3000, 5000) / 1000.0) + if self.pyfile.abort: raise Abort + + ocr = Ocr() + result = ocr.get_captcha(temp_file.name) + else: + log(DEBUG, "Using ct for captcha") + # put username and passkey into two lines in ct.conf + conf = join(expanduser("~"), "ct.conf") + if not exists(conf): raise Exception("CaptchaTrader config %s not found." % conf) + f = open(conf, "rb") + req = getRequest() + + #raise timeout threshold + req.c.setopt(LOW_SPEED_TIME, 80) + + try: + json = req.load("http://captchatrader.com/api/submit", + post={"api_key": "9f65e7f381c3af2b076ea680ae96b0b7", + "username": f.readline().strip(), + "password": f.readline().strip(), + "value": (FORM_FILE, temp_file.name), + "type": "file"}, multipart=True) + finally: + f.close() + req.close() + + response = loads(json) + log(DEBUG, str(response)) + result = response[1] + + self.cTask = response[0] + + return result + +Hoster.decryptCaptcha = decryptCaptcha + + +def respond(ticket, value): + conf = join(expanduser("~"), "ct.conf") + f = open(conf, "rb") + try: + getURL("http://captchatrader.com/api/respond", + post={"is_correct": value, + "username": f.readline().strip(), + "password": f.readline().strip(), + "ticket": ticket}) + except Exception, e : + print "CT Exception:", e + log(DEBUG, str(e)) + finally: + f.close() + + + +def invalidCaptcha(self): + log(DEBUG, "Captcha invalid") + if self.cTask: + respond(self.ticket, 0) + +Hoster.invalidCaptcha = invalidCaptcha + +def correctCaptcha(self): + log(DEBUG, "Captcha correct") + if self.cTask: + respond(self.ticket, 1) + +Hoster.correctCaptcha = correctCaptcha + Hoster.checkForSameFiles = noop class PluginTester(TestCase): - @classmethod def setUpClass(cls): cls.core = Core() + name = "tests.%s.%s" % (cls.__name__, cls.__name__) + for f in glob(join(name, "debug_*")): + remove(f) + + # Copy debug report to attachment dir for jenkins + @classmethod + def tearDownClass(cls): + name = "tests.%s.%s" % (cls.__name__, cls.__name__) + if not exists(name): makedirs(name) + for f in glob("debug_*"): + move(f, join(name, f)) def setUp(self): self.thread = Thread(self.core) @@ -48,6 +148,4 @@ class PluginTester(TestCase): exc = exc_info() if exc != (None, None, None): debug = self.thread.writeDebugReport() - log(DEBUG, debug) - # generate attachment - stderr.write("\n[[ATTACHMENT|%s]]\n" % abspath(debug)) \ No newline at end of file + log(DEBUG, debug) \ No newline at end of file diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index 153252626..a94655e2f 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -1,23 +1,28 @@ # Valid files, with md5 hash # Please only use files around 5-15 MB + +# http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 # Hoster links, append ||offline or ||fail to mark your expectation http://netload.in/datei9XirAJZs79/random.bin.htm -http://ul.to/file/o41isx||offline http://rapidshare.com/files/445996776/random.bin -http://dl.free.fr/d4aL5dyXY||offline -http://files.mail.ru/32EW66||offline -http://www.fileserve.com/file/MxjZXjX||offline -http://www.4shared.com/file/-O5CBhQV/random.html http://hotfile.com/dl/101569859/2e01f04/random.bin.html http://www.megaupload.com/?d=1JZLOP3B -http://www.share.cx/files/235687689252/random.bin.html -http://www.share-online.biz/download.php?id=PTCOX1GL6XAH||offline http://www.shragle.com/files/f899389b/random.bin http://www10.zippyshare.com/v/76557688/file.html http://yourfiles.to/?d=312EC6E911 http://depositfiles.com/files/k8la98953 http://uploading.com/files/3896f5a1/random.bin/ + + +http://ul.to/file/o41isx||offline +http://www.4shared.com/file/-O5CBhQV/random.html||offline +http://www.4shared.com/file/-O5CBhQV/random.html||offline +http://www.fileserve.com/file/MxjZXjX||offline +http://www.share-online.biz/download.php?id=PTCOX1GL6XAH||offline +http://dl.free.fr/d4aL5dyXY||offline +http://files.mail.ru/32EW66||offline +http://www.shragle.com/files/f899389b/random.bin||offline \ No newline at end of file diff --git a/tests/quit_pyload.sh b/tests/quit_pyload.sh index a8f81984a..e466bcb31 100755 --- a/tests/quit_pyload.sh +++ b/tests/quit_pyload.sh @@ -2,3 +2,6 @@ PYTHON=python which python2 > /dev/null && PYTHON=python2 $PYTHON pyLoadCore.py --configdir=tests/config --quit +if [ -d userplugins ]; then + rm -r userplugins +fi \ No newline at end of file diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 4a131ef6f..a4cc53ee5 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import __builtin__ from os import walk from os.path import abspath, dirname, join -- cgit v1.2.3 From a0615c500c8bce03aaf89156a5f5e5e06873587c Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 14 Jan 2012 16:07:47 +0100 Subject: fixed attachment file path --- tests/helper/PluginTester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index e0ce8f354..db01a2d06 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -128,14 +128,14 @@ class PluginTester(TestCase): @classmethod def setUpClass(cls): cls.core = Core() - name = "tests.%s.%s" % (cls.__name__, cls.__name__) + name = "%s.%s" % (cls.__name__, cls.__name__) for f in glob(join(name, "debug_*")): remove(f) # Copy debug report to attachment dir for jenkins @classmethod def tearDownClass(cls): - name = "tests.%s.%s" % (cls.__name__, cls.__name__) + name = "%s.%s" % (cls.__name__, cls.__name__) if not exists(name): makedirs(name) for f in glob("debug_*"): move(f, join(name, f)) -- cgit v1.2.3 From be3abec5255e91bbeb0484053302f95156ad7621 Mon Sep 17 00:00:00 2001 From: zoidberg10 Date: Sun, 15 Jan 2012 01:10:21 +0100 Subject: plugin tester links --- tests/HosterPluginTester.py | 4 ++-- tests/hosterlinks.txt | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 2972e28fe..32b67d93e 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -99,8 +99,8 @@ for l in links: flags[l] = flag.strip() urls.append(l) - elif len(l.split(" ")) == 2: - name, hash = l.split(" ") + elif len(l.rsplit(" ", 1)) == 2: + name, hash = l.rsplit(" ", 1) HosterPluginTester.files[name] = hash diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index a94655e2f..00a68eb03 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -4,6 +4,7 @@ # http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 +Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 932212256dc0b0a1e71c0944eef633a4 # Hoster links, append ||offline or ||fail to mark your expectation @@ -25,4 +26,23 @@ http://www.fileserve.com/file/MxjZXjX||offline http://www.share-online.biz/download.php?id=PTCOX1GL6XAH||offline http://dl.free.fr/d4aL5dyXY||offline http://files.mail.ru/32EW66||offline -http://www.shragle.com/files/f899389b/random.bin||offline \ No newline at end of file +http://www.shragle.com/files/f899389b/random.bin||offline + + +# Hoster links with fancy unicode filenames: +http://vs3iaw.1fichier.com/fr/ +http://www.4shared.com/file/rQltf2Fr/Mosk_elva___Зелная_черепаха___.html +http://bezvadata.cz/stahnout/99273_morska-zelva-.-d-i-m-i-d-a-.tar +http://www.crocko.com/A524453DA89841B4BFC4FB9125D6F186/ +http://czshare.com/2483034/zelva +http://www.easybytez.com/etvhltkg0d05 +http://www.filejungle.com/f/qX5fxT/ +http://fp.io/43798f2b/ +http://www.filesonic.com/file/yU2cU6s +http://www.fshare.vn/file/A7H8LSTP7Z/ +http://ifile.it/muwgivz +http://letitbit.net/download/67793.60a7d3745791db7271a6e6c92cfe/Mořská_želva_(_Зелёная_черепаха_.___綠蠵龜___-_Đồi_mồi_dứa_).tar.html +http://www.mediafire.com/?n09th58z1x5r585 +http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB +http://www.uloz.to/12553820/morska-zelva-oi-moi-dua-tar +http://www.wupload.com/file/2642593407/ \ No newline at end of file -- cgit v1.2.3 From 26227cfe53f8fd4bc1631d8e1b35031f589682dc Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 15 Jan 2012 15:55:19 +0100 Subject: backend + api test case, nicer format for plugin tester --- tests/CrypterPluginTester.py | 18 +++++++++++--- tests/HosterPluginTester.py | 33 ++++++++++++++++--------- tests/helper/PluginTester.py | 4 +-- tests/helper/Stubs.py | 9 +++---- tests/hosterlinks.txt | 4 +-- tests/plugin_tests.sh | 4 ++- tests/sloccount.sh | 2 +- tests/test_api.py | 24 +++++++++--------- tests/test_backends.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_json.py | 47 ----------------------------------- 10 files changed, 119 insertions(+), 85 deletions(-) create mode 100644 tests/test_backends.py delete mode 100644 tests/test_json.py (limited to 'tests') diff --git a/tests/CrypterPluginTester.py b/tests/CrypterPluginTester.py index 27013ede7..ceb58adc5 100644 --- a/tests/CrypterPluginTester.py +++ b/tests/CrypterPluginTester.py @@ -12,10 +12,10 @@ from module.plugins.Base import Fail from module.utils import accumulate, to_int class CrypterPluginTester(PluginTester): - @nottest def test_plugin(self, name, url, flag): + print "%s: %s" % (name, url) log(DEBUG, "%s: %s", name, url) plugin = self.core.pluginManager.getPluginClass(name) @@ -57,9 +57,15 @@ h, crypter = c.pluginManager.parseUrls(urls) plugins = accumulate(crypter) for plugin, urls in plugins.iteritems(): - for i, url in enumerate(urls): + def meta_class(plugin): + class _testerClass(CrypterPluginTester): + pass + _testerClass.__name__ = plugin + return _testerClass + _testerClass = meta_class(plugin) + for i, url in enumerate(urls): def meta(plugin, url, flag, sig): def _test(self): self.test_plugin(plugin, url, flag) @@ -67,5 +73,9 @@ for plugin, urls in plugins.iteritems(): _test.func_name = sig return _test - sig = "test_%s_LINK%d" % (plugin, i) - setattr(CrypterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file + sig = "test_LINK%d" % i + setattr(_testerClass, sig, meta(plugin, url, flags.get(url, None), sig)) + print url + + locals()[plugin] = _testerClass + del _testerClass \ No newline at end of file diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 32b67d93e..bc802ec18 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import __main__ + from os import remove from os.path import dirname from logging import log, DEBUG @@ -19,7 +21,6 @@ from module.utils.fs import save_join, join, exists DL_DIR = join("Downloads", "tmp") class HosterPluginTester(PluginTester): - files = {} def setUp(self): @@ -31,7 +32,6 @@ class HosterPluginTester(PluginTester): @nottest def test_plugin(self, name, url, flag): - # Print to stdout to see whats going on print "%s: %s, %s" % (name, url, flag) log(DEBUG, "%s: %s, %s", name, url, flag) @@ -47,13 +47,12 @@ class HosterPluginTester(PluginTester): a = time() pyfile.plugin.preprocessing(self.thread) - log(DEBUG, "downloading took %ds" % (time()-a)) + log(DEBUG, "downloading took %ds" % (time() - a)) log(DEBUG, "size %d kb" % (pyfile.size / 1024)) if flag == "offline": raise Exception("No offline Exception raised.") - if pyfile.name not in self.files: raise Exception("Filename %s not recognized." % pyfile.name) @@ -103,26 +102,38 @@ for l in links: name, hash = l.rsplit(" ", 1) HosterPluginTester.files[name] = hash - hoster, c = c.pluginManager.parseUrls(urls) plugins = accumulate(hoster) for plugin, urls in plugins.iteritems(): + # closure functions to retain local scope + def meta_class(plugin): + class _testerClass(HosterPluginTester): + pass + _testerClass.__name__ = plugin + return _testerClass - for i, url in enumerate(urls): + _testerClass = meta_class(plugin) - def meta(plugin, url, flag, sig): + for i, url in enumerate(urls): + def meta(__plugin, url, flag, sig): def _test(self): - self.test_plugin(plugin, url, flag) + self.test_plugin(__plugin, url, flag) _test.func_name = sig return _test tmp_flag = flags.get(url, None) if flags.get(url, None): - sig = "test_%s_LINK%d_%s" % (plugin, i, tmp_flag) + sig = "test_LINK%d_%s" % (i, tmp_flag) else: - sig = "test_%s_LINK%d" % (plugin, i) + sig = "test_LINK%d" % i + + # set test method + setattr(_testerClass, sig, meta(plugin, url, tmp_flag, sig)) - setattr(HosterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file + #register class + locals()[plugin] = _testerClass + # remove from locals, or tested twice + del _testerClass \ No newline at end of file diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index db01a2d06..b70c0d061 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -128,14 +128,14 @@ class PluginTester(TestCase): @classmethod def setUpClass(cls): cls.core = Core() - name = "%s.%s" % (cls.__name__, cls.__name__) + name = "%s.%s" % (cls.__module__, cls.__name__) for f in glob(join(name, "debug_*")): remove(f) # Copy debug report to attachment dir for jenkins @classmethod def tearDownClass(cls): - name = "%s.%s" % (cls.__name__, cls.__name__) + name = "%s.%s" % (cls.__module__, cls.__name__) if not exists(name): makedirs(name) for f in glob("debug_*"): move(f, join(name, f)) diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index eb3cc98c1..cfa5d6fdb 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -66,7 +66,7 @@ class Core: self.requestFactory = RequestFactory(self) __builtin__.pyreq = self.requestFactory self.accountManager = AccountManager() - self.hookManager = self.eventManager = self.interActionManager = NopClass() + self.hookManager = self.eventManager = self.interActionManager = NoopClass() self.js = JsEngine() self.cache = {} self.packageCache = {} @@ -89,8 +89,7 @@ class Core: return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0) - -class NopClass: +class NoopClass: def __getattr__(self, item): return noop @@ -114,6 +113,6 @@ class Thread(BaseThread): return dump __builtin__._ = lambda x: x -__builtin__.pypath = "" -__builtin__.hookManager = NopClass() +__builtin__.pypath = abspath(join(dirname(__file__), "..", "..")) +__builtin__.hookManager = NoopClass() __builtin__.pyreq = None \ No newline at end of file diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index 00a68eb03..f255661ab 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -2,7 +2,7 @@ # Valid files, with md5 hash # Please only use files around 5-15 MB -# http://download.pyload.org/random.bin +http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 932212256dc0b0a1e71c0944eef633a4 @@ -43,6 +43,6 @@ http://www.fshare.vn/file/A7H8LSTP7Z/ http://ifile.it/muwgivz http://letitbit.net/download/67793.60a7d3745791db7271a6e6c92cfe/Mořská_želva_(_Зелёная_черепаха_.___綠蠵龜___-_Đồi_mồi_dứa_).tar.html http://www.mediafire.com/?n09th58z1x5r585 -http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB +http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB http://www.uloz.to/12553820/morska-zelva-oi-moi-dua-tar http://www.wupload.com/file/2642593407/ \ No newline at end of file diff --git a/tests/plugin_tests.sh b/tests/plugin_tests.sh index a0260b5bb..be06c0dc5 100755 --- a/tests/plugin_tests.sh +++ b/tests/plugin_tests.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash NS=nosetests which nosetests2 > /dev/null && NS=nosetests2 -$NS tests/HosterPluginTester.py tests/CrypterPluginTester.py -s --with-xunit --with-coverage --cover-erase --cover-package=module.plugins +# must be executed within tests dir +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +$NS HosterPluginTester.py CrypterPluginTester.py -s --with-xunit --with-coverage --cover-erase --cover-package=module.plugins --with-id coverage xml diff --git a/tests/sloccount.sh b/tests/sloccount.sh index 70150501e..cd9eacaa4 100755 --- a/tests/sloccount.sh +++ b/tests/sloccount.sh @@ -1,2 +1,2 @@ #!/bin/bash -sloccount --duplicates --wide --details . > sloccount.sc +sloccount --duplicates --wide --details module pyLoadCore.py pyLoadCli.py > sloccount.sc diff --git a/tests/test_api.py b/tests/test_api.py index 76b3e1b40..236f72882 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,18 +1,18 @@ -# -*- coding: utf-8 -*- -from module.common import APIExerciser -from nose.tools import nottest +from unittest import TestCase +from pyLoadCore import Core +from module.common.APIExerciser import APIExerciser -class TestApi: +class TestApi(TestCase): - def __init__(self): - self.api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw") + @classmethod + def setUpClass(cls): + cls.core = Core() + cls.core.start(False, False, True) - def test_login(self): - assert self.api.api.login("crapp", "wrong pw") is False - - #@nottest def test_random(self): - for i in range(0, 1000): - self.api.testAPI() + api = APIExerciser(self.core) + + for i in range(2000): + api.testAPI() \ No newline at end of file diff --git a/tests/test_backends.py b/tests/test_backends.py new file mode 100644 index 000000000..71ccedd2f --- /dev/null +++ b/tests/test_backends.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- + + +from urllib import urlencode +from urllib2 import urlopen, HTTPError +from json import loads + +from logging import log + +from module.common import APIExerciser + +url = "http://localhost:8001/api/%s" + +class TestBackends(): + + def setUp(self): + u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"})) + self.key = loads(u.read()) + assert self.key is not False + + def test_random(self): + api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw") + + assert api.api.login("crapp", "wrong pw") is False + + for i in range(0, 1000): + api.testAPI() + + def call(self, name, post=None): + if not post: post = {} + post["session"] = self.key + u = urlopen(url % name, data=urlencode(post)) + return loads(u.read()) + + def test_wronglogin(self): + u = urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"})) + assert loads(u.read()) is False + + def test_access(self): + try: + urlopen(url % "getServerVersion") + except HTTPError, e: + assert e.code == 403 + else: + assert False + + def test_status(self): + ret = self.call("statusServer") + log(1, str(ret)) + assert "pause" in ret + assert "queue" in ret + + def test_unknown_method(self): + try: + self.call("notExisting") + except HTTPError, e: + assert e.code == 404 + else: + assert False diff --git a/tests/test_json.py b/tests/test_json.py deleted file mode 100644 index 4e8fb0e1f..000000000 --- a/tests/test_json.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- - -from urllib import urlencode -from urllib2 import urlopen, HTTPError -from json import loads - -from logging import log -url = "http://localhost:8001/api/%s" - -class TestJson: - - def call(self, name, post=None): - if not post: post = {} - post["session"] = self.key - u = urlopen(url % name, data=urlencode(post)) - return loads(u.read()) - - def setUp(self): - u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"})) - self.key = loads(u.read()) - assert self.key is not False - - def test_wronglogin(self): - u = urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"})) - assert loads(u.read()) is False - - def test_access(self): - try: - urlopen(url % "getServerVersion") - except HTTPError, e: - assert e.code == 403 - else: - assert False - - def test_status(self): - ret = self.call("statusServer") - log(1, str(ret)) - assert "pause" in ret - assert "queue" in ret - - def test_unknown_method(self): - try: - self.call("notExisting") - except HTTPError, e: - assert e.code == 404 - else: - assert False -- cgit v1.2.3 From 5981d85ce8ee86ac03afb129511aff5498b08b37 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 15 Jan 2012 19:47:04 +0100 Subject: keep downloaded files for debug report --- tests/HosterPluginTester.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index bc802ec18..f9ca74e5f 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -import __main__ - from os import remove from os.path import dirname from logging import log, DEBUG from hashlib import md5 from time import time +from shutil import move from nose.tools import nottest @@ -16,7 +15,7 @@ from helper.PluginTester import PluginTester from module.PyFile import PyFile from module.plugins.Base import Fail from module.utils import accumulate -from module.utils.fs import save_join, join, exists +from module.utils.fs import save_join, join, exists, listdir DL_DIR = join("Downloads", "tmp") @@ -29,6 +28,12 @@ class HosterPluginTester(PluginTester): pass if exists(join(DL_DIR, f)): remove(join(DL_DIR, f)) + # folder for reports + report = join("tmp", self.__class__.__name__) + if exists(report): + for f in listdir(report): + remove(join(report, f)) + @nottest def test_plugin(self, name, url, flag): @@ -65,9 +70,14 @@ class HosterPluginTester(PluginTester): buf = f.read(4096) if not buf: break hash.update(buf) + f.close() if hash.hexdigest() != self.files[pyfile.name]: log(DEBUG, "Hash is %s" % hash.hexdigest()) + + # Copy for debug report + move(f.name, join("tmp", plugin, f.name)) + raise Exception("Hash does not match.") -- cgit v1.2.3 From 247ae6fbec98dbc42c3910df2942842ef5256715 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 15 Jan 2012 21:17:23 +0100 Subject: fix test cases --- tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_api.py b/tests/test_api.py index 236f72882..0171b46bb 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -15,4 +15,4 @@ class TestApi(TestCase): api = APIExerciser(self.core) for i in range(2000): - api.testAPI() \ No newline at end of file + api.testAPI() -- cgit v1.2.3 From 5e55cbcf86dd05033d91ecfc0e58c2aaac16b72b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 15 Jan 2012 21:29:04 +0100 Subject: reverted sloccount --- tests/sloccount.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/sloccount.sh b/tests/sloccount.sh index cd9eacaa4..0dab4164e 100755 --- a/tests/sloccount.sh +++ b/tests/sloccount.sh @@ -1,2 +1,2 @@ #!/bin/bash -sloccount --duplicates --wide --details module pyLoadCore.py pyLoadCli.py > sloccount.sc +sloccount --duplicates --wide --details module > sloccount.sc -- cgit v1.2.3 From aabf168c0ccee7d6d7eacfbadecdca3cfc3956d3 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 18:02:26 +0100 Subject: little fixes --- tests/helper/PluginTester.py | 6 +++--- tests/hosterlinks.txt | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index b70c0d061..ef61385be 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -111,14 +111,14 @@ def respond(ticket, value): def invalidCaptcha(self): log(DEBUG, "Captcha invalid") if self.cTask: - respond(self.ticket, 0) + respond(self.cTask, 0) Hoster.invalidCaptcha = invalidCaptcha def correctCaptcha(self): log(DEBUG, "Captcha correct") if self.cTask: - respond(self.ticket, 1) + respond(self.cTask, 1) Hoster.correctCaptcha = correctCaptcha @@ -148,4 +148,4 @@ class PluginTester(TestCase): exc = exc_info() if exc != (None, None, None): debug = self.thread.writeDebugReport() - log(DEBUG, debug) \ No newline at end of file + log(DEBUG, debug) diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index f255661ab..c55634f0a 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -1,6 +1,7 @@ +# -*- coding: utf-8 -*- # Valid files, with md5 hash -# Please only use files around 5-15 MB +# Please only use files around 5-15 MB and with explicit permission for redistribution http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 @@ -45,4 +46,4 @@ http://letitbit.net/download/67793.60a7d3745791db7271a6e6c92cfe/Mořská_želva_ http://www.mediafire.com/?n09th58z1x5r585 http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB http://www.uloz.to/12553820/morska-zelva-oi-moi-dua-tar -http://www.wupload.com/file/2642593407/ \ No newline at end of file +http://www.wupload.com/file/2642593407/ -- cgit v1.2.3 From 995b6ace8598f22fe8b21b67c587797baa6f7f21 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 18:31:59 +0100 Subject: correct utf8 conversion for urls --- tests/crypterlinks.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/crypterlinks.txt b/tests/crypterlinks.txt index 38692c756..4ff651888 100644 --- a/tests/crypterlinks.txt +++ b/tests/crypterlinks.txt @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Crypter links, append ||fail or ||#N to mark error or number of expected results (single links+packages) -- cgit v1.2.3 From 20c318d1a95fe5dd33ca179c6a9e7787ab0c7e24 Mon Sep 17 00:00:00 2001 From: zoidberg10 Date: Mon, 16 Jan 2012 20:51:02 +0100 Subject: hosterlinks.txt - little fix --- tests/HosterPluginTester.py | 3 ++- tests/hosterlinks.txt | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index f9ca74e5f..23e9507f1 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -6,6 +6,7 @@ from logging import log, DEBUG from hashlib import md5 from time import time from shutil import move +import codecs from nose.tools import nottest @@ -95,7 +96,7 @@ class HosterPluginTester(PluginTester): c = Core() -f = open(join(dirname(__file__), "hosterlinks.txt")) +f = codecs.open(join(dirname(__file__), "hosterlinks.txt"), "r", "utf_8") links = [x.strip() for x in f.readlines()] urls = [] flags = {} diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index c55634f0a..6ac19f098 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -5,7 +5,8 @@ http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 -Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 932212256dc0b0a1e71c0944eef633a4 +Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 992d0871f7dbbe0e46747f1e37ba9123 +Mořská_želva_(_Зелёная_черепаха_.&+_綠蠵龜__@-_Đồi_mồi_dứa_).tar 992d0871f7dbbe0e46747f1e37ba9123 # Hoster links, append ||offline or ||fail to mark your expectation @@ -43,7 +44,7 @@ http://www.filesonic.com/file/yU2cU6s http://www.fshare.vn/file/A7H8LSTP7Z/ http://ifile.it/muwgivz http://letitbit.net/download/67793.60a7d3745791db7271a6e6c92cfe/Mořská_želva_(_Зелёная_черепаха_.___綠蠵龜___-_Đồi_mồi_dứa_).tar.html -http://www.mediafire.com/?n09th58z1x5r585 +http://www.mediafire.com/file/n09th58z1x5r585 http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB http://www.uloz.to/12553820/morska-zelva-oi-moi-dua-tar -http://www.wupload.com/file/2642593407/ +http://www.wupload.com/file/2642593407/ \ No newline at end of file -- cgit v1.2.3 From 00ea635a0528619c0ff2f09e8781418f4207504e Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 21:07:09 +0100 Subject: unicode fix --- tests/HosterPluginTester.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 23e9507f1..2dd674367 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -96,6 +96,7 @@ class HosterPluginTester(PluginTester): c = Core() +# decode everything as unicode f = codecs.open(join(dirname(__file__), "hosterlinks.txt"), "r", "utf_8") links = [x.strip() for x in f.readlines()] urls = [] @@ -106,12 +107,12 @@ for l in links: if l.startswith("http"): if "||" in l: l, flag = l.split("||") - flags[l] = flag.strip() + flags[l] = str(flag.strip()) urls.append(l) elif len(l.rsplit(" ", 1)) == 2: name, hash = l.rsplit(" ", 1) - HosterPluginTester.files[name] = hash + HosterPluginTester.files[name] = str(hash) hoster, c = c.pluginManager.parseUrls(urls) @@ -147,4 +148,4 @@ for plugin, urls in plugins.iteritems(): #register class locals()[plugin] = _testerClass # remove from locals, or tested twice - del _testerClass \ No newline at end of file + del _testerClass -- cgit v1.2.3 From 7db6de72f2446d8ead6714f25b5e814cb7585b5a Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 21:12:01 +0100 Subject: encoding fix --- tests/HosterPluginTester.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 2dd674367..8e18c3eb9 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from os import remove from os.path import dirname from logging import log, DEBUG from hashlib import md5 @@ -16,7 +15,7 @@ from helper.PluginTester import PluginTester from module.PyFile import PyFile from module.plugins.Base import Fail from module.utils import accumulate -from module.utils.fs import save_join, join, exists, listdir +from module.utils.fs import save_join, join, exists, listdir, remove DL_DIR = join("Downloads", "tmp") @@ -26,8 +25,7 @@ class HosterPluginTester(PluginTester): def setUp(self): PluginTester.setUp(self) for f in self.files: - pass - if exists(join(DL_DIR, f)): remove(join(DL_DIR, f)) + if exists(save_join(DL_DIR, f)): remove(save_join(DL_DIR, f)) # folder for reports report = join("tmp", self.__class__.__name__) -- cgit v1.2.3 From ad2f10b53b5f832c00a4d62b2e655c3268793001 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 21:32:09 +0100 Subject: add os.stat before moveing dl --- tests/HosterPluginTester.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 8e18c3eb9..f4d2c4dc4 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -15,7 +15,7 @@ from helper.PluginTester import PluginTester from module.PyFile import PyFile from module.plugins.Base import Fail from module.utils import accumulate -from module.utils.fs import save_join, join, exists, listdir, remove +from module.utils.fs import save_join, join, exists, listdir, remove, stat DL_DIR = join("Downloads", "tmp") @@ -73,9 +73,11 @@ class HosterPluginTester(PluginTester): if hash.hexdigest() != self.files[pyfile.name]: log(DEBUG, "Hash is %s" % hash.hexdigest()) - - # Copy for debug report - move(f.name, join("tmp", plugin, f.name)) + + size = stat(f.name).st_size + if size < 1024 * 1024 * 10: # 10MB + # Copy for debug report + move(f.name, join("tmp", plugin, f.name)) raise Exception("Hash does not match.") -- cgit v1.2.3 From efc86bbe3e6a97193f061c79f036b9997cadc678 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 16 Jan 2012 21:41:22 +0100 Subject: last fs encoding fix for today --- tests/HosterPluginTester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index f4d2c4dc4..b985c6687 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -15,7 +15,7 @@ from helper.PluginTester import PluginTester from module.PyFile import PyFile from module.plugins.Base import Fail from module.utils import accumulate -from module.utils.fs import save_join, join, exists, listdir, remove, stat +from module.utils.fs import save_join, join, exists, listdir, remove, stat, fs_encode DL_DIR = join("Downloads", "tmp") @@ -77,7 +77,7 @@ class HosterPluginTester(PluginTester): size = stat(f.name).st_size if size < 1024 * 1024 * 10: # 10MB # Copy for debug report - move(f.name, join("tmp", plugin, f.name)) + move(fs_encode(f.name), fs_encode(join("tmp", plugin, f.name))) raise Exception("Hash does not match.") -- cgit v1.2.3 From 3de98e43da6bc9bcf323ab258a0c1d0d046009e3 Mon Sep 17 00:00:00 2001 From: zoidberg10 Date: Mon, 16 Jan 2012 23:28:47 +0100 Subject: hosterlinks - fix md5 hash --- tests/HosterPluginTester.py | 2 +- tests/hosterlinks.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index b985c6687..ad71be0d2 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -64,7 +64,7 @@ class HosterPluginTester(PluginTester): raise Exception("File %s does not exists." % pyfile.name) hash = md5() - f = open(save_join(DL_DIR, pyfile.name)) + f = open(save_join(DL_DIR, pyfile.name), "rb") while True: buf = f.read(4096) if not buf: break diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt index 6ac19f098..70dcc44f6 100755 --- a/tests/hosterlinks.txt +++ b/tests/hosterlinks.txt @@ -5,8 +5,8 @@ http://download.pyload.org/random.bin random.bin d76505d0869f9f928a17d42d66326307 -Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 992d0871f7dbbe0e46747f1e37ba9123 -Mořská_želva_(_Зелёная_черепаха_.&+_綠蠵龜__@-_Đồi_mồi_dứa_).tar 992d0871f7dbbe0e46747f1e37ba9123 +Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 932212256dc0b0a1e71c0944eef633a4 +Mořská_želva_(_Зелёная_черепаха_.&+_綠蠵龜__@-_Đồi_mồi_dứa_).tar 932212256dc0b0a1e71c0944eef633a4 # Hoster links, append ||offline or ||fail to mark your expectation -- cgit v1.2.3 From 8b0fafe9dee3bdf60b8cf8639b14c6a06366e029 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 20 Jan 2012 15:26:24 +0100 Subject: plugintester fix --- tests/CrypterPluginTester.py | 6 +++--- tests/HosterPluginTester.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/CrypterPluginTester.py b/tests/CrypterPluginTester.py index ceb58adc5..67e5ddebc 100644 --- a/tests/CrypterPluginTester.py +++ b/tests/CrypterPluginTester.py @@ -15,8 +15,8 @@ class CrypterPluginTester(PluginTester): @nottest def test_plugin(self, name, url, flag): - print "%s: %s" % (name, url) - log(DEBUG, "%s: %s", name, url) + print "%s: %s" % (name, url.encode("utf8")) + log(DEBUG, "%s: %s", name, url.encode("utf8")) plugin = self.core.pluginManager.getPluginClass(name) p = plugin(self.core, None, "") @@ -78,4 +78,4 @@ for plugin, urls in plugins.iteritems(): print url locals()[plugin] = _testerClass - del _testerClass \ No newline at end of file + del _testerClass diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index ad71be0d2..f8a400c6d 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -37,8 +37,8 @@ class HosterPluginTester(PluginTester): @nottest def test_plugin(self, name, url, flag): # Print to stdout to see whats going on - print "%s: %s, %s" % (name, url, flag) - log(DEBUG, "%s: %s, %s", name, url, flag) + print "%s: %s, %s" % (name, url.encode("utf8"), flag) + log(DEBUG, "%s: %s, %s", name, url.encode("utf8"), flag) # url and plugin should be only important thing pyfile = PyFile(self.core, -1, url, url, 0, 0, "", name, 0, 0) -- cgit v1.2.3 From 88fde2ec4ac9f2501ed78e5c994c861c8159af31 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 5 Feb 2012 23:04:43 +0100 Subject: fix in hoster tester --- tests/HosterPluginTester.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index f8a400c6d..8299e362a 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -77,7 +77,8 @@ class HosterPluginTester(PluginTester): size = stat(f.name).st_size if size < 1024 * 1024 * 10: # 10MB # Copy for debug report - move(fs_encode(f.name), fs_encode(join("tmp", plugin, f.name))) + log(DEBUG, "Downloaded file copied to report") + move(f.name, join("tmp", plugin, f.name)) raise Exception("Hash does not match.") -- cgit v1.2.3 From b6753b215aae358d23d42fec736b3f865d923b1b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 6 Feb 2012 10:42:32 +0100 Subject: fix in unit test --- tests/helper/Stubs.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index cfa5d6fdb..ade15f0c4 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -3,6 +3,7 @@ import sys from os.path import abspath, dirname, join from time import strftime +from traceback import format_exc sys.path.append(abspath(join(dirname(__file__), "..", "..", "module", "lib"))) sys.path.append(abspath(join(dirname(__file__), "..", ".."))) @@ -87,6 +88,9 @@ class Core: def getPackage(self, id): return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0) + + def print_exc(self): + log(ERROR, format_exc()) class NoopClass: @@ -115,4 +119,4 @@ class Thread(BaseThread): __builtin__._ = lambda x: x __builtin__.pypath = abspath(join(dirname(__file__), "..", "..")) __builtin__.hookManager = NoopClass() -__builtin__.pyreq = None \ No newline at end of file +__builtin__.pyreq = None -- cgit v1.2.3 From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- tests/helper/BenchmarkTest.py | 66 +++++++++++++ tests/helper/Stubs.py | 11 ++- tests/test_database.py | 171 +++++++++++++++++++++++++++++++++ tests/test_filemanager.py | 214 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 458 insertions(+), 4 deletions(-) create mode 100644 tests/helper/BenchmarkTest.py create mode 100644 tests/test_database.py create mode 100644 tests/test_filemanager.py (limited to 'tests') diff --git a/tests/helper/BenchmarkTest.py b/tests/helper/BenchmarkTest.py new file mode 100644 index 000000000..d28c52959 --- /dev/null +++ b/tests/helper/BenchmarkTest.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- + +from time import time + + +class BenchmarkTest: + + bench = [] + results = {} + + @classmethod + def timestamp(cls, name, a): + t = time() + r = cls.results.get(name, []) + r.append((t-a) * 1000) + cls.results[name] = r + + @classmethod + def benchmark(cls, n=1): + + print "Benchmarking %s" % cls.__name__ + print + + for i in range(n): + cls.collect_results() + + if "setUpClass" in cls.results: + cls.bench.insert(0, "setUpClass") + + if "tearDownClass" in cls.results: + cls.bench.append("tearDownClass") + + length = str(max([len(k) for k in cls.bench]) + 1) + total = 0 + + for k in cls.bench: + v = cls.results[k] + + if len(v) > 1: + print ("%" + length +"s: %s | average: %.2f ms") % (k, ", ".join(["%.2f" % x for x in v]), sum(v)/len(v)) + total += sum(v)/len(v) + else: + print ("%" + length +"s: %.2f ms") % (k, v[0]) + total += v[0] + + print "\ntotal: %.2f ms" % total + + + @classmethod + def collect_results(cls): + if hasattr(cls, "setUpClass"): + a = time() + cls.setUpClass() + cls.timestamp("setUpClass", a) + + obj = cls() + + for f in cls.bench: + a = time() + getattr(obj, "test_" + f)() + cls.timestamp(f, a) + + if hasattr(cls, "tearDownClass"): + a = time() + cls.tearDownClass() + cls.timestamp("tearDownClass", a) \ No newline at end of file diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index ade15f0c4..be2f5052b 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -58,8 +58,8 @@ class Core: def __init__(self): self.log = NoLog() - self.api = self - self.core = self + self.api = self.core = self + self.threadManager = self self.debug = True self.captcha = True self.config = ConfigParser() @@ -67,7 +67,7 @@ class Core: self.requestFactory = RequestFactory(self) __builtin__.pyreq = self.requestFactory self.accountManager = AccountManager() - self.hookManager = self.eventManager = self.interActionManager = NoopClass() + self.addonManager = self.eventManager = self.interActionManager = NoopClass() self.js = JsEngine() self.cache = {} self.packageCache = {} @@ -86,6 +86,9 @@ class Core: def updatePackage(self, *args): pass + def processingIds(self, *args): + return [] + def getPackage(self, id): return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0) @@ -118,5 +121,5 @@ class Thread(BaseThread): __builtin__._ = lambda x: x __builtin__.pypath = abspath(join(dirname(__file__), "..", "..")) -__builtin__.hookManager = NoopClass() +__builtin__.addonManager = NoopClass() __builtin__.pyreq = None diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 000000000..9fe7796a4 --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- + +from collections import defaultdict + +from helper.Stubs import Core +from helper.BenchmarkTest import BenchmarkTest + +from module.database import DatabaseBackend + +# disable asyncronous queries +DatabaseBackend.async = DatabaseBackend.queue + +from random import choice + +class TestDatabase(BenchmarkTest): + bench = ["insert", "insert_links", "insert_many", "get_packages", + "get_files", "get_files_queued", "get_package_childs", "get_package_files", + "get_package_data", "get_file_data", "find_files", "collector", "purge"] + pids = None + fids = None + + @classmethod + def setUpClass(cls): + cls.pids = [-1] + cls.fids = [] + + cls.db = DatabaseBackend(Core()) + cls.db.manager = cls.db.core + cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg") + + cls.db.setup() + cls.db.purgeAll() + + @classmethod + def tearDownClass(cls): + cls.db.purgeAll() + cls.db.shutdown() + + # benchmarker ignore setup + def setUp(self): + self.db.purgeAll() + self.pids = [-1] + self.fids = [] + + self.test_insert(20) + self.test_insert_many() + self.fids = self.db.getAllFiles().keys() + + + def test_insert(self, n=200): + for i in range(n): + pid = self.db.addPackage("name", "folder", choice(self.pids), "password", "site", "comment", 0) + self.pids.append(pid) + + def test_insert_links(self): + for i in range(10000): + fid = self.db.addLink("url %s" % i, "name", "plugin", choice(self.pids)) + self.fids.append(fid) + + def test_insert_many(self): + for pid in self.pids: + self.db.addLinks([("url %s" % i, "plugin") for i in range(50)], pid) + + def test_get_packages(self): + packs = self.db.getAllPackages() + n = len(packs) + assert n == len(self.pids) -1 + + print "Fetched %d packages" % n + self.assert_pack(choice(packs.values())) + + def test_get_files(self): + files = self.db.getAllFiles() + n = len(files) + assert n >= len(self.pids) + + print "Fetched %d files" % n + self.assert_file(choice(files.values())) + + def test_get_files_queued(self): + files = self.db.getAllFiles(unfinished=True) + print "Fetched %d files queued" % len(files) + + def test_delete(self): + pid = choice(self.pids) + self.db.deletePackage(pid) + self.pids.remove(pid) + + def test_get_package_childs(self): + pid = choice(self.pids) + packs = self.db.getAllPackages(root=pid) + + print "Package %d has %d packages" % (pid, len(packs)) + self.assert_pack(choice(packs.values())) + + def test_get_package_files(self): + pid = choice(self.pids) + files = self.db.getAllFiles(package=pid) + + print "Package %d has %d files" % (pid, len(files)) + self.assert_file(choice(files.values())) + + def test_get_package_data(self, stats=False): + pid = choice(self.pids) + p = self.db.getPackageInfo(pid, stats) + self.assert_pack(p) + # test again with stat + if not stats: + self.test_get_package_data(True) + + def test_get_file_data(self): + fid = choice(self.fids) + f = self.db.getFileInfo(fid) + self.assert_file(f) + + def test_find_files(self): + files = self.db.getAllFiles(search="1") + print "Found %s files" % len(files) + f = choice(files.values()) + + assert "1" in f.name + + def test_collector(self): + self.db.deleteCollector() + assert not self.db.getCollector() + + self.db.addCollector("plugin", "package", [("name", 0, 0, "url %d" % i) for i in range(10)]) + coll = self.db.getCollector() + assert len(coll) == 10 + assert coll[0].plugin == "plugin" + assert coll[0].packagename == "package" + assert coll[0].name == "name" + assert "url" in coll[0].url + + self.db.deleteCollector(url="url 1") + assert len(self.db.getCollector()) == 9 + self.db.deleteCollector(package="package") + assert not self.db.getCollector() + + def test_purge(self): + self.db.purgeLinks() + + def assert_file(self, f): + try: + assert f is not None + self.assert_int(f, ("fid", "status", "size", "media", "fileorder", "added", "package")) + assert f.status in range(5) + assert f.media in range(1024) + assert f.package in self.pids + assert f.added > 10 ** 6 # date is usually big integer + except: + print f + raise + + def assert_pack(self, p): + try: + assert p is not None + self.assert_int(p, ("pid", "root", "added", "status", "packageorder")) + assert p.pid in self.pids + assert p.status in range(5) + assert p.root in self.pids + assert p.added > 10 ** 6 + except: + print p + raise + + def assert_int(self, obj, list): + for attr in list: assert type(getattr(obj, attr)) == int + +if __name__ == "__main__": + TestDatabase.benchmark() \ No newline at end of file diff --git a/tests/test_filemanager.py b/tests/test_filemanager.py new file mode 100644 index 000000000..a9c6d3375 --- /dev/null +++ b/tests/test_filemanager.py @@ -0,0 +1,214 @@ +# -*- coding: utf-8 -*- + +from random import choice + +from helper.Stubs import Core +from helper.BenchmarkTest import BenchmarkTest + +from module.database import DatabaseBackend +# disable asyncronous queries +DatabaseBackend.async = DatabaseBackend.queue + +from module.FileManager import FileManager + +class TestFileManager(BenchmarkTest): + bench = ["add_packages", "add_files", "get_files_root", "get", + "get_package_content", "get_package_tree", + "order_package", "order_files", "move"] + + pids = [-1] + count = 100 + + @classmethod + def setUpClass(cls): + c = Core() + # db needs seperate initialisation + cls.db = c.db = DatabaseBackend(c) + cls.db.setup() + cls.db.purgeAll() + + cls.m = cls.db.manager = FileManager(c) + + @classmethod + def tearDownClass(cls): + cls.db.purgeAll() + cls.db.shutdown() + + + # benchmarker ignore setup + def setUp(self): + self.db.purgeAll() + self.pids = [-1] + + self.count = 20 + self.test_add_packages() + self.test_add_files() + + def test_add_packages(self): + for i in range(100): + pid = self.m.addPackage("name", "folder", choice(self.pids), "", "", "", False) + self.pids.append(pid) + + if -1 in self.pids: + self.pids.remove(-1) + + def test_add_files(self): + for pid in self.pids: + self.m.addLinks([("plugin %d" % i, "url %s" % i) for i in range(self.count)], pid) + + count = self.m.getQueueCount() + files = self.count * len(self.pids) + # in test runner files get added twice + assert count == files or count == files * 2 + + def test_get(self): + info = self.m.getPackageInfo(choice(self.pids)) + assert info.stats.linkstotal == self.count + + fid = choice(info.fids) + f = self.m.getFile(fid) + assert f.fid in self.m.files + + f.name = "new name" + f.sync() + finfo = self.m.getFileInfo(fid) + assert finfo is not None + assert finfo.name == "new name" + + p = self.m.getPackage(choice(self.pids)) + assert p is not None + assert p.pid in self.m.packages + p.sync() + + p.delete() + + self.m.getView(-1, True, False) + + + def test_get_files_root(self): + view = self.m.getView(-1, True, False) + + for pid in self.pids: + assert pid in view.packages + + assert len(view.packages) == len(self.pids) + + p = choice(view.packages.values()) + assert len(p.fids) == self.count + assert p.stats.linkstotal == self.count + + + def test_get_package_content(self): + view = self.m.getView(choice(self.pids), False, False) + p = view.root + + assert len(view.packages) == len(p.pids) + for pid in p.pids: assert pid in view.packages + + def test_get_package_tree(self): + view = self.m.getView(choice(self.pids), True, False) + for pid in view.root.pids: assert pid in view.packages + for fid in view.root.fids: assert fid in view.files + + def test_delete(self): + self.m.deleteFile(self.count * 5) + self.m.deletePackage(choice(self.pids)) + + def test_order_package(self): + parent = self.m.addPackage("order", "", -1, "", "", "", False) + self.m.addLinks([("url", "plugin") for i in range(100)], parent) + + pids = [self.m.addPackage("c", "", parent, "", "", "", False) for i in range(5)] + v = self.m.getView(parent, False, False) + self.assert_ordered(pids, 0, 5, v.root.pids, v.packages, True) + + pid = v.packages.keys()[0] + self.assert_pack_ordered(parent, pid, 3) + self.assert_pack_ordered(parent, pid, 0) + self.assert_pack_ordered(parent, pid, 0) + self.assert_pack_ordered(parent, pid, 4) + pid = v.packages.keys()[2] + self.assert_pack_ordered(parent, pid, 4) + self.assert_pack_ordered(parent, pid, 3) + self.assert_pack_ordered(parent, pid, 2) + + + def test_order_files(self): + parent = self.m.addPackage("order", "", -1, "", "", "", False) + self.m.addLinks([("url", "plugin") for i in range(100)], parent) + v = self.m.getView(parent, False, False) + + fids = v.root.fids[10:20] + v = self.assert_files_ordered(parent, fids, 0) + + fids = v.root.fids[20:30] + + self.m.orderFiles(fids, parent, 99) + v = self.m.getView(parent, False, False) + assert fids[-1] == v.root.fids[-1] + assert fids[0] == v.root.fids[90] + self.assert_ordered(fids, 90, 100, v.root.fids, v.files) + + fids = v.root.fids[80:] + v = self.assert_files_ordered(parent, fids, 20) + + self.m.orderFiles(fids, parent, 80) + v = self.m.getView(parent, False, False) + self.assert_ordered(fids, 61, 81, v.root.fids, v.files) + + fids = v.root.fids[50:51] + self.m.orderFiles(fids, parent, 99) + v = self.m.getView(parent, False, False) + self.assert_ordered(fids, 99, 100, v.root.fids, v.files) + + fids = v.root.fids[50:51] + v = self.assert_files_ordered(parent, fids, 0) + + + def assert_files_ordered(self, parent, fids, pos): + fs = [self.m.getFile(choice(fids)) for i in range(5)] + self.m.orderFiles(fids, parent, pos) + v = self.m.getView(parent, False, False) + self.assert_ordered(fids, pos, pos+len(fids), v.root.fids, v.files) + + return v + + def assert_pack_ordered(self, parent, pid, pos): + self.m.orderPackage(pid, pos) + v = self.m.getView(parent, False, False) + self.assert_ordered([pid], pos, pos+1, v.root.pids, v.packages, True) + + # assert that ordering is total, complete with no gaps + def assert_ordered(self, part, start, end, data, dict, pack=False): + assert data[start:end] == part + if pack: + assert sorted([p.packageorder for p in dict.values()]) == range(len(dict)) + assert [dict[pid].packageorder for pid in part] == range(start, end) + else: + assert sorted([f.fileorder for f in dict.values()]) == range(len(dict)) + assert [dict[fid].fileorder for fid in part] == range(start, end) + + + def test_move(self): + + pid = self.pids[-1] + pid2 = self.pids[1] + + self.m.movePackage(pid, -1) + v = self.m.getView(-1, False, False) + + assert v.root.pids[-1] == pid + assert sorted([p.packageorder for p in v.packages.values()]) == range(len(v.packages)) + + v = self.m.getView(pid, False, False) + fids = v.root.fids[10:20] + self.m.moveFiles(fids, pid2) + v = self.m.getView(pid2, False, False) + + assert sorted([f.fileorder for f in v.files.values()]) == range(len(v.files)) + assert len(v.files) == self.count + len(fids) + + + +if __name__ == "__main__": + TestFileManager.benchmark() \ No newline at end of file -- cgit v1.2.3 From 50d4df8b4d48b855bd18e9922355b7f3f2b4da4e Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 20 Mar 2012 14:57:45 +0100 Subject: captcha decrypting for all plugin types, new interaction manager --- tests/helper/Stubs.py | 9 +++++-- tests/test_interactionManager.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/test_interactionManager.py (limited to 'tests') diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index be2f5052b..963efd290 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -67,7 +67,8 @@ class Core: self.requestFactory = RequestFactory(self) __builtin__.pyreq = self.requestFactory self.accountManager = AccountManager() - self.addonManager = self.eventManager = self.interActionManager = NoopClass() + self.addonManager = AddonManager() + self.eventManager = self.interActionManager = NoopClass() self.js = JsEngine() self.cache = {} self.packageCache = {} @@ -100,6 +101,10 @@ class NoopClass: def __getattr__(self, item): return noop +class AddonManager(NoopClass): + def activePlugins(self): + return [] + class AccountManager: def getAccountForPlugin(self, name): @@ -121,5 +126,5 @@ class Thread(BaseThread): __builtin__._ = lambda x: x __builtin__.pypath = abspath(join(dirname(__file__), "..", "..")) -__builtin__.addonManager = NoopClass() +__builtin__.addonManager = AddonManager() __builtin__.pyreq = None diff --git a/tests/test_interactionManager.py b/tests/test_interactionManager.py new file mode 100644 index 000000000..920d84b9d --- /dev/null +++ b/tests/test_interactionManager.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase +from helper.Stubs import Core + +from module.Api import Input, Output +from module.interaction.InteractionManager import InteractionManager + +class TestInteractionManager(TestCase): + + @classmethod + def setUpClass(cls): + cls.core = Core() + + def setUp(self): + self.im = InteractionManager(self.core) + + + def test_notifications(self): + + n = self.im.createNotification("test", "notify") + assert self.im.getNotifications() == [n] + + for i in range(10): + self.im.createNotification("title", "test") + + assert len(self.im.getNotifications()) == 11 + + + def test_captcha(self): + assert self.im.getTask() is None + + t = self.im.newCaptchaTask("1", "", "") + assert t.output == Output.Captcha + self.im.handleTask(t) + assert t is self.im.getTask() + + t2 = self.im.newCaptchaTask("2", "", "") + self.im.handleTask(t2) + + assert self.im.getTask(Output.Query) is None + assert self.im.getTask() is t + + self.im.removeTask(t) + assert self.im.getTask() is t2 + + self.im.getTaskByID(t2.iid) + assert self.im.getTask() is None + + + def test_query(self): + assert self.im.getTask() is None + t = self.im.newQueryTask(Input.Text, None, "text") + assert t.description == "text" + self.im.handleTask(t) + + assert self.im.getTask(Output.Query) is t + assert self.im.getTask(Output.Captcha) is None \ No newline at end of file -- cgit v1.2.3 From 829244a6140763712d50ed046c33f415f2b04301 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 15 May 2012 19:22:34 +0200 Subject: some multiuser db changes --- tests/test_database.py | 59 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/test_database.py b/tests/test_database.py index 9fe7796a4..e3e6b9963 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -18,6 +18,8 @@ class TestDatabase(BenchmarkTest): "get_package_data", "get_file_data", "find_files", "collector", "purge"] pids = None fids = None + owner = 123 + pstatus = 0 @classmethod def setUpClass(cls): @@ -49,22 +51,23 @@ class TestDatabase(BenchmarkTest): def test_insert(self, n=200): for i in range(n): - pid = self.db.addPackage("name", "folder", choice(self.pids), "password", "site", "comment", 0) + pid = self.db.addPackage("name", "folder", choice(self.pids), "password", "site", "comment", self.pstatus, + self.owner) self.pids.append(pid) def test_insert_links(self): for i in range(10000): - fid = self.db.addLink("url %s" % i, "name", "plugin", choice(self.pids)) + fid = self.db.addLink("url %s" % i, "name", "plugin", choice(self.pids), self.owner) self.fids.append(fid) def test_insert_many(self): for pid in self.pids: - self.db.addLinks([("url %s" % i, "plugin") for i in range(50)], pid) + self.db.addLinks([("url %s" % i, "plugin") for i in range(50)], pid, self.owner) def test_get_packages(self): packs = self.db.getAllPackages() n = len(packs) - assert n == len(self.pids) -1 + assert n == len(self.pids) - 1 print "Fetched %d packages" % n self.assert_pack(choice(packs.values())) @@ -121,30 +124,43 @@ class TestDatabase(BenchmarkTest): assert "1" in f.name def test_collector(self): - self.db.deleteCollector() - assert not self.db.getCollector() - - self.db.addCollector("plugin", "package", [("name", 0, 0, "url %d" % i) for i in range(10)]) - coll = self.db.getCollector() - assert len(coll) == 10 - assert coll[0].plugin == "plugin" - assert coll[0].packagename == "package" - assert coll[0].name == "name" - assert "url" in coll[0].url - - self.db.deleteCollector(url="url 1") - assert len(self.db.getCollector()) == 9 - self.db.deleteCollector(package="package") - assert not self.db.getCollector() + self.db.saveCollector(0, "data") + assert self.db.retrieveCollector(0) == "data" + self.db.deleteCollector(0) def test_purge(self): self.db.purgeLinks() + + def test_user_context(self): + self.db.purgeAll() + + p1 = self.db.addPackage("name", "folder", 0, "password", "site", "comment", self.pstatus, 0) + self.db.addLink("url", "name", "plugin", p1, 0) + p2 = self.db.addPackage("name", "folder", 0, "password", "site", "comment", self.pstatus, 1) + self.db.addLink("url", "name", "plugin", p2, 1) + + assert len(self.db.getAllPackages(owner=0)) == 1 == len(self.db.getAllFiles(owner=0)) + assert len(self.db.getAllPackages(root=0, owner=0)) == 1 == len(self.db.getAllFiles(package=p1, owner=0)) + assert len(self.db.getAllPackages(owner=1)) == 1 == len(self.db.getAllFiles(owner=1)) + assert len(self.db.getAllPackages(root=0, owner=1)) == 1 == len(self.db.getAllFiles(package=p2, owner=1)) + assert len(self.db.getAllPackages()) == 2 == len(self.db.getAllFiles()) + + self.db.deletePackage(p1, 1) + assert len(self.db.getAllPackages(owner=0)) == 1 == len(self.db.getAllFiles(owner=0)) + self.db.deletePackage(p1, 0) + assert len(self.db.getAllPackages(owner=1)) == 1 == len(self.db.getAllFiles(owner=1)) + self.db.deletePackage(p2) + + assert len(self.db.getAllPackages()) == 0 + + def assert_file(self, f): try: assert f is not None - self.assert_int(f, ("fid", "status", "size", "media", "fileorder", "added", "package")) + self.assert_int(f, ("fid", "status", "size", "media", "fileorder", "added", "package", "owner")) assert f.status in range(5) + assert f.owner == self.owner assert f.media in range(1024) assert f.package in self.pids assert f.added > 10 ** 6 # date is usually big integer @@ -155,8 +171,9 @@ class TestDatabase(BenchmarkTest): def assert_pack(self, p): try: assert p is not None - self.assert_int(p, ("pid", "root", "added", "status", "packageorder")) + self.assert_int(p, ("pid", "root", "added", "status", "packageorder", "owner")) assert p.pid in self.pids + assert p.owner == self.owner assert p.status in range(5) assert p.root in self.pids assert p.added > 10 ** 6 -- cgit v1.2.3 From 0d2d6daef850ac6bcc7fafccd230e52d2a862c2c Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 3 Jun 2012 17:45:10 +0200 Subject: updates for database + api --- tests/HosterPluginTester.py | 4 ++-- tests/helper/Stubs.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 8299e362a..627494a3f 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -12,10 +12,10 @@ from nose.tools import nottest from helper.Stubs import Core from helper.PluginTester import PluginTester -from module.PyFile import PyFile +from module.datatypes.PyFile import PyFile from module.plugins.Base import Fail from module.utils import accumulate -from module.utils.fs import save_join, join, exists, listdir, remove, stat, fs_encode +from module.utils.fs import save_join, join, exists, listdir, remove, stat DL_DIR = join("Downloads", "tmp") diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index 963efd290..ac4a41605 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -10,7 +10,7 @@ sys.path.append(abspath(join(dirname(__file__), "..", ".."))) import __builtin__ -from module.PyPackage import PyPackage +from module.datatypes.PyPackage import PyPackage from module.threads.BaseThread import BaseThread from module.config.ConfigParser import ConfigParser from module.network.RequestFactory import RequestFactory -- cgit v1.2.3 From cbd4f4b5375f89362733e10a9b98e5a74c2a5734 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 31 Aug 2012 23:25:26 +0200 Subject: first js models/views --- tests/test_database.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test_database.py b/tests/test_database.py index e3e6b9963..b7408e213 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -154,6 +154,12 @@ class TestDatabase(BenchmarkTest): assert len(self.db.getAllPackages()) == 0 + def test_count(self): + self.db.purgeAll() + + assert self.db.filecount() == 0 + assert self.db.queuecount() == 0 + assert self.db.proccesscount() == 0 def assert_file(self, f): try: -- cgit v1.2.3 From 560958b70043ea5b7e0e32d41cb51bd44696d775 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 9 Sep 2012 15:39:50 +0200 Subject: new config api --- tests/test_configparser.py | 30 ++++++++++++++++++++++++++++++ tests/test_filemanager.py | 28 ++++++++++++++-------------- 2 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 tests/test_configparser.py (limited to 'tests') diff --git a/tests/test_configparser.py b/tests/test_configparser.py new file mode 100644 index 000000000..29ba9e51b --- /dev/null +++ b/tests/test_configparser.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from collections import defaultdict +from helper.Stubs import Core + +from module.database import DatabaseBackend +from module.config.ConfigParser import ConfigParser + +# TODO +class TestConfigParser(): + + @classmethod + def setUpClass(cls): + cls.db = DatabaseBackend(Core()) + cls.db.manager = cls.db.core + cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg") + cls.config = ConfigParser + + + def test_db(self): + pass + + def test_dict(self): + pass + + def test_config(self): + pass + + def test_userconfig(self): + pass \ No newline at end of file diff --git a/tests/test_filemanager.py b/tests/test_filemanager.py index a9c6d3375..f5bdd9df3 100644 --- a/tests/test_filemanager.py +++ b/tests/test_filemanager.py @@ -82,11 +82,11 @@ class TestFileManager(BenchmarkTest): p.delete() - self.m.getView(-1, True, False) + self.m.getTree(-1, True, False) def test_get_files_root(self): - view = self.m.getView(-1, True, False) + view = self.m.getTree(-1, True, False) for pid in self.pids: assert pid in view.packages @@ -99,14 +99,14 @@ class TestFileManager(BenchmarkTest): def test_get_package_content(self): - view = self.m.getView(choice(self.pids), False, False) + view = self.m.getTree(choice(self.pids), False, False) p = view.root assert len(view.packages) == len(p.pids) for pid in p.pids: assert pid in view.packages def test_get_package_tree(self): - view = self.m.getView(choice(self.pids), True, False) + view = self.m.getTree(choice(self.pids), True, False) for pid in view.root.pids: assert pid in view.packages for fid in view.root.fids: assert fid in view.files @@ -119,7 +119,7 @@ class TestFileManager(BenchmarkTest): self.m.addLinks([("url", "plugin") for i in range(100)], parent) pids = [self.m.addPackage("c", "", parent, "", "", "", False) for i in range(5)] - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) self.assert_ordered(pids, 0, 5, v.root.pids, v.packages, True) pid = v.packages.keys()[0] @@ -136,7 +136,7 @@ class TestFileManager(BenchmarkTest): def test_order_files(self): parent = self.m.addPackage("order", "", -1, "", "", "", False) self.m.addLinks([("url", "plugin") for i in range(100)], parent) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) fids = v.root.fids[10:20] v = self.assert_files_ordered(parent, fids, 0) @@ -144,7 +144,7 @@ class TestFileManager(BenchmarkTest): fids = v.root.fids[20:30] self.m.orderFiles(fids, parent, 99) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) assert fids[-1] == v.root.fids[-1] assert fids[0] == v.root.fids[90] self.assert_ordered(fids, 90, 100, v.root.fids, v.files) @@ -153,12 +153,12 @@ class TestFileManager(BenchmarkTest): v = self.assert_files_ordered(parent, fids, 20) self.m.orderFiles(fids, parent, 80) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) self.assert_ordered(fids, 61, 81, v.root.fids, v.files) fids = v.root.fids[50:51] self.m.orderFiles(fids, parent, 99) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) self.assert_ordered(fids, 99, 100, v.root.fids, v.files) fids = v.root.fids[50:51] @@ -168,14 +168,14 @@ class TestFileManager(BenchmarkTest): def assert_files_ordered(self, parent, fids, pos): fs = [self.m.getFile(choice(fids)) for i in range(5)] self.m.orderFiles(fids, parent, pos) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) self.assert_ordered(fids, pos, pos+len(fids), v.root.fids, v.files) return v def assert_pack_ordered(self, parent, pid, pos): self.m.orderPackage(pid, pos) - v = self.m.getView(parent, False, False) + v = self.m.getTree(parent, False, False) self.assert_ordered([pid], pos, pos+1, v.root.pids, v.packages, True) # assert that ordering is total, complete with no gaps @@ -195,15 +195,15 @@ class TestFileManager(BenchmarkTest): pid2 = self.pids[1] self.m.movePackage(pid, -1) - v = self.m.getView(-1, False, False) + v = self.m.getTree(-1, False, False) assert v.root.pids[-1] == pid assert sorted([p.packageorder for p in v.packages.values()]) == range(len(v.packages)) - v = self.m.getView(pid, False, False) + v = self.m.getTree(pid, False, False) fids = v.root.fids[10:20] self.m.moveFiles(fids, pid2) - v = self.m.getView(pid2, False, False) + v = self.m.getTree(pid2, False, False) assert sorted([f.fileorder for f in v.files.values()]) == range(len(v.files)) assert len(v.files) == self.count + len(fids) -- cgit v1.2.3 From 54bc92b4c5e0b3543a313f497cbc2276403c5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 10 Sep 2012 11:49:35 +0200 Subject: changed config + progress api --- tests/helper/Stubs.py | 2 +- tests/test_configparser.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index ac4a41605..5c44cfb58 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -14,7 +14,7 @@ from module.datatypes.PyPackage import PyPackage from module.threads.BaseThread import BaseThread from module.config.ConfigParser import ConfigParser from module.network.RequestFactory import RequestFactory -from module.plugins.PluginManager import PluginManager +from module.PluginManager import PluginManager from module.common.JsEngine import JsEngine from logging import log, DEBUG, INFO, WARN, ERROR diff --git a/tests/test_configparser.py b/tests/test_configparser.py index 29ba9e51b..d797c7912 100644 --- a/tests/test_configparser.py +++ b/tests/test_configparser.py @@ -14,14 +14,32 @@ class TestConfigParser(): cls.db = DatabaseBackend(Core()) cls.db.manager = cls.db.core cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg") - cls.config = ConfigParser + cls.config = ConfigParser() + cls.db.setup() + cls.db.clearAllConfigs() def test_db(self): - pass + + self.db.saveConfig("plugin", "some value", 0) + self.db.saveConfig("plugin", "some other value", 1) + + assert self.db.loadConfig("plugin", 0) == "some value" + assert self.db.loadConfig("plugin", 1) == "some other value" + + d = self.db.loadAllConfigs() + assert d[0]["plugin"] == "some value" + + self.db.deleteConfig("plugin") + + assert not self.db.loadAllConfigs() + def test_dict(self): - pass + + assert self.config["general"]["language"] + self.config["general"]["language"] = "de" + assert self.config["general"]["language"] == "de" def test_config(self): pass -- cgit v1.2.3