summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-14 15:49:08 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-01-14 15:49:08 +0100
commit828cc89cc9b7a2ecacf98fc73928d988e15f0b98 (patch)
tree5cbf3274b7bfe365a89442f26fbfe230311d3785 /tests
parentcosmetic fixes (diff)
downloadpyload-828cc89cc9b7a2ecacf98fc73928d988e15f0b98.tar.xz
captcha and attachments for plugin tester
Diffstat (limited to 'tests')
-rw-r--r--tests/HosterPluginTester.py18
-rw-r--r--tests/helper/PluginTester.py118
-rwxr-xr-xtests/hosterlinks.txt19
-rwxr-xr-xtests/quit_pyload.sh3
-rw-r--r--tests/test_syntax.py1
5 files changed, 137 insertions, 22 deletions
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