mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
functional-tests: Merge plinth-tester into plinth
- Rename Plinth-tester to FreedomBox - Add pytest.ini to discover the root directory for tests easily - Update README to say that py.test should be run from functional_tests directory. - Add geckodriver.log to .gitignore Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
73bac986e4
commit
0bdc2802f2
45 files changed
+2130
No files matched your search
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import configparser
|
||||
import os
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
config['DEFAULT']['url'] = os.environ.get('FREEDOMBOX_URL',
|
||||
config['DEFAULT']['url'])
|
||||
@@ -0,0 +1,130 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from time import sleep
|
||||
|
||||
from support import config, interface
|
||||
from support.service import eventually
|
||||
|
||||
# unlisted apps just use the app_name as module name
|
||||
app_module = {
|
||||
'ntp': 'datetime',
|
||||
'wiki': 'ikiwiki',
|
||||
'tt-rss': 'ttrss',
|
||||
}
|
||||
|
||||
app_checkbox_id = {
|
||||
'tor': 'id_tor-enabled',
|
||||
}
|
||||
|
||||
app_config_updating_text = {
|
||||
'tor': 'Tor configuration is being updated',
|
||||
}
|
||||
|
||||
default_url = config['DEFAULT']['url']
|
||||
|
||||
|
||||
def get_app_module(app_name):
|
||||
module = app_name
|
||||
if app_name in app_module:
|
||||
module = app_module[app_name]
|
||||
return module
|
||||
|
||||
|
||||
def get_app_checkbox_id(app_name):
|
||||
checkbox_id = 'id_is_enabled'
|
||||
if app_name in app_checkbox_id:
|
||||
checkbox_id = app_checkbox_id[app_name]
|
||||
return checkbox_id
|
||||
|
||||
|
||||
def install(browser, app_name):
|
||||
interface.nav_to_module(browser, get_app_module(app_name))
|
||||
install = browser.find_by_value('Install')
|
||||
if install:
|
||||
install.click()
|
||||
while browser.is_text_present('Installing') \
|
||||
or browser.is_text_present('Performing post-install operation'):
|
||||
sleep(1)
|
||||
sleep(2)
|
||||
|
||||
|
||||
def _change_status(browser, app_name, change_status_to='enabled'):
|
||||
interface.nav_to_module(browser, get_app_module(app_name))
|
||||
checkbox = browser.find_by_id(get_app_checkbox_id(app_name))
|
||||
checkbox.check() if change_status_to == 'enabled' else checkbox.uncheck()
|
||||
browser.find_by_value('Update setup').click()
|
||||
if app_name == app_config_updating_text:
|
||||
wait_for_config_update(browser, app_name)
|
||||
|
||||
|
||||
def enable(browser, app_name):
|
||||
_change_status(browser, app_name, 'enabled')
|
||||
|
||||
|
||||
def disable(browser, app_name):
|
||||
_change_status(browser, app_name, 'disabled')
|
||||
|
||||
|
||||
def wait_for_config_update(browser, app_name):
|
||||
while browser.is_text_present(app_config_updating_text['tor']):
|
||||
sleep(1)
|
||||
|
||||
|
||||
def select_domain_name(browser, app_name, domain_name):
|
||||
browser.visit('{}/plinth/apps/{}/setup/'.format(default_url, app_name))
|
||||
drop_down = browser.find_by_id('id_domain_name')
|
||||
drop_down.select(domain_name)
|
||||
browser.find_by_value('Update setup').click()
|
||||
|
||||
|
||||
def configure_shadowsocks(browser):
|
||||
"""Configure shadowsocks client with some fake server details"""
|
||||
browser.visit('{}/plinth/apps/shadowsocks/'.format(default_url))
|
||||
browser.find_by_id('id_server').fill('some.shadow.tunnel')
|
||||
browser.find_by_id('id_password').fill('fakepassword')
|
||||
browser.find_by_value('Update setup').click()
|
||||
|
||||
|
||||
def modify_max_file_size(browser, size):
|
||||
"""Change the maximum file size of coquelicot to the given value"""
|
||||
browser.visit('{}/plinth/apps/coquelicot/'.format(default_url))
|
||||
browser.find_by_id('id_max_file_size').fill(size)
|
||||
browser.find_by_value('Update setup').click()
|
||||
# Wait for the service to restart after updating maximum file size
|
||||
eventually(message_or_setting_unchanged,
|
||||
args=[browser, 'Maximum file size updated'])
|
||||
|
||||
|
||||
def message_or_setting_unchanged(browser, message):
|
||||
return browser.is_text_present(message) or browser.is_text_present(
|
||||
'Setting unchanged')
|
||||
|
||||
|
||||
def get_max_file_size(browser):
|
||||
"""Get the maximum file size of coquelicot"""
|
||||
browser.visit('{}/plinth/apps/coquelicot/'.format(default_url))
|
||||
return int(browser.find_by_id('id_max_file_size').value)
|
||||
|
||||
|
||||
def modify_upload_password(browser, password):
|
||||
"""Change the upload password for coquelicot to the given value"""
|
||||
browser.visit('{}/plinth/apps/coquelicot/'.format(default_url))
|
||||
browser.find_by_id('id_upload_password').fill(password)
|
||||
browser.find_by_value('Update setup').click()
|
||||
# Wait for the service to restart after updating password
|
||||
eventually(browser.is_text_present, args=['Upload password updated'])
|
||||
@@ -0,0 +1,101 @@
|
||||
#
|
||||
# This file is part of Plinth-tester.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from support import config
|
||||
|
||||
sys_modules = [
|
||||
'avahi', 'cockpit', 'config', 'datetime', 'diagnostics', 'firewall',
|
||||
'letsencrypt', 'monkeysphere', 'names', 'networks', 'power', 'snapshot',
|
||||
'upgrades', 'users'
|
||||
]
|
||||
|
||||
default_url = config['DEFAULT']['url']
|
||||
|
||||
|
||||
def login(browser, url, username, password):
|
||||
browser.visit(url)
|
||||
if browser.find_by_id('logout-nojs'):
|
||||
return # already logged in
|
||||
|
||||
login_button = browser.find_link_by_href('/plinth/accounts/login/')
|
||||
if login_button:
|
||||
login_button.first.click()
|
||||
login_submit = browser.find_by_value('Login')
|
||||
if login_button:
|
||||
browser.fill('username', username)
|
||||
browser.fill('password', password)
|
||||
login_submit.click()
|
||||
else:
|
||||
browser.visit(default_url + '/plinth/firstboot/welcome')
|
||||
browser.find_by_value('Start Setup').click()
|
||||
create_admin_account(browser, 'tester', 'testingtesting')
|
||||
login(browser, url, username, password)
|
||||
|
||||
|
||||
def is_login_prompt(browser):
|
||||
return all(
|
||||
[browser.find_by_id('id_username'),
|
||||
browser.find_by_id('id_password')])
|
||||
|
||||
|
||||
def nav_to_module(browser, module):
|
||||
browser.find_link_by_href('/plinth/').first.click()
|
||||
if module in sys_modules:
|
||||
browser.find_link_by_href('/plinth/sys/').first.click()
|
||||
browser.find_link_by_href('/plinth/sys/' + module + '/').first.click()
|
||||
else:
|
||||
browser.find_link_by_href('/plinth/apps/').first.click()
|
||||
browser.find_link_by_href('/plinth/apps/' + module + '/').first.click()
|
||||
|
||||
|
||||
def submit(browser):
|
||||
browser.find_by_value('Submit').click()
|
||||
|
||||
|
||||
def create_user(browser, name, password):
|
||||
nav_to_module(browser, 'users')
|
||||
browser.find_link_by_href('/plinth/sys/users/create/').first.click()
|
||||
browser.find_by_id('id_username').fill(name)
|
||||
browser.find_by_id('id_password1').fill(password)
|
||||
browser.find_by_id('id_password2').fill(password)
|
||||
browser.find_by_value('Create User').click()
|
||||
|
||||
|
||||
def rename_user(browser, old_name, new_name):
|
||||
nav_to_module(browser, 'users')
|
||||
browser.find_link_by_href('/plinth/sys/users/' + old_name +
|
||||
'/edit/').first.click()
|
||||
browser.find_by_id('id_username').fill(new_name)
|
||||
browser.find_by_value('Save Changes').click()
|
||||
|
||||
|
||||
def delete_user(browser, name):
|
||||
nav_to_module(browser, 'users')
|
||||
browser.find_link_by_href('/plinth/sys/users/' + name +
|
||||
'/delete/').first.click()
|
||||
browser.find_by_value('Delete ' + name).click()
|
||||
|
||||
|
||||
def is_user(browser, name):
|
||||
nav_to_module(browser, 'users')
|
||||
return browser.is_text_present(name)
|
||||
|
||||
|
||||
def create_admin_account(browser, username, password):
|
||||
browser.find_by_id('id_username').fill(username)
|
||||
browser.find_by_id('id_password1').fill(password)
|
||||
browser.find_by_id('id_password2').fill(password)
|
||||
browser.find_by_value('Create Account').click()
|
||||
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from time import sleep
|
||||
|
||||
from support import interface
|
||||
|
||||
# unlisted services just use the service_name as module name
|
||||
service_module = {
|
||||
'ntp': 'datetime',
|
||||
}
|
||||
|
||||
|
||||
def get_service_module(service_name):
|
||||
module = service_name
|
||||
if service_name in service_module:
|
||||
module = service_module[service_name]
|
||||
return module
|
||||
|
||||
|
||||
def is_running(browser, service_name):
|
||||
interface.nav_to_module(browser, get_service_module(service_name))
|
||||
return browser.is_text_present('is running')
|
||||
|
||||
|
||||
def is_not_running(browser, service_name):
|
||||
interface.nav_to_module(browser, get_service_module(service_name))
|
||||
return browser.is_text_present('is not running')
|
||||
|
||||
|
||||
def eventually(function, args, timeout=30):
|
||||
"""Execute a function returning a boolean expression till it returns
|
||||
True or a timeout is reached"""
|
||||
counter = 1
|
||||
while counter < timeout:
|
||||
if function(*args):
|
||||
return True
|
||||
else:
|
||||
counter += 1
|
||||
sleep(1)
|
||||
return False
|
||||
@@ -0,0 +1,59 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from time import sleep
|
||||
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
from support import config
|
||||
from support.service import eventually
|
||||
|
||||
# unlisted sites just use '/' + site_name as url
|
||||
site_url = {
|
||||
'wiki': '/ikiwiki',
|
||||
'jsxc': '/plinth/apps/jsxc/jsxc/',
|
||||
'cockpit': '/_cockpit/'
|
||||
}
|
||||
|
||||
|
||||
def get_site_url(site_name):
|
||||
url = '/' + site_name
|
||||
if site_name in site_url:
|
||||
url = site_url[site_name]
|
||||
return url
|
||||
|
||||
|
||||
def is_available(browser, site_name):
|
||||
browser.visit(config['DEFAULT']['url'] + get_site_url(site_name))
|
||||
sleep(3)
|
||||
browser.reload()
|
||||
return browser.title != '404 Not Found'
|
||||
|
||||
|
||||
def access_url(browser, site_name):
|
||||
browser.visit(config['DEFAULT']['url'] + get_site_url(site_name))
|
||||
|
||||
|
||||
def verify_coquelicot_upload_password(browser, password):
|
||||
browser.visit(config['DEFAULT']['url'] + '/coquelicot')
|
||||
browser.find_by_id('upload_password').fill(password)
|
||||
actions = ActionChains(browser.driver)
|
||||
actions.send_keys(Keys.RETURN)
|
||||
actions.perform()
|
||||
assert eventually(browser.is_element_present_by_css,
|
||||
args=['div[style*="display: none;"]'])
|
||||
@@ -0,0 +1,88 @@
|
||||
#
|
||||
# This file is part of Plinth-tester.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from support import config
|
||||
|
||||
from .interface import nav_to_module, submit
|
||||
|
||||
config_page_title_language_map = {
|
||||
'da': 'Generel Konfiguration',
|
||||
'de': 'Allgemeine Konfiguration',
|
||||
'es': 'Configuración general',
|
||||
'fr': 'Configuration générale',
|
||||
'nb': 'Generelt oppsett',
|
||||
'nl': 'Algemene Instellingen',
|
||||
'pl': 'Ustawienia główne',
|
||||
'pt': 'Configuração Geral',
|
||||
'ru': 'Общие настройки',
|
||||
'sv': 'Allmän Konfiguration',
|
||||
'te': 'సాధారణ ఆకృతీకరణ',
|
||||
'tr': 'Genel Yapılandırma',
|
||||
'zh-hans': '常规配置',
|
||||
}
|
||||
|
||||
|
||||
def get_hostname(browser):
|
||||
nav_to_module(browser, 'config')
|
||||
return browser.find_by_id('id_configuration-hostname').value
|
||||
|
||||
|
||||
def set_hostname(browser, hostname):
|
||||
nav_to_module(browser, 'config')
|
||||
browser.find_by_id('id_configuration-hostname').fill(hostname)
|
||||
submit(browser)
|
||||
|
||||
|
||||
def get_domain_name(browser):
|
||||
nav_to_module(browser, 'config')
|
||||
return browser.find_by_id('id_configuration-domainname').value
|
||||
|
||||
|
||||
def set_domain_name(browser, domain_name):
|
||||
nav_to_module(browser, 'config')
|
||||
browser.find_by_id('id_configuration-domainname').fill(domain_name)
|
||||
submit(browser)
|
||||
|
||||
|
||||
def set_language(browser, language_code):
|
||||
nav_to_module(browser, 'config')
|
||||
browser.find_by_xpath(
|
||||
'//select[@id="id_configuration-language"]//option[@value="' \
|
||||
+ language_code + '"]'
|
||||
).first.click()
|
||||
submit(browser)
|
||||
|
||||
|
||||
def check_language(browser, language_code):
|
||||
nav_to_module(browser, 'config')
|
||||
return browser.title == config_page_title_language_map[language_code]
|
||||
|
||||
|
||||
def delete_all_snapshots(browser):
|
||||
browser.visit(config['DEFAULT']['url'] + '/plinth/sys/snapshot/all/delete')
|
||||
browser.find_by_value('Delete Snapshots').click()
|
||||
|
||||
|
||||
def create_snapshot(browser):
|
||||
nav_to_module(browser, 'snapshot')
|
||||
browser.find_by_value('Create Snapshot').click()
|
||||
|
||||
|
||||
def get_snapshot_count(browser):
|
||||
nav_to_module(browser, 'snapshot')
|
||||
# Subtract 1 for table header
|
||||
return len(browser.find_by_xpath('//tr')) - 1
|
||||
Reference in new issue
Block a user