mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
tests: functional: Re-organize step definitions and helper methods
- Move non-reusable app specific step definitions and helper methods into <app>/tests/test_functional.py. - Merge reusable helper methods into plinth.tests.functional - Merge reusable step definitions into plinth.tests.functional.step_definitions - avahi, datetime, ikiwiki: Reuse common methods to avoid repetition. Avoid mapping from app nicknames to actual app names. - deluge, transmission: Make a copy of sample.torrent for each app to avoid clogging common place. - Implement functional.visit() to simplify a lot of browser.visit() calls. - Ensure that name of the mark on functional tests for an app is same as name of the app. This will help with predicting the mark when running tests for a particular app. Tests performed: - Run all functional tests. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
1 parent
8fac6a71fe
commit
80dff7bf9c
53 files changed
+3340
-3410
No files matched your search
@@ -3,6 +3,140 @@
|
||||
Functional, browser based tests for users app.
|
||||
"""
|
||||
|
||||
from pytest_bdd import scenarios
|
||||
from pytest_bdd import given, parsers, scenarios, then, when
|
||||
|
||||
from plinth.tests import functional
|
||||
|
||||
scenarios('users.feature')
|
||||
|
||||
_language_codes = {
|
||||
'Deutsch': 'de',
|
||||
'Nederlands': 'nl',
|
||||
'Português': 'pt',
|
||||
'Türkçe': 'tr',
|
||||
'dansk': 'da',
|
||||
'español': 'es',
|
||||
'français': 'fr',
|
||||
'norsk (bokmål)': 'nb',
|
||||
'polski': 'pl',
|
||||
'svenska': 'sv',
|
||||
'Русский': 'ru',
|
||||
'తెలుగు': 'te',
|
||||
'简体中文': 'zh-hans'
|
||||
}
|
||||
|
||||
_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': '常规配置',
|
||||
}
|
||||
|
||||
|
||||
@given(parsers.parse("the user {name:w} doesn't exist"))
|
||||
def new_user_does_not_exist(session_browser, name):
|
||||
_delete_user(session_browser, name)
|
||||
|
||||
|
||||
@given(parsers.parse('the user {name:w} exists'))
|
||||
def test_user_exists(session_browser, name):
|
||||
functional.nav_to_module(session_browser, 'users')
|
||||
user_link = session_browser.find_link_by_href('/plinth/sys/users/' + name +
|
||||
'/edit/')
|
||||
if not user_link:
|
||||
create_user(session_browser, name, 'secret123')
|
||||
|
||||
|
||||
@when(
|
||||
parsers.parse('I create a user named {name:w} with password {password:w}'))
|
||||
def create_user(session_browser, name, password):
|
||||
_create_user(session_browser, name, password)
|
||||
|
||||
|
||||
@when(parsers.parse('I rename the user {old_name:w} to {new_name:w}'))
|
||||
def rename_user(session_browser, old_name, new_name):
|
||||
_rename_user(session_browser, old_name, new_name)
|
||||
|
||||
|
||||
@when(parsers.parse('I delete the user {name:w}'))
|
||||
def delete_user(session_browser, name):
|
||||
_delete_user(session_browser, name)
|
||||
|
||||
|
||||
@then(parsers.parse('{name:w} should be listed as a user'))
|
||||
def new_user_is_listed(session_browser, name):
|
||||
assert _is_user(session_browser, name)
|
||||
|
||||
|
||||
@then(parsers.parse('{name:w} should not be listed as a user'))
|
||||
def new_user_is_not_listed(session_browser, name):
|
||||
assert not _is_user(session_browser, name)
|
||||
|
||||
|
||||
@when('I change the language to <language>')
|
||||
def change_language(session_browser, language):
|
||||
_set_language(session_browser, _language_codes[language])
|
||||
|
||||
|
||||
@then('Plinth language should be <language>')
|
||||
def plinth_language_should_be(session_browser, language):
|
||||
assert _check_language(session_browser, _language_codes[language])
|
||||
|
||||
|
||||
def _create_user(browser, name, password):
|
||||
functional.nav_to_module(browser, 'users')
|
||||
with functional.wait_for_page_update(browser):
|
||||
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)
|
||||
functional.submit(browser)
|
||||
|
||||
|
||||
def _rename_user(browser, old_name, new_name):
|
||||
functional.nav_to_module(browser, 'users')
|
||||
with functional.wait_for_page_update(browser):
|
||||
browser.find_link_by_href('/plinth/sys/users/' + old_name +
|
||||
'/edit/').first.click()
|
||||
browser.find_by_id('id_username').fill(new_name)
|
||||
functional.submit(browser)
|
||||
|
||||
|
||||
def _delete_user(browser, name):
|
||||
functional.nav_to_module(browser, 'users')
|
||||
delete_link = browser.find_link_by_href('/plinth/sys/users/' + name +
|
||||
'/delete/')
|
||||
if delete_link:
|
||||
with functional.wait_for_page_update(browser):
|
||||
delete_link.first.click()
|
||||
functional.submit(browser)
|
||||
|
||||
|
||||
def _is_user(browser, name):
|
||||
functional.nav_to_module(browser, 'users')
|
||||
edit_link = browser.find_link_by_href('/plinth/sys/users/' + name +
|
||||
'/edit/')
|
||||
return bool(edit_link)
|
||||
|
||||
|
||||
def _set_language(browser, language_code):
|
||||
username = functional.config['DEFAULT']['username']
|
||||
functional.visit(browser, '/plinth/sys/users/{}/edit/'.format(username))
|
||||
browser.find_by_xpath('//select[@id="id_language"]//option[@value="' +
|
||||
language_code + '"]').first.click()
|
||||
functional.submit(browser)
|
||||
|
||||
|
||||
def _check_language(browser, language_code):
|
||||
functional.nav_to_module(browser, 'config')
|
||||
return browser.find_by_css('.app-titles').first.find_by_tag(
|
||||
'h2').first.value == _config_page_title_language_map[language_code]
|
||||
@@ -8,7 +8,7 @@
|
||||
# TODO Scenario: Make user active
|
||||
# TODO Scenario: Change user password
|
||||
|
||||
@system @essential @users_groups
|
||||
@system @essential @users
|
||||
Feature: Users and Groups
|
||||
Manage users and groups.
|
||||
|
||||
|
||||
Reference in new issue
Block a user