From a51e4aaa1c32d3eb01446a1e75f1bbef9800ebd0 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sun, 3 Oct 2021 09:00:59 -0400 Subject: [PATCH] sharing: Convert functional tests to non-BDD python format Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- plinth/modules/sharing/tests/sharing.feature | 52 --------- .../modules/sharing/tests/test_functional.py | 100 ++++++++++-------- 2 files changed, 54 insertions(+), 98 deletions(-) delete mode 100644 plinth/modules/sharing/tests/sharing.feature diff --git a/plinth/modules/sharing/tests/sharing.feature b/plinth/modules/sharing/tests/sharing.feature deleted file mode 100644 index fc75661ee..000000000 --- a/plinth/modules/sharing/tests/sharing.feature +++ /dev/null @@ -1,52 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -@apps @sharing -Feature: Sharing - Share server folders over HTTP, etc. - -Background: - Given I'm a logged in user - -Scenario: Add new share - Given share tmp is not available - When I add a share tmp from path /tmp for admin - Then the share tmp should be listed from path /tmp for admin - And the share tmp should be accessible - -Scenario: Edit a share - Given share tmp is not available - When I remove share boot - And I add a share tmp from path /tmp for admin - And I edit share tmp to boot from path /boot for admin - Then the share tmp should not be listed - And the share tmp should not exist - And the share boot should be listed from path /boot for admin - And the share boot should be accessible - -Scenario: Remove a share - When I remove share tmp - And I add a share tmp from path /tmp for admin - And I remove share tmp - Then the share tmp should not be listed - And the share tmp should not exist - -Scenario: Share permissions - When I remove share tmp - And I add a share tmp from path /tmp for syncthing-access - Then the share tmp should be listed from path /tmp for syncthing-access - And the share tmp should not be accessible - -Scenario: Public share - When I edit share tmp to be public - And I log out - Then the share_tmp site should be available - -@backups -Scenario: Backup and restore sharing - Given share tmp is not available - When I add a share tmp from path /tmp for admin - And I create a backup of the sharing app data with name test_sharing - And I remove share tmp - And I restore the sharing app data backup with name test_sharing - Then the share tmp should be listed from path /tmp for admin - And the share tmp should be accessible diff --git a/plinth/modules/sharing/tests/test_functional.py b/plinth/modules/sharing/tests/test_functional.py index 0717038ca..5e335d29a 100644 --- a/plinth/modules/sharing/tests/test_functional.py +++ b/plinth/modules/sharing/tests/test_functional.py @@ -5,66 +5,69 @@ Functional, browser based tests for sharing app. import pytest import splinter -from pytest_bdd import given, parsers, scenarios, then, when - from plinth.tests import functional -scenarios('sharing.feature') +pytestmark = [pytest.mark.apps, pytest.mark.sharing] -@given(parsers.parse('share {name:w} is not available')) -def remove_share(session_browser, name): - _remove_share(session_browser, name) +@pytest.fixture(scope='module', autouse=True) +def fixture_background(session_browser): + """Login.""" + functional.login(session_browser) -@when(parsers.parse('I add a share {name:w} from path {path} for {group:S}')) -def add_share(session_browser, name, path, group): - _add_share(session_browser, name, path, group) +def test_add_remove_share(session_browser): + """Test adding and removing a share.""" + _remove_share(session_browser, 'tmp') + _add_share(session_browser, 'tmp', '/tmp', 'admin') + _verify_share(session_browser, 'tmp', '/tmp', 'admin') + _access_share(session_browser, 'tmp') + + _remove_share(session_browser, 'tmp') + _verify_invalid_share(session_browser, 'tmp') + _verify_nonexistant_share(session_browser, 'tmp') -@when( - parsers.parse('I edit share {old_name:w} to {new_name:w} from path {path} ' - 'for {group:w}')) -def edit_share(session_browser, old_name, new_name, path, group): - _edit_share(session_browser, old_name, new_name, path, group) +def test_edit_share(session_browser): + """Test editing a share.""" + _remove_share(session_browser, 'tmp') + _remove_share(session_browser, 'boot') + + _add_share(session_browser, 'tmp', '/tmp', 'admin') + _edit_share(session_browser, 'tmp', 'boot', '/boot', 'admin') + + _verify_invalid_share(session_browser, 'tmp') + _verify_nonexistant_share(session_browser, 'tmp') + + _verify_share(session_browser, 'boot', '/boot', 'admin') + _access_share(session_browser, 'boot') -@when(parsers.parse('I remove share {name:w}')) -def remove_share2(session_browser, name): - _remove_share(session_browser, name) +def test_share_permissions(session_browser): + """Test share permissions.""" + _remove_share(session_browser, 'tmp') + _add_share(session_browser, 'tmp', '/tmp', 'syncthing-access') + _verify_share(session_browser, 'tmp', '/tmp', 'syncthing-access') + _verify_inaccessible_share(session_browser, 'tmp') + + _make_share_public(session_browser, 'tmp') + functional.logout(session_browser) + assert functional.is_available(session_browser, 'share_tmp') + functional.login(session_browser) -@when(parsers.parse('I edit share {name:w} to be public')) -def edit_share_public_access(session_browser, name): - _make_share_public(session_browser, name) +@pytest.mark.backups +def test_backup_restore(session_browser): + """Test backup and restore.""" + _remove_share(session_browser, 'tmp') + _add_share(session_browser, 'tmp', '/tmp', 'admin') + functional.backup_create(session_browser, 'sharing', 'test_sharing') + _remove_share(session_browser, 'tmp') + functional.backup_restore(session_browser, 'sharing', 'test_sharing') -@then( - parsers.parse( - 'the share {name:w} should be listed from path {path} for {group:S}')) -def verify_share(session_browser, name, path, group): - _verify_share(session_browser, name, path, group) - - -@then(parsers.parse('the share {name:w} should not be listed')) -def verify_invalid_share(session_browser, name): - with pytest.raises(splinter.exceptions.ElementDoesNotExist): - _get_share(session_browser, name) - - -@then(parsers.parse('the share {name:w} should be accessible')) -def access_share(session_browser, name): - _access_share(session_browser, name) - - -@then(parsers.parse('the share {name:w} should not exist')) -def verify_nonexistant_share(session_browser, name): - _verify_nonexistant_share(session_browser, name) - - -@then(parsers.parse('the share {name:w} should not be accessible')) -def verify_inaccessible_share(session_browser, name): - _verify_inaccessible_share(session_browser, name) + _verify_share(session_browser, 'tmp', '/tmp', 'admin') + _access_share(session_browser, 'tmp') def _remove_share(browser, name): @@ -135,6 +138,11 @@ def _make_share_public(browser, name): functional.submit(browser) +def _verify_invalid_share(browser, name): + with pytest.raises(splinter.exceptions.ElementDoesNotExist): + _get_share(browser, name) + + def _verify_nonexistant_share(browser, name): """Verify that given URL for a given share name is a 404.""" functional.visit(browser, f'/share/{name}')