backups: tests: Simplify functional test using more classes

- This makes the functional test focus more on the repository that is added
rather than all remote repositories.

Tests:

- Functional tests for backups app works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2026-02-04 18:53:45 -08:00
parent ff7c3a53a5
commit 2208a7b210
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
5 changed files with 23 additions and 19 deletions

View File

@ -16,7 +16,7 @@
<h3>{{ title }}</h3>
<form class="form" method="post">
<form class="form form-add-remote-repository" method="post">
{% if form.non_field_errors %}
<div class="alert alert-danger">
<a class="close" data-dismiss="alert">&times;</a>

View File

@ -4,8 +4,8 @@
{% load i18n %}
<div class="table-responsive">
<table class="table" id="archives-list">
<div class="table-responsive repository" data-repository-name="{{ repository.name }}">
<table class="table" class="archives-list">
<thead>
<tr>
<th colspan="2">
@ -23,7 +23,7 @@
</span>
{% endif %}
{{ repository.name }}
<span class="repository-name">{{ repository.name }}</span>
</div>
<div class="text-end">

View File

@ -24,7 +24,7 @@
</p>
<p>
<form class="form" method="post">
<form class="form form-remove-location" method="post">
{% csrf_token %}
<input type="submit" class="btn btn-danger"
@ -33,4 +33,3 @@
</p>
{% endblock %}

View File

@ -10,7 +10,7 @@
<h3>{{ title }}</h3>
<form class="form" method="post">
<form class="form form-verify-ssh-hostkey" method="post">
{% csrf_token %}
{% if form.ssh_public_key|length == 0 %}

View File

@ -190,6 +190,7 @@ def _download_file_logged_in(browser, url, suffix=''):
def _download(browser, archive_name=None):
"""Download a backup archive to a temporary file on disk."""
functional.nav_to_module(browser, 'backups')
href = f'/plinth/sys/backups/root/download/{archive_name}/'
url = functional.base_url + href
@ -198,11 +199,13 @@ def _download(browser, archive_name=None):
def _open_main_page(browser):
"""Open the FreedomBox interface main page."""
with functional.wait_for_page_update(browser):
browser.links.find_by_href('/plinth/').first.click()
def _upload_and_restore(browser, app_name, downloaded_file_path):
"""Upload a backup archive from the disk and perform restore operation."""
functional.nav_to_module(browser, 'backups')
with functional.wait_for_page_update(browser):
browser.links.find_by_href('/plinth/sys/backups/upload/').first.click()
@ -218,11 +221,14 @@ def _upload_and_restore(browser, app_name, downloaded_file_path):
def _has_remote_backup_location(browser) -> bool:
"""Return whether atleast one remote backup location is configured."""
functional.nav_to_module(browser, 'backups')
return browser.is_text_present(REMOTE_PATH)
return browser.is_element_present_by_css(
f'.repository[data-repository-name="{REMOTE_PATH}"]')
def _add_remote_backup_location(browser, ssh_use_password=True):
"""Add a remote backup location."""
if _has_remote_backup_location(browser):
_remove_remote_backup_location(browser)
@ -232,16 +238,15 @@ def _add_remote_backup_location(browser, ssh_use_password=True):
password = functional.get_password(
functional.config['DEFAULT']['username'])
if ssh_use_password:
browser.find_by_id('id_ssh_auth_type_password').first.check()
browser.find_by_id('id_ssh_auth_type_1').check()
browser.find_by_name('ssh_password').fill(password)
else:
browser.find_by_id('id_ssh_auth_type_key').first.check()
browser.find_by_id('id_ssh_auth_type_0').check()
browser.choose('id_encryption', 'repokey')
browser.find_by_name('encryption_passphrase').fill(password)
browser.find_by_name('confirm_encryption_passphrase').fill(password)
submit_button = browser.find_by_value('Create Location')
functional.submit(browser, element=submit_button)
functional.submit(browser, form_class='form-add-remote-repository')
assert browser.is_text_present('Added new remote SSH repository.')
@ -250,15 +255,15 @@ def _add_remote_backup_location(browser, ssh_use_password=True):
def _remove_remote_backup_location(browser):
remote_locations = browser.find_by_tag('table')[1]
remote_locations.links.find_by_partial_href('/delete/').first.click()
submit_button = browser.find_by_value('Remove Location')
functional.submit(browser, element=submit_button)
"""Remove the remote backup location with known remote path."""
repository = browser.find_by_css(
f'.repository[data-repository-name="{REMOTE_PATH}"]').first
repository.find_by_css('.repository-remove').first.click()
functional.submit(browser, form_class='form-remove-location')
def _verify_host_key(browser):
"""Verify the remote location's SSH host key."""
browser.find_by_name('ssh_public_key').first.click()
submit_button = browser.find_by_value('Verify Host')
functional.submit(browser, element=submit_button)
functional.submit(browser, form_class='form-verify-ssh-hostkey')
assert browser.is_text_present('SSH host verified.')