From cb430b4b4b872b95804f5ca5bfbf539ef8739258 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 20 Sep 2021 19:34:02 -0400 Subject: [PATCH] bind: Convert functional tests to non-BDD python format Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- plinth/modules/bind/tests/bind.feature | 49 -------------- plinth/modules/bind/tests/test_functional.py | 67 ++++++++++++++++---- 2 files changed, 53 insertions(+), 63 deletions(-) delete mode 100644 plinth/modules/bind/tests/bind.feature diff --git a/plinth/modules/bind/tests/bind.feature b/plinth/modules/bind/tests/bind.feature deleted file mode 100644 index f0bac0d46..000000000 --- a/plinth/modules/bind/tests/bind.feature +++ /dev/null @@ -1,49 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -@apps @bind -Feature: Bind Domain Name Server - Configure the Bind Domain Name Server. - -Background: - Given I'm a logged in user - Given the bind application is installed - -Scenario: Enable bind application - Given the bind application is disabled - When I enable the bind application - Then the bind service should be running - -Scenario: Set bind forwarders - Given the bind application is enabled - And bind forwarders are set to 1.1.1.1 - When I set bind forwarders to 1.1.1.1 1.0.0.1 - Then bind forwarders should be 1.1.1.1 1.0.0.1 - -Scenario: Enable bind DNSSEC - Given the bind application is enabled - And bind DNSSEC is disabled - When I enable bind DNSSEC - Then bind DNSSEC should be enabled - -Scenario: Disable bind DNSSEC - Given the bind application is enabled - And bind DNSSEC is disabled - When I disable bind DNSSEC - Then bind DNSSEC should be disabled - -@backups -Scenario: Backup and restore bind - Given the bind application is enabled - When I set bind forwarders to 1.1.1.1 - And I disable bind DNSSEC - And I create a backup of the bind app data with name test_bind - And I set bind forwarders to 1.0.0.1 - And I enable bind DNSSEC - And I restore the bind app data backup with name test_bind - Then bind forwarders should be 1.1.1.1 - And bind DNSSEC should be disabled - -Scenario: Disable bind application - Given the bind application is enabled - When I disable the bind application - Then the bind service should not be running diff --git a/plinth/modules/bind/tests/test_functional.py b/plinth/modules/bind/tests/test_functional.py index 78e47183a..0fe336b0a 100644 --- a/plinth/modules/bind/tests/test_functional.py +++ b/plinth/modules/bind/tests/test_functional.py @@ -3,28 +3,67 @@ Functional, browser based tests for bind app. """ -from pytest_bdd import given, parsers, scenarios, then, when - +import pytest from plinth.tests import functional -scenarios('bind.feature') +pytestmark = [pytest.mark.system, pytest.mark.bind] -@given(parsers.parse('bind DNSSEC is {enable:w}')) -def bind_given_enable_dnssec(session_browser, enable): - should_enable = (enable == 'enabled') - _enable_dnssec(session_browser, should_enable) +@pytest.fixture(scope='module', autouse=True) +def fixture_background(session_browser): + """Login and install the app.""" + functional.login(session_browser) + functional.install(session_browser, 'bind') + yield + functional.app_disable(session_browser, 'bind') -@when(parsers.parse('I {enable:w} bind DNSSEC')) -def bind_enable_dnssec(session_browser, enable): - should_enable = (enable == 'enable') - _enable_dnssec(session_browser, should_enable) +def test_enable_disable(session_browser): + """Test enabling the app.""" + functional.app_disable(session_browser, 'bind') + + functional.app_enable(session_browser, 'bind') + assert functional.service_is_running(session_browser, 'bind') + + functional.app_disable(session_browser, 'bind') + assert functional.service_is_not_running(session_browser, 'bind') -@then(parsers.parse('bind DNSSEC should be {enabled:w}')) -def bind_assert_dnssec(session_browser, enabled): - assert _get_dnssec(session_browser) == (enabled == 'enabled') +def test_set_forwarders(session_browser): + """Test setting forwarders.""" + functional.app_enable(session_browser, 'bind') + functional.set_forwarders(session_browser, '1.1.1.1') + + functional.set_forwarders(session_browser, '1.1.1.1 1.0.0.1') + assert functional.get_forwarders(session_browser) == '1.1.1.1 1.0.0.1' + + +def test_enable_disable_dnssec(session_browser): + """Test enabling/disabling DNSSEC.""" + functional.app_enable(session_browser, 'bind') + _enable_dnssec(session_browser, False) + + _enable_dnssec(session_browser, True) + assert _get_dnssec(session_browser) + + _enable_dnssec(session_browser, False) + assert not _get_dnssec(session_browser) + + +@pytest.mark.backups +def test_backup(session_browser): + """Test backup and restore.""" + functional.app_enable(session_browser, 'bind') + functional.set_forwarders(session_browser, '1.1.1.1') + _enable_dnssec(session_browser, False) + functional.backup_create(session_browser, 'bind', 'test_bind') + + functional.set_forwarders(session_browser, '1.0.0.1') + _enable_dnssec(session_browser, True) + + functional.backup_restore(session_browser, 'bind', 'test_bind') + assert functional.get_forwarders(session_browser) == '1.1.1.1' + assert not _get_dnssec(session_browser) def _enable_dnssec(browser, enable):