tests: Add BaseAppTests class for common functional tests

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Use the verb 'assert' instead of 'confirm']
[sunil: More documentation for base app tests class]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2021-10-15 06:58:33 -04:00 committed by Sunil Mohan Adapa
parent 8899bdef7b
commit 74e3cb9946
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -583,3 +583,65 @@ def user_exists(browser, name):
nav_to_module(browser, 'users')
links = browser.links.find_by_href(f'/plinth/sys/users/{name}/edit/')
return len(links) == 1
class BaseAppTests:
"""Base class for common functional tests.
To run these tests on an app, the app should subclass this class with a
class name starting with 'Test'. This allows the app tests to be
automatically discovered while the base class tests to stay undiscovered.
Tests will apply to the app without the need not override each test.
"""
app_name = ''
# TODO: Check the components of the app instead of configuring here.
has_service = False
has_web = True
def assert_app_running(self, session_browser):
"""Assert that the app is running."""
if self.has_service:
assert service_is_running(session_browser, self.app_name)
if self.has_web:
assert is_available(session_browser, self.app_name)
def assert_app_not_running(self, session_browser):
"""Assert that the app is not running."""
if self.has_service:
assert service_is_not_running(session_browser, self.app_name)
if self.has_web:
assert not is_available(session_browser, self.app_name)
@pytest.fixture(scope='class', autouse=True)
def fixture_background(self, session_browser):
"""Login and install the app."""
login(session_browser)
install(session_browser, self.app_name)
yield
app_disable(session_browser, self.app_name)
def test_enable_disable(self, session_browser):
"""Test enabling and disabling the app."""
app_disable(session_browser, self.app_name)
app_enable(session_browser, self.app_name)
self.assert_app_running(session_browser)
app_disable(session_browser, self.app_name)
self.assert_app_not_running(session_browser)
def test_run_diagnostics(self, session_browser):
"""Test that all app diagnostics are passing."""
app_enable(session_browser, self.app_name)
# TODO
@pytest.mark.backups
def test_backup_restore(self, session_browser):
"""Test that backup and restore operations work on the app."""
app_enable(session_browser, self.app_name)
backup_create(session_browser, self.app_name, 'test_' + self.app_name)
backup_restore(session_browser, self.app_name, 'test_' + self.app_name)
self.assert_app_running(session_browser)