Browse Source

Improve automated download-testing

- Catch all Selenium exceptions while waiting for the download to complete
- Correctly set autodisconnect=0
- Make job-name even more unique
- Wait for the RSS-added job to finish fetching
- Move sabnzbd.basic.ini to data folder
- Use new SAB_DATA_DIR
- Optimized imports
pull/1516/head
Safihre 5 years ago
parent
commit
92efc9ed8a
  1. 4
      tests/conftest.py
  2. 2
      tests/data/sabnzbd.basic.ini
  3. 7
      tests/sabnews.py
  4. 6
      tests/test_filesystem.py
  5. 8
      tests/test_functional_config.py
  6. 12
      tests/test_functional_downloads.py
  7. 4
      tests/test_functional_misc.py
  8. 12
      tests/test_postproc.py
  9. 6
      tests/test_urlgrabber.py
  10. 1
      tests/test_utils/test_happyeyeballs.py
  11. 5
      tests/test_utils/test_sleepless.py
  12. 1
      tests/test_win_utils.py
  13. 7
      tests/testhelper.py

4
tests/conftest.py

@ -20,8 +20,6 @@ tests.conftest - Setup pytest fixtures
These have to be separate otherwise SABnzbd is started multiple times!
"""
import shutil
import subprocess
import sys
from tests.testhelper import *
@ -34,7 +32,7 @@ def start_sabnzbd():
# Copy basic config file with API key
os.makedirs(SAB_CACHE_DIR, exist_ok=True)
shutil.copyfile(os.path.join(SAB_BASE_DIR, "sabnzbd.basic.ini"), os.path.join(SAB_CACHE_DIR, "sabnzbd.ini"))
shutil.copyfile(os.path.join(SAB_DATA_DIR, "sabnzbd.basic.ini"), os.path.join(SAB_CACHE_DIR, "sabnzbd.ini"))
# Check if we have language files
if not os.path.exists(os.path.join(SAB_BASE_DIR, "..", "locale")):

2
tests/sabnzbd.basic.ini → tests/data/sabnzbd.basic.ini

@ -2,4 +2,4 @@ __version__ = 19
__encoding__ = utf-8
[misc]
api_key = apikey
autodisconnect = 0
auto_disconnect = 0

7
tests/sabnews.py

@ -22,13 +22,14 @@ Run sabnews.py -h for parameters!
"""
import argparse
import asyncio
import logging
import os
import re
import time
import sabyenc3
import argparse
import asyncio
import logging
logging.getLogger().setLevel(logging.INFO)

6
tests/test_filesystem.py

@ -18,16 +18,14 @@
"""
tests.test_filesystem - Testing functions in filesystem.py
"""
import os
import stat
import pyfakefs.fake_filesystem_unittest as ffs
import sabnzbd.filesystem as filesystem
import sabnzbd.cfg
import sabnzbd.filesystem as filesystem
from tests.testhelper import *
# Set the global uid for fake filesystems to a non-root user;
# by default this depends on the user running pytest.
global_uid = 1000

8
tests/test_functional_config.py

@ -217,15 +217,17 @@ class SABnzbdConfigRSS(SABnzbdBaseTest):
# Does the page think it's a success?
assert "Added NZB" in download_btn.text
# Let's check the queue, it can take 10 seconds to fetch the URL
for _ in range(10):
# Let's check the queue, it can take 60 seconds to fetch the URL in case it needs a retry
for _ in range(60):
queue_result_slots = get_api_result("queue")["queue"]["slots"]
if len(queue_result_slots) == 1:
# Wait until fetched, then it will not have a label anymore
if queue_result_slots and not queue_result_slots[0]["labels"]:
break
time.sleep(1)
else:
# The loop never stopped, so we fail
pytest.fail("Did not find the RSS job in the queue")
return
# Let's remove this thing
get_api_result("queue", extra_arguments={"name": "delete", "value": queue_result_slots[0]["nzo_id"]})

12
tests/test_functional_downloads.py

