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/helper/Stubs.py | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tests/helper/Stubs.py (limited to 'tests/helper/Stubs.py') 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 -- 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/helper/Stubs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/helper/Stubs.py') 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 -- 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/helper/Stubs.py') 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/Stubs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests/helper/Stubs.py') 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 -- 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 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/helper/Stubs.py') 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 -- 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/helper/Stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/helper/Stubs.py') 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 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/helper/Stubs.py') 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 -- cgit v1.2.3