From aa94d9f622ab9f88ef36588313fe0f8f321bab86 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 18 Aug 2022 22:06:39 -0700 Subject: [PATCH] app: Add API to uninstall an app Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/app.py | 8 ++++++++ plinth/tests/test_app.py | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plinth/app.py b/plinth/app.py index 408a7b90e..5e294ff06 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -133,6 +133,11 @@ class App: for component in self.components.values(): component.setup(old_version=old_version) + def uninstall(self): + """De-configure and uninstall the app.""" + for component in self.components.values(): + component.uninstall() + def get_setup_state(self) -> SetupState: """Return whether the app is not setup or needs upgrade.""" current_version = self.get_setup_version() @@ -280,6 +285,9 @@ class Component: def setup(self, old_version): """Run operations to install and configure the component.""" + def uninstall(self): + """De-configure and uninstall the component.""" + def enable(self): """Run operations to enable the component.""" diff --git a/plinth/tests/test_app.py b/plinth/tests/test_app.py index 91ca7fee8..353426daf 100644 --- a/plinth/tests/test_app.py +++ b/plinth/tests/test_app.py @@ -126,7 +126,7 @@ def test_get_components_of_type(app_with_components): def test_app_setup(app_with_components): - """Test that running setup on an app run setup on components.""" + """Test that running setup on an app runs setup on components.""" for component in app_with_components.components.values(): component.setup = Mock() @@ -135,6 +135,16 @@ def test_app_setup(app_with_components): component.setup.assert_has_calls([call(old_version=2)]) +def test_app_uninstall(app_with_components): + """Test that running uninstall on an app runs uninstall on components.""" + for component in app_with_components.components.values(): + component.uninstall = Mock() + + app_with_components.uninstall() + for component in app_with_components.components.values(): + component.uninstall.assert_has_calls([call()]) + + @pytest.mark.django_db def test_setup_state(): """Test retrieving the current setup state of the app.""" @@ -284,6 +294,12 @@ def test_component_setup(): assert component.setup(old_version=1) is None +def test_component_uninstall(): + """Test running uninstall on component.""" + component = Component('test-component') + assert component.uninstall() is None + + def test_component_enable(): """Test running enable on component.""" component = Component('test-component')