@ -19,9 +19,6 @@
tests.test_functional_downloads - Test the downloading flow
"""
import random
from selenium.common.exceptions import NoSuchElementException
from tests.testhelper import *
@ -49,11 +46,6 @@ class SABnzbdDownloadFlow(SABnzbdBaseTest):
# This will fail if the translations failed to compile!
self.selenium_wrapper(self.driver.find_element_by_partial_link_text, "Advanced Settings").click()
# Lower number of connections to prevent testing errors
pass_inp = self.selenium_wrapper(self.driver.find_element_by_name, "connections")
pass_inp.clear()
pass_inp.send_keys(4)
# Change port
port_inp = self.selenium_wrapper(self.driver.find_element_by_name, "port")
port_inp.clear()
@ -81,7 +73,7 @@ class SABnzbdDownloadFlow(SABnzbdBaseTest):
nzb_path = create_nzb(nzb_dir)
# Add NZB
test_job_name = "testfile_%s" % int(time.time())
test_job_name = "testfile_%s" % time.time()
api_result = get_api_result("addlocalfile", extra_arguments={"name": nzb_path, "nzbname": test_job_name})
assert api_result["status"]
@ -103,7 +95,7 @@ class SABnzbdDownloadFlow(SABnzbdBaseTest):
break
else:
time.sleep(1)
except NoSuchElementException:
except WebDriverException:
time.sleep(1)
else:
self.fail("Download did not complete")

4
tests/test_functional_misc.py

@ -19,8 +19,6 @@
tests.test_functional_misc - Functional tests of various functions
"""
import shutil
import subprocess
import sys
import sabnzbd.encoding
from tests.testhelper import *
@ -121,7 +119,7 @@ class TestDaemonizing(SABnzbdBaseTest):
# We need the basic-config to set the API-key
# Otherwise we can't shut it down at the end
shutil.copyfile(os.path.join(SAB_BASE_DIR, "sabnzbd.basic.ini"), os.path.join(ini_location, "sabnzbd.ini"))
shutil.copyfile(os.path.join(SAB_DATA_DIR, "sabnzbd.basic.ini"), os.path.join(ini_location, "sabnzbd.ini"))
# Combine it all into the script call
script_call = [

12
tests/test_postproc.py

@ -8,12 +8,12 @@
tests.test_postproc- Tests of various functions in newspack, among which rar_renamer()
"""
import pytest
import shutil
from distutils.dir_util import copy_tree
from unittest import mock
from sabnzbd.postproc import *
from tests.testhelper import *
class TestPostProc:
@ -23,10 +23,6 @@ class TestPostProc:
# Function to deobfuscate one directorty with rar_renamer()
def deobfuscate_dir(sourcedir, expected_filename_matches):
# sourcedir is the relative path to the directory with obfuscated files
# enrich to absolute path:
sourcedir = os.path.join(os.getcwd(), sourcedir)
# We create a workingdir inside the sourcedir, because the filenames are really changed
workingdir = os.path.join(sourcedir, "workingdir")
@ -64,17 +60,17 @@ class TestPostProc:
return number_renamed_files
# obfuscated, single rar set
sourcedir = os.path.join("tests", "data", "obfuscated_single_rar_set")
sourcedir = os.path.join(SAB_DATA_DIR, "obfuscated_single_rar_set")
# Now define the filematches we want to see, in which amount ("*-*-*-*-*" are the input files):
expected_filename_matches = {"*part007.rar": 1, "*-*-*-*-*": 0}
assert deobfuscate_dir(sourcedir, expected_filename_matches) == 7
# obfuscated, two rar sets
sourcedir = os.path.join("tests", "data", "obfuscated_two_rar_sets")
sourcedir = os.path.join(SAB_DATA_DIR, "obfuscated_two_rar_sets")
expected_filename_matches = {"*part007.rar": 2, "*part009.rar": 1, "*-*-*-*-*": 0}
assert deobfuscate_dir(sourcedir, expected_filename_matches) == 16
# obfuscated, but not a rar set
sourcedir = os.path.join("tests", "data", "obfuscated_but_no_rar")
sourcedir = os.path.join(SAB_DATA_DIR, "obfuscated_but_no_rar")
expected_filename_matches = {"*.rar": 0, "*-*-*-*-*": 6}
assert deobfuscate_dir(sourcedir, expected_filename_matches) == 0

6
tests/test_urlgrabber.py

@ -18,15 +18,15 @@
"""
tests.test_urlgrabber - Testing functions in urlgrabber.py
"""
import json
import urllib.error
import urllib.parse
import pytest_httpbin
import json
import sabnzbd.urlgrabber as urlgrabber
from sabnzbd.cfg import selftest_host
import sabnzbd.version
from sabnzbd.cfg import selftest_host
from tests.testhelper import *

1
tests/test_utils/test_happyeyeballs.py

@ -20,6 +20,7 @@ tests.test_utils.test_happyeyeballs - Testing SABnzbd happyeyeballs
"""
from flaky import flaky
from sabnzbd.utils.happyeyeballs import happyeyeballs

5
tests/test_utils/test_sleepless.py

@ -19,10 +19,11 @@
tests.test_sleepless - Test sleepless for macOS
"""
import subprocess
import sys
import pytest
import time
import subprocess
import pytest
if not sys.platform.startswith("darwin"):
pytest.skip("Skipping macOS-only tests", allow_module_level=True)

1
tests/test_win_utils.py

@ -20,6 +20,7 @@ tests.test_win_utils - Testing Windows utils
"""
import sys
import pytest
if not sys.platform.startswith("win"):

7
tests/testhelper.py

@ -28,21 +28,22 @@ from http.client import RemoteDisconnected
import pytest
import requests
import tests.sabnews
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from urllib3.exceptions import ProtocolError
import sabnzbd
import sabnzbd.cfg as cfg
import tests.sabnews
SAB_HOST = "localhost"
SAB_PORT = 8081
SAB_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
SAB_CACHE_DIR = os.path.join(SAB_BASE_DIR, "cache")
SAB_DATA_DIR = os.path.join(SAB_BASE_DIR, "data")
SAB_COMPLETE_DIR = os.path.join(SAB_CACHE_DIR, "Downloads", "complete")
SAB_NEWSSERVER_HOST = "127.0.0.1"
SAB_NEWSSERVER_PORT = 8888
@ -125,7 +126,7 @@ def start_sabnews():
def create_nzb(nzb_dir):
""" Create NZB from directory using SABNews """
nzb_dir_full = os.path.join(SAB_BASE_DIR, "data", nzb_dir)
nzb_dir_full = os.path.join(SAB_DATA_DIR, nzb_dir)
return tests.sabnews.create_nzb(nzb_dir=nzb_dir_full)

Loading…
Cancel
Save