Verified Commit 4d3f0411 authored by Michael P's avatar Michael P

Backups: functional tests update; restoring backup bugfix

- updated functional tests to work with changed UI
- fixed bug when restoring an uploaded file
parent 241e1806
Pipeline #27990 failed with stages
in 4 minutes and 29 seconds
......@@ -67,6 +67,6 @@ Scenario: Download, upload and restore a backup
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
And I download the latest app data backup
And I restore the downloaded app data backup
Then bind forwarders should be 1.1.1.1
......@@ -183,12 +183,9 @@ 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/download/root/_functional_test_%s/' % \
app_name
file_path = system.download_file_logged_in(browser, url, app_name,
suffix='.tar.gz')
@when(parsers.parse('I download the latest app data backup'))
def backup_download(browser, downloaded_file_info):
file_path = system.download_latest_backup(browser)
downloaded_file_info['path'] = file_path
......@@ -197,7 +194,7 @@ 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'))
@when(parsers.parse('I restore the downloaded app data backup'))
def backup_restore_from_upload(browser, app_name, downloaded_file_info):
path = downloaded_file_info["path"]
try:
......
......@@ -200,7 +200,6 @@ def backup_create(browser, app_name):
application.install(browser, 'backups')
browser.find_link_by_href('/plinth/sys/backups/create/').first.click()
browser.find_by_id('id_backups-name').fill('_functional_test_' + app_name)
for app in browser.find_by_css('input[type=checkbox]'):
app.uncheck()
......@@ -233,10 +232,20 @@ def backup_upload_and_restore(browser, app_name, downloaded_file_path):
submit(browser)
def download_file_logged_in(browser, url_path, app_names, suffix=''):
def download_latest_backup(browser):
nav_to_module(browser, 'backups')
path = "//a[starts-with(@href,'/plinth/sys/backups/download/root')]"
ele = browser.driver.find_elements_by_xpath(path)[0]
url = ele.get_attribute('href')
file_path = download_file_logged_in(browser, url, suffix='.tar.gz')
return file_path
def download_file_logged_in(browser, url, 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)
if not url.startswith("http"):
current_url = urlparse(browser.url)
url = "%s://%s%s" % (current_url.scheme, current_url.netloc, url)
cookies = browser.driver.get_cookies()
cookies = {cookie["name"]: cookie["value"] for cookie in cookies}
response = requests.get(url, verify=False, cookies=cookies)
......
......@@ -96,7 +96,7 @@ def get_exported_archive_apps(path):
return output.splitlines()
def _restore_exported_archive_handler(packet):
def _restore_exported_archive_handler(packet, encryption_passphrase=None):
"""Perform restore operation on packet."""
locations = {'directories': packet.directories, 'files': packet.files}
locations_data = json.dumps(locations)
......
......@@ -96,7 +96,9 @@ class BorgRepository(object):
def list_archives(self):
output = self.run(['list-repo', '--path', self.repo_path])
return json.loads(output)['archives']
archives = json.loads(output)['archives']
return sorted(archives, key=lambda archive: archive['start'],
reverse=True)
def get_view_content(self):
"""Get archives with additional information as needed by the view"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment