syncthing: Convert functional tests to non-BDD python format

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2021-10-03 20:02:04 -04:00 committed by Sunil Mohan Adapa
parent 3bbbd0c812
commit 7ea6eeeac8
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 75 additions and 95 deletions

View File

@ -1,59 +0,0 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
@apps @syncthing @sso
Feature: Syncthing File Synchronization
Run Syncthing File Synchronization server.
Background:
Given I'm a logged in user
Given the syncthing application is installed
Scenario: Enable syncthing application
Given the syncthing application is disabled
When I enable the syncthing application
Then the syncthing service should be running
Scenario: Authentication and usage reporting notifications not shown
Given the syncthing application is enabled
When I access syncthing application
Then the usage reporting notification is not shown
And the authentication notification is not shown
Scenario: Add a syncthing folder
Given the syncthing application is enabled
And syncthing folder Test is not present
When I add a folder /tmp as syncthing folder Test
Then syncthing folder Test should be present
Scenario: Remove a syncthing folder
Given the syncthing application is enabled
And folder /tmp is present as syncthing folder Test
When I remove syncthing folder Test
Then syncthing folder Test should not be present
@backups
Scenario: Backup and restore syncthing
Given the syncthing application is enabled
And syncthing folder Test is not present
When I add a folder /tmp as syncthing folder Test
And I create a backup of the syncthing app data with name test_syncthing
And I remove syncthing folder Test
And I restore the syncthing app data backup with name test_syncthing
Then syncthing folder Test should be present
Scenario: User of syncthing-access group can access syncthing site
Given the syncthing application is enabled
And the user syncthinguser in group syncthing-access exists
When I'm logged in as the user syncthinguser
Then the syncthing site should be available
Scenario: User not of syncthing-access group can't access syncthing site
Given the syncthing application is enabled
And the user nogroupuser exists
When I'm logged in as the user nogroupuser
Then the syncthing site should not be available
Scenario: Disable syncthing application
Given the syncthing application is enabled
When I disable the syncthing application
Then the syncthing service should not be running

View File

@ -5,63 +5,102 @@ Functional, browser based tests for syncthing app.
import time
from pytest_bdd import given, parsers, scenarios, then, when
import pytest
from plinth.tests import functional
scenarios('syncthing.feature')
pytestmark = [pytest.mark.apps, pytest.mark.syncthing]
@given(parsers.parse('syncthing folder {folder_name:w} is not present'))
def syncthing_folder_not_present(session_browser, folder_name):
if _folder_is_present(session_browser, folder_name):
_remove_folder(session_browser, folder_name)
@pytest.fixture(scope='module', autouse=True)
def fixture_background(session_browser):
"""Login and install the app."""
functional.login(session_browser)
functional.install(session_browser, 'syncthing')
yield
functional.app_disable(session_browser, 'syncthing')
@given(
parsers.parse(
'folder {folder_path:S} is present as syncthing folder {folder_name:w}'
))
def syncthing_folder_present(session_browser, folder_name, folder_path):
if not _folder_is_present(session_browser, folder_name):
_add_folder(session_browser, folder_name, folder_path)
def test_enable_disable(session_browser):
"""Test enabling the app."""
functional.app_disable(session_browser, 'syncthing')
functional.app_enable(session_browser, 'syncthing')
assert functional.service_is_running(session_browser, 'syncthing')
functional.app_disable(session_browser, 'syncthing')
assert functional.service_is_not_running(session_browser, 'syncthing')
@when(
parsers.parse(
'I add a folder {folder_path:S} as syncthing folder {folder_name:w}'))
def syncthing_add_folder(session_browser, folder_name, folder_path):
_add_folder(session_browser, folder_name, folder_path)
def test_notifications(session_browser):
"""Test that authentication and usage reporting notifications are not
shown."""
functional.app_enable(session_browser, 'syncthing')
functional.access_url(session_browser, 'syncthing')
_assert_usage_report_notification_not_shown(session_browser)
_assert_authentication_notification_not_shown(session_browser)
@when(parsers.parse('I remove syncthing folder {folder_name:w}'))
def syncthing_remove_folder(session_browser, folder_name):
_remove_folder(session_browser, folder_name)
def test_add_remove_folder(session_browser):
"""Test adding and removing a folder."""
functional.app_enable(session_browser, 'syncthing')
if _folder_is_present(session_browser, 'Test'):
_remove_folder(session_browser, 'Test')
_add_folder(session_browser, 'Test', '/tmp')
assert _folder_is_present(session_browser, 'Test')
_remove_folder(session_browser, 'Test')
assert not _folder_is_present(session_browser, 'Test')
@then('the usage reporting notification is not shown')
def syncthing_assert_usage_report_notification_not_shown(session_browser):
@pytest.mark.backups
def test_backup_restore(session_browser):
"""Test backup and restore of app data."""
functional.app_enable(session_browser, 'syncthing')
if _folder_is_present(session_browser, 'Test'):
_remove_folder(session_browser, 'Test')
_add_folder(session_browser, 'Test', '/tmp')
functional.backup_create(session_browser, 'syncthing', 'test_syncthing')
_remove_folder(session_browser, 'Test')
functional.backup_restore(session_browser, 'syncthing', 'test_syncthing')
assert _folder_is_present(session_browser, 'Test')
def test_user_group_access(session_browser):
"""Test that only users in syncthing-access group can access syncthing
site."""
functional.app_enable(session_browser, 'syncthing')
if not functional.user_exists(session_browser, 'syncthinguser'):
functional.create_user(session_browser, 'syncthinguser',
groups=['syncthing-access'])
if not functional.user_exists(session_browser, 'nogroupuser'):
functional.create_user(session_browser, 'nogroupuser')
functional.login_with_account(session_browser, functional.base_url,
'syncthinguser')
assert functional.is_available(session_browser, 'syncthing')
functional.login_with_account(session_browser, functional.base_url,
'nogroupuser')
assert not functional.is_available(session_browser, 'syncthing')
functional.login(session_browser)
def _assert_usage_report_notification_not_shown(session_browser):
_load_main_interface(session_browser)
assert session_browser.find_by_id('ur').visible is False
@then('the authentication notification is not shown')
def syncthing_assert_authentication_notification_not_shown(session_browser):
def _assert_authentication_notification_not_shown(session_browser):
_load_main_interface(session_browser)
assert bool(session_browser.find_by_css(
'#authenticationUserAndPassword *')) is False
@then(parsers.parse('syncthing folder {folder_name:w} should be present'))
def syncthing_assert_folder_present(session_browser, folder_name):
assert _folder_is_present(session_browser, folder_name)
@then(parsers.parse('syncthing folder {folder_name:w} should not be present'))
def syncthing_assert_folder_not_present(session_browser, folder_name):
assert not _folder_is_present(session_browser, folder_name)
def _load_main_interface(browser):
"""Close the dialog boxes that many popup after visiting the URL."""
functional.access_url(browser, 'syncthing')