Backups: functional test to download and restore an archive

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Michael Pimmer 2018-11-09 16:24:37 +01:00 committed by James Valleroy
parent d4d5c15566
commit c988d468f2
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 62 additions and 3 deletions

View File

@ -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

View File

@ -15,6 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
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)

View File

@ -15,9 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
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')