summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CrypterPluginTester.py71
-rw-r--r--tests/HosterPluginTester.py115
-rw-r--r--tests/crypterlinks.txt4
-rw-r--r--tests/helper/PluginTester.py52
-rw-r--r--tests/helper/Stubs.py119
-rw-r--r--tests/helper/__init__.py0
-rwxr-xr-xtests/hosterlinks.txt (renamed from tests/testlinks.txt)24
-rwxr-xr-xtests/plugin_tests.sh5
-rw-r--r--tests/stubs/__init__.py1
-rw-r--r--tests/test_syntax.py5
10 files changed, 376 insertions, 20 deletions
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
--- /dev/null
+++ b/tests/helper/__init__.py
diff --git a/tests/testlinks.txt b/tests/hosterlinks.txt
index 428cf63ea..0da4074dc 100755
--- a/tests/testlinks.txt
+++ b/tests/hosterlinks.txt
@@ -1,24 +1,22 @@
-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
----------------------------------------
+# 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
+http://ul.to/file/o41isx||offline
http://rapidshare.com/files/445996776/random.bin
-http://dl.free.fr/d4aL5dyXY
+http://dl.free.fr/d4aL5dyXY||offline
http://www.duckload.com/dl/QggW2
-http://files.mail.ru/32EW66
-http://www.fileserve.com/file/MxjZXjX
+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
+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
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