From d3c7383cb62802b83b5c458543b11565b7deb067 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 2 Oct 2021 15:19:35 -0400 Subject: [PATCH] shadowsocks: Convert functional tests to non-BDD python format Signed-off-by: James Valleroy [sunil: Properly changes the values before restoring from backup] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- .../shadowsocks/tests/shadowsocks.feature | 30 ------------ .../shadowsocks/tests/test_functional.py | 47 +++++++++++++------ 2 files changed, 33 insertions(+), 44 deletions(-) delete mode 100644 plinth/modules/shadowsocks/tests/shadowsocks.feature diff --git a/plinth/modules/shadowsocks/tests/shadowsocks.feature b/plinth/modules/shadowsocks/tests/shadowsocks.feature deleted file mode 100644 index 67167e004..000000000 --- a/plinth/modules/shadowsocks/tests/shadowsocks.feature +++ /dev/null @@ -1,30 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -@apps @shadowsocks -Feature: Shadowsocks Socks5 Proxy - Run the Shadowsocks Socks5 proxy client. - -Background: - Given I'm a logged in user - Given the shadowsocks application is installed - Given the shadowsocks application is configured - -Scenario: Enable shadowsocks application - Given the shadowsocks application is disabled - When I enable the shadowsocks application - Then the shadowsocks service should be running - -@backups -Scenario: Backup and restore shadowsocks - Given the shadowsocks application is enabled - When I configure shadowsocks with server example.com and password beforebackup123 - And I create a backup of the shadowsocks app data with name test_shadowsocks - And I configure shadowsocks with server example.org and password afterbackup123 - And I restore the shadowsocks app data backup with name test_shadowsocks - Then the shadowsocks service should be running - And shadowsocks should be configured with server example.com and password beforebackup123 - -Scenario: Disable shadowsocks application - Given the shadowsocks application is enabled - When I disable the shadowsocks application - Then the shadowsocks service should not be running diff --git a/plinth/modules/shadowsocks/tests/test_functional.py b/plinth/modules/shadowsocks/tests/test_functional.py index 3e6095690..5f7e7bcfa 100644 --- a/plinth/modules/shadowsocks/tests/test_functional.py +++ b/plinth/modules/shadowsocks/tests/test_functional.py @@ -3,30 +3,49 @@ Functional, browser based tests for shadowsocks app. """ -from pytest_bdd import given, parsers, scenarios, then, when +import pytest from plinth.tests import functional -scenarios('shadowsocks.feature') +pytestmark = [pytest.mark.apps, pytest.mark.shadowsocks] -@given('the shadowsocks application is configured') -def configure_shadowsocks(session_browser): +@pytest.fixture(scope='module', autouse=True) +def fixture_background(session_browser): + """Login and install the app.""" + functional.login(session_browser) + functional.install(session_browser, 'shadowsocks') _configure(session_browser, 'example.com', 'fakepassword') + yield + functional.app_disable(session_browser, 'shadowsocks') -@when( - parsers.parse('I configure shadowsocks with server {server:S} and ' - 'password {password:w}')) -def configure_shadowsocks_with_details(session_browser, server, password): - _configure(session_browser, server, password) +def test_enable_disable(session_browser): + """Test enabling the app.""" + functional.app_disable(session_browser, 'shadowsocks') + + functional.app_enable(session_browser, 'shadowsocks') + assert functional.service_is_running(session_browser, 'shadowsocks') + + functional.app_disable(session_browser, 'shadowsocks') + assert functional.service_is_not_running(session_browser, 'shadowsocks') -@then( - parsers.parse('shadowsocks should be configured with server {server:S} ' - 'and password {password:w}')) -def assert_shadowsocks_configuration(session_browser, server, password): - assert (server, password) == _get_configuration(session_browser) +@pytest.mark.backups +def test_backup_restore(session_browser): + """Test backup and restore of configuration.""" + functional.app_enable(session_browser, 'shadowsocks') + _configure(session_browser, 'example.com', 'beforebackup123') + functional.backup_create(session_browser, 'shadowsocks', + 'test_shadowsocks') + + _configure(session_browser, 'example.org', 'afterbackup123') + functional.backup_restore(session_browser, 'shadowsocks', + 'test_shadowsocks') + + assert functional.service_is_running(session_browser, 'shadowsocks') + assert _get_configuration(session_browser) == ('example.com', + 'beforebackup123') def _configure(browser, server, password):