6 changed files with 170 additions and 16 deletions
@ -1,16 +0,0 @@ |
|||
import six |
|||
|
|||
import mock |
|||
|
|||
from cherrypy import wsgiserver |
|||
|
|||
|
|||
class TestWSGIGateway_u0: |
|||
@mock.patch('cherrypy.wsgiserver.WSGIGateway_10.get_environ', |
|||
lambda self: {'foo': 'bar'}) |
|||
def test_decodes_items(self): |
|||
req = mock.MagicMock(path=b'/', qs=b'') |
|||
gw = wsgiserver.WSGIGateway_u0(req=req) |
|||
env = gw.get_environ() |
|||
assert env['foo'] == 'bar' |
|||
assert isinstance(env['foo'], six.text_type) |
@ -0,0 +1,67 @@ |
|||
#!/usr/bin/python -OO |
|||
# Copyright 2008-2017 The SABnzbd-Team <team@sabnzbd.org> |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|||
|
|||
""" |
|||
tests.conftest - Wrappers to start SABnzbd for testing |
|||
""" |
|||
|
|||
import os |
|||
import itertools |
|||
import urllib2 |
|||
import pytest |
|||
import shutil |
|||
import time |
|||
import testhelper |
|||
|
|||
from xprocess import ProcessStarter |
|||
|
|||
@pytest.fixture(scope='module') |
|||
def sabnzbd(request, xprocess): |
|||
# Get cache directory |
|||
base_path = os.path.dirname(os.path.abspath(__file__)) |
|||
cache_dir = os.path.join(base_path, 'cache') |
|||
|
|||
# Copy basic config file |
|||
try: |
|||
os.mkdir(cache_dir) |
|||
shutil.copyfile(os.path.join(base_path, 'sabnzbd.basic.ini'), os.path.join(cache_dir, 'sabnzbd.ini')) |
|||
except: |
|||
pass |
|||
|
|||
class Starter(ProcessStarter): |
|||
# Wait for SABnzbd to start |
|||
pattern = "ENGINE Bus STARTED" |
|||
|
|||
# Start without browser and with basic logging |
|||
args = 'python ../../SABnzbd.py -l1 -s %s:%s -b0 -f %s' % (testhelper.SAB_HOST, testhelper.SAB_PORT, cache_dir) |
|||
args = args.split() |
|||
|
|||
# We have to wait a bit longer than default |
|||
def filter_lines(self, lines): |
|||
return itertools.islice(lines, 500) |
|||
|
|||
# Shut it down at the end |
|||
def shutdown_sabnzbd(): |
|||
# Gracefull shutdown request |
|||
testhelper.get_url_result('shutdown') |
|||
# Wait 5s before removing, to finish shutdown |
|||
time.sleep(5) |
|||
shutil.rmtree(cache_dir) |
|||
request.addfinalizer(shutdown_sabnzbd) |
|||
|
|||
return xprocess.ensure("sabnzbd", Starter) |
|||
|
@ -0,0 +1,11 @@ |
|||
__version__ = 19 |
|||
__encoding__ = utf-8 |
|||
[misc] |
|||
api_key = apikey |
|||
|
|||
[servers] |
|||
[[sabnzbd.test]] |
|||
enable = 1 |
|||
host = sabnzd.test |
|||
username = sabnzbd |
|||
password = sabnzbd |
@ -0,0 +1,56 @@ |
|||
#!/usr/bin/python -OO |
|||
# Copyright 2008-2017 The SABnzbd-Team <team@sabnzbd.org> |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|||
|
|||
""" |
|||
tests.test_startup - The most basic testing if things work |
|||
""" |
|||
|
|||
import pytest |
|||
import testhelper |
|||
|
|||
def test_main_pages(sabnzbd): |
|||
# See if the basic pages work |
|||
assert 'Traceback' not in testhelper.get_url_result() |
|||
assert 'Traceback' not in testhelper.get_url_result('history') |
|||
assert 'Traceback' not in testhelper.get_url_result('queue') |
|||
assert 'Traceback' not in testhelper.get_url_result('status') |
|||
|
|||
def test_wizard_pages(sabnzbd): |
|||
# Test if wizard pages work |
|||
assert 'Traceback' not in testhelper.get_url_result('wizard') |
|||
assert 'Traceback' not in testhelper.get_url_result('wizard/one') |
|||
assert 'Traceback' not in testhelper.get_url_result('wizard/two') |
|||
|
|||
def test_config_pages(sabnzbd): |
|||
# Test if config pages work |
|||
assert 'Traceback' not in testhelper.get_url_result('config') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/general') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/server') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/categories') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/switches') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/sorting') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/notify') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/scheduling') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/rss') |
|||
assert 'Traceback' not in testhelper.get_url_result('config/special') |
|||
|
|||
def test_basic_api(sabnzbd): |
|||
# Basic API test |
|||
assert 'queue' in testhelper.get_api_result('queue') |
|||
assert 'history' in testhelper.get_api_result('history') |
|||
assert 'status' in testhelper.get_api_result('fullstatus') |
|||
assert 'config' in testhelper.get_api_result('get_config') |
@ -0,0 +1,32 @@ |
|||
#!/usr/bin/python -OO |
|||
# Copyright 2008-2017 The SABnzbd-Team <team@sabnzbd.org> |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|||
|
|||
""" |
|||
tests.testhelper - Basic helper functions |
|||
""" |
|||
|
|||
import urllib2 |
|||
import json |
|||
|
|||
SAB_HOST = 'localhost' |
|||
SAB_PORT = 8081 |
|||
|
|||
def get_url_result(url=''): |
|||
return urllib2.urlopen('http://%s:%s/%s/?session=apikey' % (SAB_HOST, SAB_PORT, url)).read() |
|||
|
|||
def get_api_result(method='', args=''): |
|||
return json.loads(urllib2.urlopen('http://%s:%s/api?apikey=apikey&output=json&mode=%s&%s' % (SAB_HOST, SAB_PORT, method, args)).read()) |
Loading…
Reference in new issue