summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-10 20:48:38 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-10 20:48:38 +0100
commitc484268fbef4ef07455eb856d3924224c784d3e2 (patch)
tree9792966733612bd5ace2b9837ddc5bf24a00db07
parentmegaupload #451, uploadedto #443 (diff)
downloadpyload-c484268fbef4ef07455eb856d3924224c784d3e2.tar.xz
little test cases
-rw-r--r--module/common/APIExerciser.py16
-rw-r--r--module/database/FileDatabase.py2
-rw-r--r--pavement.py9
-rw-r--r--tests/test_api.py20
-rw-r--r--tests/test_json.py48
5 files changed, 86 insertions, 9 deletions
diff --git a/module/common/APIExerciser.py b/module/common/APIExerciser.py
index 7cc30c6a1..f782efa53 100644
--- a/module/common/APIExerciser.py
+++ b/module/common/APIExerciser.py
@@ -36,7 +36,7 @@ def startApiExerciser(core, n):
class APIExerciser(Thread):
- def __init__(self, core, thrift=False):
+ def __init__(self, core, thrift=False, user=None, pw=None):
global idPool
Thread.__init__(self)
@@ -46,18 +46,19 @@ class APIExerciser(Thread):
self.time = time()
if thrift:
- self.api = ThriftClient()
- self.api.login("user", "pw")
+ self.api = ThriftClient(user=user, password=pw)
else:
self.api = core.api
self.id = idPool
- self.core.log.info("API Excerciser started %d" % self.id)
+ if core:
+ self.core.log.info("API Excerciser started %d" % self.id)
+
idPool += 1
- self.start()
+ #self.start()
def run(self):
out = open("error.log", "ab")
@@ -150,4 +151,7 @@ class APIExerciser(Thread):
self.api.getPackageData(choice(info).pid)
def getAccounts(self):
- self.api.getAccounts(False) \ No newline at end of file
+ self.api.getAccounts(False)
+
+ def getCaptchaTask(self):
+ self.api.getCaptchaTask(False) \ No newline at end of file
diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py
index 564fc4562..d51241591 100644
--- a/module/database/FileDatabase.py
+++ b/module/database/FileDatabase.py
@@ -175,7 +175,7 @@ class FileHandler:
packs = self.packageCache.values()
for pack in packs:
- if pack.queue != queue and p.order < oldorder:
+ if pack.queue == p.queue and p.order < oldorder:
pack.order -= 1
pack.notifyChange()
diff --git a/pavement.py b/pavement.py
index 618617ef0..e2ac10b81 100644
--- a/pavement.py
+++ b/pavement.py
@@ -25,18 +25,19 @@ setup(
version="0.4.9",
description='Fast, lightweight and full featured download manager.',
long_description=open(PROJECT_DIR / "README").read(),
- keywords='',
+ keywords = ('pyload', 'download-manager', 'one-click-hoster', 'download'),
url="http://pyload.org",
download_url='http://pyload.org/download',
license='GPL v3',
author="pyLoad Team",
author_email="support@pyload.org",
+ platforms = ('Any',),
#package_dir={'pyload': 'src'},
packages=['pyload'],
#package_data=find_package_data(),
#data_files=[],
include_package_data=True,
- exclude_package_data={'pyload': ['docs*', 'scripts*']}, #exluced from build but not from sdist
+ exclude_package_data={'pyload': ['docs*', 'scripts*', 'tests*']}, #exluced from build but not from sdist
# 'bottle >= 0.10.0' not in list, because its small and contain little modifications
install_requires=['thrift >= 0.8.0', 'jinja2', 'pycurl', 'Beaker', 'BeautifulSoup>=3.2, <3.3'] + extradeps,
extras_require={
@@ -232,6 +233,10 @@ def generate_locale():
@task
+def tests():
+ call(["nosetests2"])
+
+@task
def virtualenv(options):
"""Setup virtual environment"""
if path(options.dir).exists():
diff --git a/tests/test_api.py b/tests/test_api.py
new file mode 100644
index 000000000..f8901f731
--- /dev/null
+++ b/tests/test_api.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+
+from module.common import APIExerciser
+from nose.tools import nottest
+
+
+class TestApi:
+
+ def __init__(self):
+ self.api = APIExerciser.APIExerciser(None, True, "TestUser", "pwhere")
+
+ def test_login(self):
+ assert self.api.api.login("crapp", "wrong pw") is False
+
+ #takes really long, only test when needed
+ @nottest
+ def test_random(self):
+
+ for i in range(0, 100):
+ self.api.testAPI()
diff --git a/tests/test_json.py b/tests/test_json.py
new file mode 100644
index 000000000..ff56e8f5a
--- /dev/null
+++ b/tests/test_json.py
@@ -0,0 +1,48 @@
+# -*- 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": "pwhere"}))
+ 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 \ No newline at end of file