tests: functional: Add a convenience method to logout

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-07-28 18:38:41 -07:00 committed by James Valleroy
parent 28030933dc
commit 5340cf3119
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 13 additions and 9 deletions

View File

@ -158,7 +158,7 @@ def can_log_in(session_browser, username):
parsers.parse(
'I can log in as the user {username:w} with password {password:w}'))
def can_log_in_with_password(session_browser, username, password):
functional.visit(session_browser, '/plinth/accounts/logout/')
functional.logout(session_browser)
functional.login_with_account(session_browser, functional.base_url,
username, password)
assert len(session_browser.find_by_id('id_user_menu')) > 0

View File

@ -248,13 +248,13 @@ def _create_admin_account(browser, username, password):
def login(browser):
"""Login to the interface."""
"""Login to the FreedomBox interface with default test account."""
login_with_account(browser, base_url, config['DEFAULT']['username'],
config['DEFAULT']['password'])
def login_with_account(browser, url, username, password=None):
"""Login to the FreedomBox interface with provided account."""
if password is None:
password = get_password(username)
# XXX: Find a way to remove the hardcoded jsxc URL
@ -294,6 +294,11 @@ def login_with_account(browser, url, username, password=None):
submit(browser, element=browser.find_by_name('next')[0])
def logout(browser):
"""Log out of the FreedomBox interface."""
visit(browser, '/plinth/accounts/logout/')
#################
# App utilities #
#################
@ -356,10 +361,9 @@ def _change_app_status(browser, app_name, change_status_to='enabled'):
if button:
should_enable_field = browser.find_by_id('id_should_enable')
if (should_enable_field.value == 'False'
and change_status_to == 'disabled') or (
should_enable_field.value == 'True'
and change_status_to == 'enabled'):
if (should_enable_field.value == 'False' and change_status_to
== 'disabled') or (should_enable_field.value == 'True'
and change_status_to == 'enabled'):
submit(browser, element=button)
else:
checkbox_id = _app_checkbox_id[app_name]

View File

@ -18,12 +18,12 @@ def logged_in(session_browser):
@given("I'm a logged out user")
def logged_out_user(session_browser):
functional.visit(session_browser, '/plinth/accounts/logout/')
functional.logout(session_browser)
@when("I log out")
def log_out_user(session_browser):
functional.visit(session_browser, '/plinth/accounts/logout/')
functional.logout(session_browser)
@given(parsers.parse('the {app_name:w} application is installed'))