From 057a1255312dd17a64f59032c0da43657e2559cc Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 16 Nov 2021 08:17:22 -0800 Subject: [PATCH] app: Introduce API to setup an app Like the earlier API, accept old_version as parameter. A base implementation, simply call setup on all components. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/app.py | 8 ++++++++ plinth/tests/test_app.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plinth/app.py b/plinth/app.py index b93853b1e..0cc195039 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -113,6 +113,11 @@ class App: """ return self.get_component(self.app_id + '-info') + def setup(self, old_version): + """Install and configure the app and its components.""" + for component in self.components.values(): + component.setup(old_version=old_version) + def enable(self): """Enable all the components of the app.""" for component in self.components.values(): @@ -221,6 +226,9 @@ class Component: """ return App.get(self.app_id) + def setup(self, old_version): + """Run operations to install and configure 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 c2a05539d..95e95b092 100644 --- a/plinth/tests/test_app.py +++ b/plinth/tests/test_app.py @@ -4,7 +4,7 @@ Test module for App, base class for all applications. """ import collections -from unittest.mock import patch +from unittest.mock import Mock, call, patch import pytest @@ -114,6 +114,16 @@ def test_get_components_of_type(app_with_components): assert list(components) == leader_components +def test_app_setup(app_with_components): + """Test that running setup on an app run setup on components.""" + for component in app_with_components.components.values(): + component.setup = Mock() + + app_with_components.setup(old_version=2) + for component in app_with_components.components.values(): + component.setup.assert_has_calls([call(old_version=2)]) + + def test_app_enable(app_with_components): """Test that enabling an app enables components.""" app_with_components.disable() @@ -222,6 +232,24 @@ def test_component_app_property(): assert component.app == app +def test_component_setup(): + """Test running setup on component.""" + component = Component('test-component') + assert component.setup(old_version=1) is None + + +def test_component_enable(): + """Test running enable on component.""" + component = Component('test-component') + assert component.enable() is None + + +def test_component_disable(): + """Test running disable on component.""" + component = Component('test-component') + assert component.disable() is None + + def test_component_diagnose(): """Test running diagnostics on component.""" component = Component('test-component')