Browse Source

If no newsserver-info, skip tests

pull/1182/head
Safihre 7 years ago
parent
commit
0958caf5ed
  1. 124
      tests/test_functional.py
  2. 21
      tests/testhelper.py

124
tests/test_functional.py

@ -27,6 +27,7 @@ from selenium.common.exceptions import WebDriverException, NoSuchElementExceptio
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from testhelper import *
@ -51,7 +52,8 @@ class SABnzbdBaseTest(unittest.TestCase):
driver_options.headless = True
cls.driver = webdriver.Firefox(firefox_options=driver_options)
# Get the newsserver-info
# Get the newsserver-info, if available
if "SAB_NEWSSERVER_HOST" in os.environ:
cls.newsserver_host = os.environ['SAB_NEWSSERVER_HOST']
cls.newsserver_user = os.environ['SAB_NEWSSERVER_USER']
cls.newsserver_password = os.environ['SAB_NEWSSERVER_PASSWORD']
@ -61,23 +63,26 @@ class SABnzbdBaseTest(unittest.TestCase):
cls.driver.close()
cls.driver.quit()
def no_page_crash(self):
# Do a base test if CherryPy did not report test
self.assertNotIn('500 Internal Server Error', self.driver.title)
def open_page(self, url):
# Open a page and test for crash
self.driver.get(url)
self.no_page_crash()
def scroll_to_top(self):
self.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
time.sleep(2)
def wait_for_ajax(self):
wait = WebDriverWait(self.driver, 15)
try:
wait.until(lambda driver: self.driver.execute_script('return jQuery.active') == 0)
wait.until(lambda driver: self.driver.execute_script('return document.readyState') == 'complete')
except Exception:
pass
def no_page_crash(self):
# Do a base test if CherryPy did not report test
self.assertNotIn('500 Internal Server Error', self.driver.title)
wait.until(lambda driver_wait: self.driver.execute_script('return jQuery.active') == 0)
wait.until(lambda driver_wait: self.driver.execute_script('return document.readyState') == 'complete')
@unittest.skipIf("SAB_NEWSSERVER_HOST" not in os.environ, "Test-server not specified")
class SABnzbdHappyFlow(SABnzbdBaseTest):
def test_happy_flow(self):
@ -87,8 +92,7 @@ class SABnzbdHappyFlow(SABnzbdBaseTest):
def start_wizard(self):
# Language-selection
self.driver.get("http://%s:%s/sabnzbd/wizard/" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
self.open_page("http://%s:%s/sabnzbd/wizard/" % (SAB_HOST, SAB_PORT))
self.driver.find_element_by_id("en").click()
self.driver.find_element_by_css_selector('.btn.btn-default').click()
@ -126,8 +130,7 @@ class SABnzbdHappyFlow(SABnzbdBaseTest):
def add_nzb_from_url(self):
test_job_name = 'basic_rar5_%s' % random.randint(500, 1000)
self.driver.get("http://%s:%s/sabnzbd/" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
self.open_page("http://%s:%s/sabnzbd/" % (SAB_HOST, SAB_PORT))
# Wait for modal to open, add URL
self.driver.find_element_by_css_selector('a[href="#modal-add-nzb"]').click()
@ -137,7 +140,7 @@ class SABnzbdHappyFlow(SABnzbdBaseTest):
self.driver.find_element_by_css_selector('form[data-bind="submit: addNZBFromURL"] input[type="submit"]').click()
# We wait for 30 seconds to let it complete
for x in range(30):
for _ in range(30):
try:
# Locate resulting row
result_row = self.driver.find_element_by_xpath('//*[@id="history-tab"]//tr[td//text()[contains(., "%s")]]' % test_job_name)
@ -148,7 +151,6 @@ class SABnzbdHappyFlow(SABnzbdBaseTest):
time.sleep(1)
except NoSuchElementException:
time.sleep(1)
pass
else:
self.fail("Download did not complete")
@ -156,38 +158,34 @@ class SABnzbdHappyFlow(SABnzbdBaseTest):
self.assertTrue(os.path.exists(os.path.join(SAB_COMPLETE_DIR, test_job_name, 'testfile.bin')))
class SABnzbdConfigStart(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigGeneral(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/general" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdBasicPagesTest(SABnzbdBaseTest):
class SABnzbdConfigFolders(SABnzbdBaseTest):
def test_base_pages(self):
# Quick-check of all Config pages
test_urls = ['config',
'config/general',
'config/folders',
'config/server',
'config/categories',
'config/switches',
'config/sorting',
'config/notify',
'config/scheduling',
'config/rss',
'config/special']
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/folders" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
for test_url in test_urls:
self.open_page("http://%s:%s/%s" % (SAB_HOST, SAB_PORT, test_url))
@unittest.skipIf("SAB_NEWSSERVER_HOST" not in os.environ, "Test-server not specified")
class SABnzbdConfigServers(SABnzbdBaseTest):
server_name = "_SeleniumServer"
def open_config_servers(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/server" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
self.open_page("http://%s:%s/sabnzbd/config/server" % (SAB_HOST, SAB_PORT))
self.scroll_to_top()
# Show advanced options
@ -272,7 +270,7 @@ class SABnzbdConfigCategories(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/categories" % (SAB_HOST, SAB_PORT))
self.open_page("http://%s:%s/sabnzbd/config/categories" % (SAB_HOST, SAB_PORT))
# Add new category
self.driver.find_elements_by_name("newname")[1].send_keys("testCat")
@ -281,53 +279,5 @@ class SABnzbdConfigCategories(SABnzbdBaseTest):
self.assertNotIn(self.category_name, self.driver.page_source)
class SABnzbdConfigSwitches(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/switches" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigSorting(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/sorting" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigNotifications(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/notify" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigScheduling(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/scheduling" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigRSS(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/rss" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
class SABnzbdConfigSpecials(SABnzbdBaseTest):
def test_page(self):
# Test if base page works
self.driver.get("http://%s:%s/sabnzbd/config/special" % (SAB_HOST, SAB_PORT))
self.no_page_crash()
if __name__ == "__main__":
unittest.main(failfast=True)

21
tests/testhelper.py

@ -25,7 +25,6 @@ import subprocess
import time
import requests
from selenium.webdriver.support.ui import WebDriverWait
SAB_HOST = 'localhost'
SAB_PORT = 8081
@ -72,12 +71,28 @@ def setUpModule():
# Start SABnzbd
sab_command = 'python %s/../SABnzbd.py --new -l2 -s %s:%s -b0 -f %s' % (SAB_BASE_DIR, SAB_HOST, SAB_PORT, SAB_CACHE_DIR)
subprocess.Popen(sab_command.split())
time.sleep(10)
# Wait for SAB to respond
for _ in range(10):
try:
get_url_result()
# Woohoo, we're up!
return
except requests.ConnectionError:
time.sleep(1)
else:
# Make sure we clean up
tearDownModule()
raise requests.ConnectionError()
def tearDownModule():
# Gracefull shutdown request
# Graceful shutdown request
try:
get_url_result('shutdown')
except requests.ConnectionError:
pass
# Takes a second to shutdown
for x in range(10):
try:

Loading…
Cancel
Save