From 382e23636acfc5ceea7aee13eac9bb0ac011ed1d Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Thu, 4 Oct 2018 22:03:46 -0700 Subject: [PATCH] pagekite: Add functional tests Reviewed-by: James Valleroy --- functional_tests/features/pagekite.feature | 39 ++++++++++++++ functional_tests/step_definitions/system.py | 47 ++++++++++++++++ functional_tests/support/interface.py | 2 +- functional_tests/support/system.py | 54 +++++++++++++++++-- .../templates/pagekite_configure.html | 4 +- 5 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 functional_tests/features/pagekite.feature diff --git a/functional_tests/features/pagekite.feature b/functional_tests/features/pagekite.feature new file mode 100644 index 000000000..bf21aebb3 --- /dev/null +++ b/functional_tests/features/pagekite.feature @@ -0,0 +1,39 @@ +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +@apps @pagekite +Feature: Pagekite Public Visibility + Configure Pagekite public visitbility server. + +Background: + Given I'm a logged in user + Given the pagekite application is installed + +Scenario: Enable pagekite application + Given pagekite is disabled + When I enable pagekite + Then pagekite should be enabled + +Scenario: Disable pagekite application + Given pagekite is enabled + When I disable pagekite + Then pagekite should be disabled + +Scenario: Configure pagekite application + Given pagekite is enabled + When I configure pagekite with host pagekite.example.com, port 8080, kite name mykite.example.com and kite secret mysecret + Then pagekite should be configured with host pagekite.example.com, port 8080, kite name mykite.example.com and kite secret mysecret diff --git a/functional_tests/step_definitions/system.py b/functional_tests/step_definitions/system.py index f84c3814f..5c3040882 100644 --- a/functional_tests/step_definitions/system.py +++ b/functional_tests/step_definitions/system.py @@ -130,3 +130,50 @@ def backup_export(browser, app_name): @when(parsers.parse('I restore the {app_name:w} app data backup')) def backup_restore(browser, app_name): system.backup_restore(browser, app_name) + + +@given('pagekite is enabled') +def pagekite_is_enabled(browser): + system.pagekite_enable(browser, True) + + +@given('pagekite is disabled') +def pagekite_is_disabled(browser): + system.pagekite_enable(browser, False) + + +@when('I enable pagekite') +def pagekite_enable(browser): + system.pagekite_enable(browser, True) + + +@when('I disable pagekite') +def pagekite_disable(browser): + system.pagekite_enable(browser, False) + + +@then('pagekite should be enabled') +def pagekite_assert_enabled(browser): + assert system.pagekite_is_enabled(browser) + + +@then('pagekite should be disabled') +def pagekite_assert_disabled(browser): + assert not system.pagekite_is_enabled(browser) + + +@when( + parsers.parse( + 'I configure pagekite with host {host:S}, port {port:d}, kite name {kite_name:S} and kite secret {kite_secret:w}' + )) +def pagekite_configure(browser, host, port, kite_name, kite_secret): + system.pagekite_configure(browser, host, port, kite_name, kite_secret) + + +@then( + parsers.parse( + 'pagekite should be configured with host {host:S}, port {port:d}, kite name {kite_name:S} and kite secret {kite_secret:w}' + )) +def pagekite_assert_configured(browser, host, port, kite_name, kite_secret): + assert (host, port, kite_name, + kite_secret) == system.pagekite_get_configuration(browser) diff --git a/functional_tests/support/interface.py b/functional_tests/support/interface.py index 6eea6eed4..9de43331e 100644 --- a/functional_tests/support/interface.py +++ b/functional_tests/support/interface.py @@ -28,7 +28,7 @@ from .service import wait_for_page_update sys_modules = [ 'avahi', 'backups', 'cockpit', 'config', 'datetime', 'diagnostics', 'dynamicdns', 'firewall', 'letsencrypt', 'monkeysphere', 'names', - 'networks', 'power', 'snapshot', 'upgrades', 'users' + 'networks', 'pagekite', 'power', 'snapshot', 'upgrades', 'users' ] default_url = config['DEFAULT']['url'] diff --git a/functional_tests/support/system.py b/functional_tests/support/system.py index d0a7c277e..dd613c1db 100644 --- a/functional_tests/support/system.py +++ b/functional_tests/support/system.py @@ -170,9 +170,8 @@ def backup_create(browser, app_name): def backup_export(browser, app_name): browser.visit(default_url) nav_to_module(browser, 'backups') - browser.find_link_by_href( - '/plinth/sys/backups/export/_functional_test_' - + app_name + '/').first.click() + browser.find_link_by_href('/plinth/sys/backups/export/_functional_test_' + + app_name + '/').first.click() browser.find_by_id('id_backups-disk_0').first.check() submit(browser) @@ -181,6 +180,51 @@ def backup_restore(browser, app_name): browser.visit(default_url) nav_to_module(browser, 'backups') browser.find_link_by_href( - '/plinth/sys/backups/restore/Root%2520Filesystem/_functional_test_' - + app_name + '.tar.gz/').first.click() + '/plinth/sys/backups/restore/Root%2520Filesystem/_functional_test_' + + app_name + '.tar.gz/').first.click() submit(browser) + + +def pagekite_enable(browser, should_enable): + """Enable/disable pagekite service.""" + nav_to_module(browser, 'pagekite') + browser.find_link_by_href('/plinth/sys/pagekite/configure/').first.click() + checkbox = browser.find_by_id('id_pagekite-enabled').first + if checkbox.checked == should_enable: + return + + if should_enable: + checkbox.check() + else: + checkbox.uncheck() + + submit(browser) + + +def pagekite_is_enabled(browser): + """Return whether pagekite is enabled.""" + nav_to_module(browser, 'pagekite') + browser.find_link_by_href('/plinth/sys/pagekite/configure/').first.click() + return browser.find_by_id('id_pagekite-enabled').value + + +def pagekite_configure(browser, host, port, kite_name, kite_secret): + """Configure pagekite basic parameters.""" + nav_to_module(browser, 'pagekite') + browser.find_link_by_href('/plinth/sys/pagekite/configure/').first.click() + #time.sleep(0.250) # Wait for 200ms show animation to complete + browser.fill('pagekite-server_domain', host) + browser.fill('pagekite-server_port', str(port)) + browser.fill('pagekite-kite_name', kite_name) + browser.fill('pagekite-kite_secret', kite_secret) + submit(browser) + + +def pagekite_get_configuration(browser): + """Return pagekite basic parameters.""" + nav_to_module(browser, 'pagekite') + browser.find_link_by_href('/plinth/sys/pagekite/configure/').first.click() + return (browser.find_by_name('pagekite-server_domain').value, + int(browser.find_by_name('pagekite-server_port').value), + browser.find_by_name('pagekite-kite_name').value, + browser.find_by_name('pagekite-kite_secret').value) diff --git a/plinth/modules/pagekite/templates/pagekite_configure.html b/plinth/modules/pagekite/templates/pagekite_configure.html index d9a609b52..b9f3a04ba 100644 --- a/plinth/modules/pagekite/templates/pagekite_configure.html +++ b/plinth/modules/pagekite/templates/pagekite_configure.html @@ -51,9 +51,9 @@ $('#id_pagekite-enabled').change(function() { if ($('#id_pagekite-enabled').prop('checked')) { - $('#pagekite-post-enabled-form').show('slow'); + $('#pagekite-post-enabled-form').show('fast'); } else { - $('#pagekite-post-enabled-form').hide('slow'); + $('#pagekite-post-enabled-form').hide('fast'); } });