diff --git a/functional_tests/features/bind.feature b/functional_tests/features/bind.feature
index f6d2651a2..a735ef8d5 100644
--- a/functional_tests/features/bind.feature
+++ b/functional_tests/features/bind.feature
@@ -61,3 +61,12 @@ Scenario: Backup and restore bind
And I restore the bind app data backup
Then bind forwarders should be 1.1.1.1
And bind DNSSEC should be disabled
+
+Scenario: Download, upload and restore a backup
+ Given the bind application is enabled
+ When I set bind forwarders to 1.1.1.1
+ And I create a backup of the bind app data
+ And I set bind forwarders to 1.0.0.1
+ And I download the bind app data backup
+ And I restore the downloaded bind app data backup
+ Then bind forwarders should be 1.1.1.1
diff --git a/functional_tests/step_definitions/system.py b/functional_tests/step_definitions/system.py
index 1f87302f6..c8932f94a 100644
--- a/functional_tests/step_definitions/system.py
+++ b/functional_tests/step_definitions/system.py
@@ -15,6 +15,8 @@
# along with this program. If not, see .
#
+import os
+
from pytest_bdd import given, parsers, then, when
from support import system
@@ -172,11 +174,31 @@ def backup_create(browser, app_name):
system.backup_create(browser, app_name)
+@when(parsers.parse('I download the {app_name:w} app data backup'))
+def backup_download(browser, app_name, downloaded_file_info):
+ url = '/plinth/sys/backups/export-and-download/_functional_test_%s/' % \
+ app_name
+ file_path = system.download_file_logged_in(browser, url, app_name,
+ suffix='.tar.gz')
+ downloaded_file_info['path'] = file_path
+
+
@when(parsers.parse('I restore the {app_name:w} app data backup'))
def backup_restore(browser, app_name):
system.backup_restore(browser, app_name)
+@when(parsers.parse('I restore the downloaded {app_name:w} app data backup'))
+def backup_restore_from_upload(browser, app_name, downloaded_file_info):
+ path = downloaded_file_info["path"]
+ try:
+ system.backup_upload_and_restore(browser, app_name, path)
+ except Exception as err:
+ raise err
+ finally:
+ os.remove(path)
+
+
@given('pagekite is enabled')
def pagekite_is_enabled(browser):
system.pagekite_enable(browser, True)
diff --git a/functional_tests/support/system.py b/functional_tests/support/system.py
index d815b4db8..03e410f31 100644
--- a/functional_tests/support/system.py
+++ b/functional_tests/support/system.py
@@ -15,9 +15,11 @@
# along with this program. If not, see .
#
-from support import application, config
+from urllib.parse import urlparse
+import requests
+import tempfile
-from . import application
+from . import application, config
from .interface import default_url, nav_to_module, submit
from .service import wait_for_page_update
@@ -206,11 +208,37 @@ def backup_restore(browser, app_name):
browser.visit(default_url)
nav_to_module(browser, 'backups')
browser.find_link_by_href(
- '/plinth/sys/backups/restore-archive/%252F/_functional_test_' +
+ '/plinth/sys/backups/restore-archive/_functional_test_' +
app_name + '/').first.click()
submit(browser)
+def backup_upload_and_restore(browser, app_name, downloaded_file_path):
+ browser.visit(default_url)
+ nav_to_module(browser, 'backups')
+ browser.find_link_by_href('/plinth/sys/backups/upload/').first.click()
+ fileinput = browser.driver.find_element_by_id('id_backups-file')
+ fileinput.send_keys(downloaded_file_path)
+ # submit upload form
+ submit(browser)
+ # submit restore form
+ with wait_for_page_update(browser, expected_url='/plinth/sys/backups/'):
+ submit(browser)
+
+
+def download_file_logged_in(browser, url_path, app_names, suffix=''):
+ """Download a file from Plinth, pretend being logged in via cookies"""
+ current_url = urlparse(browser.url)
+ url = "%s://%s%s" % (current_url.scheme, current_url.netloc, url_path)
+ cookies = browser.driver.get_cookies()
+ cookies = {cookie["name"]: cookie["value"] for cookie in cookies}
+ response = requests.get(url, verify=False, cookies=cookies)
+ with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
+ for chunk in response.iter_content(chunk_size=128):
+ temp_file.write(chunk)
+ return temp_file.name
+
+
def pagekite_enable(browser, should_enable):
"""Enable/disable pagekite service."""
nav_to_module(browser, 'pagekite')