From 5340cf3119495a3fcfe16fbf5f0f788d96db1b60 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 28 Jul 2021 18:38:41 -0700 Subject: [PATCH] tests: functional: Add a convenience method to logout Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/users/tests/test_functional.py | 2 +- plinth/tests/functional/__init__.py | 16 ++++++++++------ plinth/tests/functional/step_definitions.py | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plinth/modules/users/tests/test_functional.py b/plinth/modules/users/tests/test_functional.py index bdcbb3117..a8fe4a6c7 100644 --- a/plinth/modules/users/tests/test_functional.py +++ b/plinth/modules/users/tests/test_functional.py @@ -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 diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index 85d330e39..07d49003c 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -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] diff --git a/plinth/tests/functional/step_definitions.py b/plinth/tests/functional/step_definitions.py index 9bb445f70..5d48f6eed 100644 --- a/plinth/tests/functional/step_definitions.py +++ b/plinth/tests/functional/step_definitions.py @@ -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'))