Browse Source

Basic NZB adding via upload or from disk

pull/1029/head
Safihre 8 years ago
parent
commit
408b84e02d
  1. 4
      .travis.yml
  2. 12
      tests/conftest.py
  3. 20
      tests/data/reftestnzb.nzb
  4. 25
      tests/test_api_pages.py
  5. 58
      tests/test_nzb.py
  6. 8
      tests/testhelper.py

4
.travis.yml

@ -1,6 +1,10 @@
language: python
python:
- "2.7"
before_install:
- sudo add-apt-repository ppa:jcfp -y
- sudo apt-get update -q
- sudo apt-get install sabnzbdplus -y
install:
- pip install --upgrade -r tests/requirements.txt
script:

12
tests/conftest.py

@ -30,7 +30,7 @@ import testhelper
from xprocess import ProcessStarter
@pytest.fixture(scope='session')
def sabnzbd(request, xprocess):
def sabnzbd_connect(request, xprocess):
# Get cache directory
base_path = os.path.dirname(os.path.abspath(__file__))
cache_dir = os.path.join(base_path, 'cache')
@ -58,9 +58,13 @@ def sabnzbd(request, xprocess):
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)
# Takes a second to shutdown
for x in range(5):
try:
shutil.rmtree(cache_dir)
break
except:
time.sleep(1)
request.addfinalizer(shutdown_sabnzbd)
return xprocess.ensure("sabnzbd", Starter)

20
tests/data/reftestnzb.nzb

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file poster="nzbtester5@gmail.com" date="1495557432" subject="RefTestNZB: rar5 8288192_RAR5_FILE.rar ff2f7ca6 - &quot;8288192_RAR5_FILE.rar&quot; yEnc (1/11)">
<groups><group>alt.binaries.boneless</group></groups>
<segments>
<segment bytes="350593" number="1">YyZUA.55279$4Z1.8096@fx31.am4</segment>
<segment bytes="350823" number="2">ZyZUA.55280$4Z1.25561@fx31.am4</segment>
<segment bytes="350639" number="3">ZyZUA.55281$4Z1.11063@fx31.am4</segment>
<segment bytes="350732" number="4">_yZUA.55282$4Z1.16876@fx31.am4</segment>
<segment bytes="350700" number="5">_yZUA.55283$4Z1.13779@fx31.am4</segment>
<segment bytes="350608" number="6">%yZUA.55284$4Z1.46223@fx31.am4</segment>
<segment bytes="350828" number="7">0zZUA.55285$4Z1.6649@fx31.am4</segment>
<segment bytes="119105" number="11">2zZUA.55289$4Z1.25108@fx31.am4</segment>
<segment bytes="350796" number="8">0zZUA.55286$4Z1.37644@fx31.am4</segment>
<segment bytes="350756" number="9">1zZUA.55287$4Z1.2275@fx31.am4</segment>
<segment bytes="350656" number="10">2zZUA.55288$4Z1.18213@fx31.am4</segment>
</segments>
</file>
</nzb>

25
tests/test_startup.py → tests/test_api_pages.py

@ -16,26 +16,37 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
tests.test_startup - The most basic testing if things work
tests.test_api_pages - The most basic testing if things work
"""
import pytest
import testhelper
def test_main_pages(sabnzbd):
def test_basic_api(sabnzbd_connect):
# 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')
def test_main_pages(sabnzbd_connect):
# 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):
def test_wizard_pages(sabnzbd_connect):
# 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):
def test_config_pages(sabnzbd_connect):
# Test if config pages work
assert 'Traceback' not in testhelper.get_url_result('config')
assert 'Traceback' not in testhelper.get_url_result('config/general')
@ -48,9 +59,3 @@ def test_config_pages(sabnzbd):
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')

58
tests/test_nzb.py

@ -0,0 +1,58 @@
#!/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_nzb - Basic NZB adding support
"""
import os
import pytest
import testhelper
# Where are we now?
base_path = os.path.dirname(os.path.abspath(__file__))
def nzo_in_queue(nzo_response):
""" Helper function for checking if file is in queue and then remove it """
queue_res = testhelper.get_api_result('queue')
nzo_id = nzo_response['nzo_ids'][0]
# Was it added?
assert nzo_response['status'] == True
assert queue_res['queue']['slots'][0]['nzo_id'] == nzo_response['nzo_ids'][0]
# Let's remove it
remove_response = testhelper.get_api_result('queue', {'name': 'delete', 'value': nzo_id})
assert nzo_response['status'] == True
# Really gone?
queue_res = testhelper.get_api_result('queue')
assert not queue_res['queue']['slots']
def test_addfile(sabnzbd_connect):
# See if basic upload works
nzo_response = testhelper.upload_nzb(os.path.join(base_path, 'data', 'reftestnzb.nzb'))
nzo_in_queue(nzo_response)
def test_addlocalfile(sabnzbd_connect):
# See if basic adding from disk-file works
nzo_response = testhelper.get_api_result('addlocalfile', {'name': os.path.join(base_path, 'data', 'reftestnzb.nzb')})
nzo_in_queue(nzo_response)

8
tests/testhelper.py

@ -42,9 +42,7 @@ def get_api_result(mode, extra_arguments={}):
def upload_nzb(file):
""" Upload file and return request to queue-API call """
""" Upload file and return nzo_id reponse """
files = {'name': open(file, 'rb')}
arguments ={'apikey':'apikey', 'mode':'addfile'}
requests.post(url, files=files, data=arguments)
# Return what the queue looks like now
return get_api_result('queue')
arguments ={'apikey':'apikey', 'mode':'addfile', 'output': 'json'}
return requests.post('http://%s:%s/api' % (SAB_HOST, SAB_PORT), files=files, data=arguments).json()

Loading…
Cancel
Save