From 79f09e3d885698bc012b56697f975a149c130614 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 4 Oct 2021 18:48:20 -0400 Subject: [PATCH] transmission: Convert functional tests to non-BDD python format Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- .../transmission/tests/test_functional.py | 57 ++++++++++++++----- .../transmission/tests/transmission.feature | 36 ------------ 2 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 plinth/modules/transmission/tests/transmission.feature diff --git a/plinth/modules/transmission/tests/test_functional.py b/plinth/modules/transmission/tests/test_functional.py index 68e8341e8..457e670e2 100644 --- a/plinth/modules/transmission/tests/test_functional.py +++ b/plinth/modules/transmission/tests/test_functional.py @@ -5,27 +5,58 @@ Functional, browser based tests for transmission app. import os -from pytest_bdd import parsers, scenarios, then, when - +import pytest from plinth.tests import functional -scenarios('transmission.feature') +pytestmark = [pytest.mark.apps, pytest.mark.transmission, pytest.mark.sso] -@when('all torrents are removed from transmission') -def transmission_remove_all_torrents(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, 'transmission') + yield + functional.app_disable(session_browser, 'transmission') + + +def test_enable_disable(session_browser): + """Test enabling the app.""" + functional.app_disable(session_browser, 'transmission') + + functional.app_enable(session_browser, 'transmission') + assert functional.is_available(session_browser, 'transmission') + + functional.app_disable(session_browser, 'transmission') + assert not functional.is_available(session_browser, 'transmission') + + +def test_upload_torrent(session_browser): + """Test uploading a torrent to Transmission.""" + functional.app_enable(session_browser, 'transmission') _remove_all_torrents(session_browser) - - -@when('I upload a sample torrent to transmission') -def transmission_upload_sample_torrent(session_browser): _upload_sample_torrent(session_browser) + _assert_number_of_torrents(session_browser, 1) -@then( - parsers.parse( - 'there should be {torrents_number:d} torrents listed in transmission')) -def transmission_assert_number_of_torrents(session_browser, torrents_number): +@pytest.mark.backups +def test_backup_restore(session_browser): + """Test backup and restore of app data.""" + functional.app_enable(session_browser, 'transmission') + _remove_all_torrents(session_browser) + _upload_sample_torrent(session_browser) + functional.backup_create(session_browser, 'transmission', + 'test_transmission') + + _remove_all_torrents(session_browser) + functional.backup_restore(session_browser, 'transmission', + 'test_transmission') + + assert functional.service_is_running(session_browser, 'transmission') + _assert_number_of_torrents(session_browser, 1) + + +def _assert_number_of_torrents(session_browser, torrents_number): functional.visit(session_browser, '/transmission') assert functional.eventually( lambda: torrents_number == _get_number_of_torrents(session_browser)) diff --git a/plinth/modules/transmission/tests/transmission.feature b/plinth/modules/transmission/tests/transmission.feature deleted file mode 100644 index bec006c7b..000000000 --- a/plinth/modules/transmission/tests/transmission.feature +++ /dev/null @@ -1,36 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -@apps @transmission @sso -Feature: Transmission BitTorrent Client - Run the Transmission BitTorrent client. - -Background: - Given I'm a logged in user - Given the transmission application is installed - -Scenario: Enable transmission application - Given the transmission application is disabled - When I enable the transmission application - Then the transmission site should be available - -Scenario: Upload a torrent to transmission - Given the transmission application is enabled - When all torrents are removed from transmission - And I upload a sample torrent to transmission - Then there should be 1 torrents listed in transmission - -@backups -Scenario: Backup and restore transmission - Given the transmission application is enabled - When all torrents are removed from transmission - And I upload a sample torrent to transmission - And I create a backup of the transmission app data with name test_transmission - And all torrents are removed from transmission - And I restore the transmission app data backup with name test_transmission - Then the transmission service should be running - And there should be 1 torrents listed in transmission - -Scenario: Disable transmission application - Given the transmission application is enabled - When I disable the transmission application - Then the transmission site should not be available