From 5dbf8908812e591a85a3aa82022f283eabfb3104 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 8 Mar 2024 19:38:59 -0800 Subject: [PATCH] tests: functional: Refactor install/setup fixture for apps - Fixes an issue with zoph not being setup after uninstall+install setup and makes a test pass. - Some failures exist but don't seem related to this change. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/matrixsynapse/tests/test_functional.py | 5 ++++- plinth/modules/mediawiki/tests/test_functional.py | 9 +++------ plinth/modules/shaarli/tests/test_functional.py | 9 +++------ plinth/modules/shadowsocks/tests/test_functional.py | 8 +++----- .../shadowsocksserver/tests/test_functional.py | 8 +++----- plinth/modules/zoph/tests/test_functional.py | 11 +++++------ plinth/tests/functional/__init__.py | 8 ++++++-- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/plinth/modules/matrixsynapse/tests/test_functional.py b/plinth/modules/matrixsynapse/tests/test_functional.py index 9a57103fd..b1bc4e3ce 100644 --- a/plinth/modules/matrixsynapse/tests/test_functional.py +++ b/plinth/modules/matrixsynapse/tests/test_functional.py @@ -21,7 +21,10 @@ class TestMatrixSynapseApp(functional.BaseAppTests): """Setup the app.""" functional.login(session_browser) functional.set_domain_name(session_browser, 'mydomain.example') - functional.install(session_browser, self.app_name) + + def install_and_setup(self, session_browser): + """Install the app and run setup.""" + super().install_and_setup(session_browser) functional.app_select_domain_name(session_browser, self.app_name, 'mydomain.example') diff --git a/plinth/modules/mediawiki/tests/test_functional.py b/plinth/modules/mediawiki/tests/test_functional.py index b82afdc2e..a01d0faeb 100644 --- a/plinth/modules/mediawiki/tests/test_functional.py +++ b/plinth/modules/mediawiki/tests/test_functional.py @@ -20,12 +20,9 @@ class TestMediawikiApp(functional.BaseAppTests): has_service = False has_web = True - @pytest.fixture(scope='class', autouse=True) - def fixture_setup(self, session_browser): - """Setup the app.""" - functional.login(session_browser) - functional.install(session_browser, 'mediawiki') - functional.app_enable(session_browser, 'mediawiki') + def install_and_setup(self, session_browser): + """Install the app and run setup.""" + super().install_and_setup(session_browser) _set_domain(session_browser) _set_admin_password(session_browser, 'whatever123') diff --git a/plinth/modules/shaarli/tests/test_functional.py b/plinth/modules/shaarli/tests/test_functional.py index 4a1cb4fdf..b756a8bf9 100644 --- a/plinth/modules/shaarli/tests/test_functional.py +++ b/plinth/modules/shaarli/tests/test_functional.py @@ -17,12 +17,9 @@ class TestShaarliApp(functional.BaseAppTests): has_service = False has_web = True - @pytest.fixture(scope='class', autouse=True) - def fixture_setup(self, session_browser): - """Setup the app.""" - functional.login(session_browser) - functional.install(session_browser, self.app_name) - functional.app_enable(session_browser, self.app_name) + def install_and_setup(self, session_browser): + """Install the app and set it up if needed.""" + super().install_and_setup(session_browser) self._shaarli_is_setup(session_browser) def _shaarli_is_setup(self, session_browser): diff --git a/plinth/modules/shadowsocks/tests/test_functional.py b/plinth/modules/shadowsocks/tests/test_functional.py index 87bcda6e0..1ed8fc38e 100644 --- a/plinth/modules/shadowsocks/tests/test_functional.py +++ b/plinth/modules/shadowsocks/tests/test_functional.py @@ -15,11 +15,9 @@ class TestShadowsocksApp(functional.BaseAppTests): has_service = True has_web = False - @pytest.fixture(scope='class', autouse=True) - def fixture_setup(self, session_browser): - """Setup the app.""" - functional.login(session_browser) - functional.install(session_browser, 'shadowsocks') + def install_and_setup(self, session_browser): + """Install the app and run setup.""" + super().install_and_setup(session_browser) _configure(session_browser, 'example.com', 'fakepassword') @pytest.mark.backups diff --git a/plinth/modules/shadowsocksserver/tests/test_functional.py b/plinth/modules/shadowsocksserver/tests/test_functional.py index c270bc163..4b0cc2c07 100644 --- a/plinth/modules/shadowsocksserver/tests/test_functional.py +++ b/plinth/modules/shadowsocksserver/tests/test_functional.py @@ -15,11 +15,9 @@ class TestShadowsocksServerApp(functional.BaseAppTests): has_service = True has_web = False - @pytest.fixture(scope='class', autouse=True) - def fixture_setup(self, session_browser): - """Setup the app.""" - functional.login(session_browser) - functional.install(session_browser, 'shadowsocksserver') + def install_and_setup(self, session_browser): + """Install the app and run setup.""" + super().install_and_setup(session_browser) _configure(session_browser, 'fakepassword') @pytest.mark.backups diff --git a/plinth/modules/zoph/tests/test_functional.py b/plinth/modules/zoph/tests/test_functional.py index 62fa7f82c..1b34c2abe 100644 --- a/plinth/modules/zoph/tests/test_functional.py +++ b/plinth/modules/zoph/tests/test_functional.py @@ -15,17 +15,16 @@ class TestZophApp(functional.BaseAppTests): has_service = False has_web = True - @pytest.fixture(scope='class', autouse=True) - def fixture_setup(self, session_browser): - """Setup the app.""" - functional.login(session_browser) - functional.install(session_browser, self.app_name) + def install_and_setup(self, session_browser): + """Install the app and run setup.""" + super().install_and_setup(session_browser) self._zoph_is_setup(session_browser) def _zoph_is_setup(self, session_browser): """Click setup button on the setup page.""" functional.nav_to_module(session_browser, self.app_name) - functional.submit(session_browser, form_class='form-configuration') + if session_browser.find_by_css('.form-configuration'): + functional.submit(session_browser, form_class='form-configuration') def assert_app_running(self, session_browser): assert functional.app_is_enabled(session_browser, self.app_name) diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index b5f232a86..e4349cf42 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -675,11 +675,15 @@ class BaseAppTests: if self.has_web: assert not is_available(session_browser, self.app_name) + def install_and_setup(self, session_browser): + """Install the app and set it up if needed.""" + install(session_browser, self.app_name) + @pytest.fixture(autouse=True) def fixture_background(self, session_browser): """Login, install, and enable the app.""" login(session_browser) - install(session_browser, self.app_name) + self.install_and_setup(session_browser) app_enable(session_browser, self.app_name) yield login(session_browser) @@ -728,4 +732,4 @@ class BaseAppTests: uninstall(session_browser, self.app_name) assert not is_installed(session_browser, self.app_name) - install(session_browser, self.app_name) + self.install_and_setup(session_browser)