From 46f162d093ae64dcb121382692914e133c6ee034 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 31 May 2019 11:44:14 -0700 Subject: [PATCH] app: Add unique ID to each app class Also maintain a global list of apps Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/app.py | 14 +++++++++++++ plinth/modules/apache/__init__.py | 2 ++ plinth/modules/avahi/__init__.py | 2 ++ plinth/modules/backups/__init__.py | 2 ++ plinth/modules/bind/__init__.py | 2 ++ plinth/modules/cockpit/__init__.py | 2 ++ plinth/modules/config/__init__.py | 2 ++ plinth/modules/coquelicot/__init__.py | 2 ++ plinth/modules/datetime/__init__.py | 2 ++ plinth/modules/deluge/__init__.py | 2 ++ plinth/modules/diagnostics/__init__.py | 2 ++ plinth/modules/diaspora/__init__.py | 2 ++ plinth/modules/dynamicdns/__init__.py | 2 ++ plinth/modules/ejabberd/__init__.py | 2 ++ plinth/modules/firewall/__init__.py | 2 ++ plinth/modules/help/help.py | 2 ++ plinth/modules/i2p/__init__.py | 2 ++ plinth/modules/ikiwiki/__init__.py | 2 ++ plinth/modules/infinoted/__init__.py | 2 ++ plinth/modules/jsxc/__init__.py | 2 ++ plinth/modules/letsencrypt/__init__.py | 2 ++ plinth/modules/matrixsynapse/__init__.py | 2 ++ plinth/modules/mediawiki/__init__.py | 2 ++ plinth/modules/minetest/__init__.py | 2 ++ plinth/modules/mldonkey/__init__.py | 2 ++ plinth/modules/monkeysphere/__init__.py | 2 ++ plinth/modules/mumble/__init__.py | 2 ++ plinth/modules/names/__init__.py | 2 ++ plinth/modules/networks/__init__.py | 2 ++ plinth/modules/openvpn/__init__.py | 2 ++ plinth/modules/pagekite/__init__.py | 2 ++ plinth/modules/privoxy/__init__.py | 2 ++ plinth/modules/quassel/__init__.py | 6 ++++-- plinth/modules/radicale/__init__.py | 2 ++ plinth/modules/repro/__init__.py | 2 ++ plinth/modules/restore/__init__.py | 2 ++ plinth/modules/roundcube/__init__.py | 2 ++ plinth/modules/searx/__init__.py | 2 ++ plinth/modules/security/__init__.py | 2 ++ plinth/modules/shaarli/__init__.py | 2 ++ plinth/modules/shadowsocks/__init__.py | 2 ++ plinth/modules/sharing/__init__.py | 2 ++ plinth/modules/snapshot/__init__.py | 2 ++ plinth/modules/ssh/__init__.py | 2 ++ plinth/modules/storage/__init__.py | 2 ++ plinth/modules/syncthing/__init__.py | 2 ++ plinth/modules/tahoe/__init__.py | 2 ++ plinth/modules/tor/__init__.py | 2 ++ plinth/modules/transmission/__init__.py | 2 ++ plinth/modules/ttrss/__init__.py | 2 ++ plinth/modules/upgrades/__init__.py | 2 ++ plinth/modules/users/__init__.py | 2 ++ plinth/tests/test_app.py | 26 +++++++++++++++++++++--- 53 files changed, 141 insertions(+), 5 deletions(-) diff --git a/plinth/app.py b/plinth/app.py index 6e6e36981..e17a65d2e 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -31,10 +31,24 @@ class App: """ + app_id = None + _all_apps = collections.OrderedDict() + def __init__(self): """Initialize the app object.""" + if not self.app_id: + raise ValueError('Invalid app ID configured') + self.components = collections.OrderedDict() + # Add self to global list of apps + self._all_apps[self.app_id] = self + + @classmethod + def get(cls, app_id): + """Return an app with given ID.""" + return cls._all_apps[app_id] + def add(self, component): """Add a component to an app.""" self.components[component.component_id] = component diff --git a/plinth/modules/apache/__init__.py b/plinth/modules/apache/__init__.py index 536b6a4b1..19f646153 100644 --- a/plinth/modules/apache/__init__.py +++ b/plinth/modules/apache/__init__.py @@ -38,6 +38,8 @@ app = None class ApacheApp(app_module.App): """FreedomBox app for Apache web server.""" + app_id = 'apache' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py index 31e824907..e20177a96 100644 --- a/plinth/modules/avahi/__init__.py +++ b/plinth/modules/avahi/__init__.py @@ -63,6 +63,8 @@ app = None class AvahiApp(app_module.App): """FreedomBox app for Avahi.""" + app_id = 'avahi' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index f3c14749a..2d32de583 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -59,6 +59,8 @@ app = None class BackupsApp(app_module.App): """FreedomBox app for backup and restore.""" + app_id = 'backups' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index 34a341862..02bc421cd 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -90,6 +90,8 @@ app = None class BindApp(app_module.App): """FreedomBox app for Bind.""" + app_id = 'bind' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/cockpit/__init__.py b/plinth/modules/cockpit/__init__.py index 217aaef1c..e99e801a9 100644 --- a/plinth/modules/cockpit/__init__.py +++ b/plinth/modules/cockpit/__init__.py @@ -68,6 +68,8 @@ app = None class CockpitApp(app_module.App): """FreedomBox app for Cockpit.""" + app_id = 'cockpit' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/config/__init__.py b/plinth/modules/config/__init__.py index 1e730f8a3..c99741289 100644 --- a/plinth/modules/config/__init__.py +++ b/plinth/modules/config/__init__.py @@ -53,6 +53,8 @@ app = None class ConfigApp(app_module.App): """FreedomBox app for basic system configuration.""" + app_id = 'config' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/coquelicot/__init__.py b/plinth/modules/coquelicot/__init__.py index 9f492500d..d3d3eb9ce 100644 --- a/plinth/modules/coquelicot/__init__.py +++ b/plinth/modules/coquelicot/__init__.py @@ -61,6 +61,8 @@ app = None class CoquelicotApp(app_module.App): """FreedomBox app for Coquelicot.""" + app_id = 'coquelicot' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/datetime/__init__.py b/plinth/modules/datetime/__init__.py index 2b7b40681..6b8c6f208 100644 --- a/plinth/modules/datetime/__init__.py +++ b/plinth/modules/datetime/__init__.py @@ -53,6 +53,8 @@ app = None class DateTimeApp(app_module.App): """FreedomBox app for date and time.""" + app_id = 'datetime' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/deluge/__init__.py b/plinth/modules/deluge/__init__.py index efd07d0fd..c31bec212 100644 --- a/plinth/modules/deluge/__init__.py +++ b/plinth/modules/deluge/__init__.py @@ -64,6 +64,8 @@ app = None class DelugeApp(app_module.App): """FreedomBox app for Deluge.""" + app_id = 'deluge' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index b29e0e6fe..81f2b8a3e 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -46,6 +46,8 @@ app = None class DiagnosticsApp(app_module.App): """FreedomBox app for diagnostics.""" + app_id = 'diagnostics' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/diaspora/__init__.py b/plinth/modules/diaspora/__init__.py index a983158be..2e5e4f128 100644 --- a/plinth/modules/diaspora/__init__.py +++ b/plinth/modules/diaspora/__init__.py @@ -81,6 +81,8 @@ app = None class DiasporaApp(app_module.App): """FreedomBox app for Diaspora.""" + app_id = 'diaspora' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index c8963f26b..085a1ecfc 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -64,6 +64,8 @@ app = None class DynamicDNSApp(app_module.App): """FreedomBox app for Dynamic DNS.""" + app_id = 'dynamicdns' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 8b6f039a1..4a556a979 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -81,6 +81,8 @@ app = None class EjabberdApp(app_module.App): """FreedomBox app for ejabberd.""" + app_id = 'ejabberd' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/firewall/__init__.py b/plinth/modules/firewall/__init__.py index 540f1c3dd..a66d14ac3 100644 --- a/plinth/modules/firewall/__init__.py +++ b/plinth/modules/firewall/__init__.py @@ -53,6 +53,8 @@ app = None class FirewallApp(app_module.App): """FreedomBox app for Firewall.""" + app_id = 'firewall' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/help/help.py b/plinth/modules/help/help.py index 5b01b9dd8..c84926668 100644 --- a/plinth/modules/help/help.py +++ b/plinth/modules/help/help.py @@ -38,6 +38,8 @@ app = None class HelpApp(app_module.App): """FreedomBox app for showing help.""" + app_id = 'help' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/i2p/__init__.py b/plinth/modules/i2p/__init__.py index 7260b7f44..005f3bae6 100644 --- a/plinth/modules/i2p/__init__.py +++ b/plinth/modules/i2p/__init__.py @@ -80,6 +80,8 @@ app = None class I2PApp(app_module.App): """FreedomBox app for I2P.""" + app_id = 'i2p' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/ikiwiki/__init__.py b/plinth/modules/ikiwiki/__init__.py index 1f8225b93..51bf9c667 100644 --- a/plinth/modules/ikiwiki/__init__.py +++ b/plinth/modules/ikiwiki/__init__.py @@ -72,6 +72,8 @@ app = None class IkiwikiApp(app_module.App): """FreedomBox app for Ikiwiki.""" + app_id = 'ikiwiki' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/infinoted/__init__.py b/plinth/modules/infinoted/__init__.py index a0332a6f9..39014c3d1 100644 --- a/plinth/modules/infinoted/__init__.py +++ b/plinth/modules/infinoted/__init__.py @@ -62,6 +62,8 @@ app = None class InfinotedApp(app_module.App): """FreedomBox app for infinoted.""" + app_id = 'infinoted' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/jsxc/__init__.py b/plinth/modules/jsxc/__init__.py index 50d3a300e..4891b4c1c 100644 --- a/plinth/modules/jsxc/__init__.py +++ b/plinth/modules/jsxc/__init__.py @@ -55,6 +55,8 @@ app = None class JSXCApp(app_module.App): """FreedomBox app for JSXC.""" + app_id = 'jsxc' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/letsencrypt/__init__.py b/plinth/modules/letsencrypt/__init__.py index 3d88cdc51..a19d79608 100644 --- a/plinth/modules/letsencrypt/__init__.py +++ b/plinth/modules/letsencrypt/__init__.py @@ -74,6 +74,8 @@ app = None class LetsEncryptApp(app_module.App): """FreedomBox app for Let's Encrypt.""" + app_id = 'letsencrypt' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index e88fb2f31..b7974a227 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -77,6 +77,8 @@ app = None class MatrixSynapseApp(app_module.App): """FreedomBox app for Matrix Synapse.""" + app_id = 'matrixsynapse' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/mediawiki/__init__.py b/plinth/modules/mediawiki/__init__.py index 16761526d..9eb220af1 100644 --- a/plinth/modules/mediawiki/__init__.py +++ b/plinth/modules/mediawiki/__init__.py @@ -64,6 +64,8 @@ app = None class MediaWikiApp(app_module.App): """FreedomBox app for MediaWiki.""" + app_id = 'mediawiki' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index 1dd3b62e8..ccce4a7bd 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -81,6 +81,8 @@ app = None class MinetestApp(app_module.App): """FreedomBox app for Minetest.""" + app_id = 'minetest' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/mldonkey/__init__.py b/plinth/modules/mldonkey/__init__.py index 8b8f6a7ef..aa54901e0 100644 --- a/plinth/modules/mldonkey/__init__.py +++ b/plinth/modules/mldonkey/__init__.py @@ -70,6 +70,8 @@ app = None class MLDonkeyApp(app_module.App): """FreedomBox app for MLDonkey.""" + app_id = 'mldonkey' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/monkeysphere/__init__.py b/plinth/modules/monkeysphere/__init__.py index 0e4e6579b..2b1b8796a 100644 --- a/plinth/modules/monkeysphere/__init__.py +++ b/plinth/modules/monkeysphere/__init__.py @@ -60,6 +60,8 @@ app = None class MonkeysphereApp(app_module.App): """FreedomBox app for Monkeysphere.""" + app_id = 'monkeysphere' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index f014beeb0..64f409ea4 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -67,6 +67,8 @@ app = None class MumbleApp(app_module.App): """FreedomBox app for Mumble.""" + app_id = 'mumble' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index c244ba7aa..b9a30cf1c 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -63,6 +63,8 @@ app = None class NamesApp(app_module.App): """FreedomBox app for names.""" + app_id = 'names' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/networks/__init__.py b/plinth/modules/networks/__init__.py index 02ee855a9..0e11157bb 100644 --- a/plinth/modules/networks/__init__.py +++ b/plinth/modules/networks/__init__.py @@ -45,6 +45,8 @@ app = None class NetworksApp(app_module.App): """FreedomBox app for Networks.""" + app_id = 'networks' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index b8c39fb00..f51f6a7dd 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -63,6 +63,8 @@ app = None class OpenVPNApp(app_module.App): """FreedomBox app for OpenVPN.""" + app_id = 'openvpn' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/pagekite/__init__.py b/plinth/modules/pagekite/__init__.py index 3304637da..eb78b329e 100644 --- a/plinth/modules/pagekite/__init__.py +++ b/plinth/modules/pagekite/__init__.py @@ -82,6 +82,8 @@ app = None class PagekiteApp(app_module.App): """FreedomBox app for Pagekite.""" + app_id = 'pagekite' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index 52cc19f90..a18d1b08c 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -70,6 +70,8 @@ app = None class PrivoxyApp(app_module.App): """FreedomBox app for Privoxy.""" + app_id = 'privoxy' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py index 0c276aec4..4fcad5621 100644 --- a/plinth/modules/quassel/__init__.py +++ b/plinth/modules/quassel/__init__.py @@ -73,6 +73,8 @@ app = None class QuasselApp(app_module.App): """FreedomBox app for Quassel.""" + app_id = 'quassel' + def __init__(self): """Create components for the app.""" super().__init__() @@ -88,8 +90,8 @@ class QuasselApp(app_module.App): login_required=True) self.add(shortcut) - firewall = Firewall('firewall-quassel', name, - ports=['quassel-plinth'], is_external=True) + firewall = Firewall('firewall-quassel', name, ports=['quassel-plinth'], + is_external=True) self.add(firewall) diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py index af07907ca..dfe208a92 100644 --- a/plinth/modules/radicale/__init__.py +++ b/plinth/modules/radicale/__init__.py @@ -78,6 +78,8 @@ app = None class RadicaleApp(app_module.App): """FreedomBox app for Radicale.""" + app_id = 'radicale' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/repro/__init__.py b/plinth/modules/repro/__init__.py index 5fee5e8fd..ec64b4d8f 100644 --- a/plinth/modules/repro/__init__.py +++ b/plinth/modules/repro/__init__.py @@ -76,6 +76,8 @@ app = None class ReproApp(app_module.App): """FreedomBox app for Repro.""" + app_id = 'repro' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/restore/__init__.py b/plinth/modules/restore/__init__.py index 52d065ffa..dab62552d 100644 --- a/plinth/modules/restore/__init__.py +++ b/plinth/modules/restore/__init__.py @@ -62,6 +62,8 @@ app = None class RestoreApp(app_module.App): """FreedomBox app for Restore.""" + app_id = 'restore' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/roundcube/__init__.py b/plinth/modules/roundcube/__init__.py index cae9311ed..dc49478ce 100644 --- a/plinth/modules/roundcube/__init__.py +++ b/plinth/modules/roundcube/__init__.py @@ -69,6 +69,8 @@ app = None class RoundcubeApp(app_module.App): """FreedomBox app for Roundcube.""" + app_id = 'roundcube' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/searx/__init__.py b/plinth/modules/searx/__init__.py index eb7ec19ac..9b8d6a1c0 100644 --- a/plinth/modules/searx/__init__.py +++ b/plinth/modules/searx/__init__.py @@ -63,6 +63,8 @@ app = None class SearxApp(app_module.App): """FreedomBox app for Searx.""" + app_id = 'searx' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/security/__init__.py b/plinth/modules/security/__init__.py index 2e5a7f4a9..bc7815804 100644 --- a/plinth/modules/security/__init__.py +++ b/plinth/modules/security/__init__.py @@ -50,6 +50,8 @@ app = None class SecurityApp(app_module.App): """FreedomBox app for security.""" + app_id = 'security' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/shaarli/__init__.py b/plinth/modules/shaarli/__init__.py index bc1f1b246..4c0069dfd 100644 --- a/plinth/modules/shaarli/__init__.py +++ b/plinth/modules/shaarli/__init__.py @@ -56,6 +56,8 @@ app = None class ShaarliApp(app_module.App): """FreedomBox app for Shaarli.""" + app_id = 'shaarli' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/shadowsocks/__init__.py b/plinth/modules/shadowsocks/__init__.py index 66b343cde..ecdab7d9a 100644 --- a/plinth/modules/shadowsocks/__init__.py +++ b/plinth/modules/shadowsocks/__init__.py @@ -64,6 +64,8 @@ app = None class ShadowsocksApp(app_module.App): """FreedomBox app for Shadowsocks.""" + app_id = 'shadowsocks' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/sharing/__init__.py b/plinth/modules/sharing/__init__.py index 5398ab2eb..76fb6158d 100644 --- a/plinth/modules/sharing/__init__.py +++ b/plinth/modules/sharing/__init__.py @@ -46,6 +46,8 @@ app = None class SharingApp(app_module.App): """FreedomBox app for sharing files.""" + app_id = 'sharing' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/snapshot/__init__.py b/plinth/modules/snapshot/__init__.py index cac33421f..66f982c6c 100644 --- a/plinth/modules/snapshot/__init__.py +++ b/plinth/modules/snapshot/__init__.py @@ -64,6 +64,8 @@ app = None class SnapshotApp(app_module.App): """FreedomBox app for snapshots.""" + app_id = 'snapshot' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/ssh/__init__.py b/plinth/modules/ssh/__init__.py index a524ec1b4..dabf47083 100644 --- a/plinth/modules/ssh/__init__.py +++ b/plinth/modules/ssh/__init__.py @@ -56,6 +56,8 @@ app = None class SSHApp(app_module.App): """FreedomBox app for SSH.""" + app_id = 'ssh' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index 1e80cc714..4330fca7c 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -61,6 +61,8 @@ app = None class StorageApp(app_module.App): """FreedomBox app for storage.""" + app_id = 'storage' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/syncthing/__init__.py b/plinth/modules/syncthing/__init__.py index 0bdc9fb82..94eb60639 100644 --- a/plinth/modules/syncthing/__init__.py +++ b/plinth/modules/syncthing/__init__.py @@ -73,6 +73,8 @@ app = None class SyncthingApp(app_module.App): """FreedomBox app for Syncthing.""" + app_id = 'syncthing' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/tahoe/__init__.py b/plinth/modules/tahoe/__init__.py index 0b7de60d8..8f5cf34c2 100644 --- a/plinth/modules/tahoe/__init__.py +++ b/plinth/modules/tahoe/__init__.py @@ -66,6 +66,8 @@ app = None class TahoeApp(app_module.App): """FreedomBox app for Tahoe LAFS.""" + app_id = 'tahoe' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index 34a9b7f77..0b80074ca 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -69,6 +69,8 @@ app = None class TorApp(app_module.App): """FreedomBox app for Tor.""" + app_id = 'tor' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/transmission/__init__.py b/plinth/modules/transmission/__init__.py index 95465eb03..689a0152e 100644 --- a/plinth/modules/transmission/__init__.py +++ b/plinth/modules/transmission/__init__.py @@ -65,6 +65,8 @@ app = None class TransmissionApp(app_module.App): """FreedomBox app for Transmission.""" + app_id = 'transmission' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/ttrss/__init__.py b/plinth/modules/ttrss/__init__.py index 8d123bb3d..b51f21f77 100644 --- a/plinth/modules/ttrss/__init__.py +++ b/plinth/modules/ttrss/__init__.py @@ -72,6 +72,8 @@ app = None class TTRSSApp(app_module.App): """FreedomBox app for TT-RSS.""" + app_id = 'ttrss' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 2d6d7becb..27d3c16ab 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -49,6 +49,8 @@ app = None class UpgradesApp(app_module.App): """FreedomBox app for software upgrades.""" + app_id = 'upgrades' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index 3c42867c8..937b2ab38 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -54,6 +54,8 @@ app = None class UsersApp(app_module.App): """FreedomBox app for users and groups management.""" + app_id = 'users' + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/tests/test_app.py b/plinth/tests/test_app.py index 946bf7081..815b3d482 100644 --- a/plinth/tests/test_app.py +++ b/plinth/tests/test_app.py @@ -25,6 +25,11 @@ import pytest from plinth.app import App, Component, FollowerComponent, LeaderComponent +class TestApp(App): + """Sample App for testing.""" + app_id = 'test-app' + + class LeaderTest(FollowerComponent): """Test class for using LeaderComponent in tests.""" is_leader = True @@ -33,7 +38,7 @@ class LeaderTest(FollowerComponent): @pytest.fixture(name='app_with_components') def fixture_app_with_components(): """Setup an app with some components.""" - app = App() + app = TestApp() app.add(FollowerComponent('test-follower-1')) app.add(FollowerComponent('test-follower-2')) app.add(LeaderTest('test-leader-1')) @@ -41,16 +46,31 @@ def fixture_app_with_components(): return app +@pytest.fixture(name='empty_apps', autouse=True) +def fixture_empty_apps(): + """Remove all apps from global list before starting a test.""" + App._all_apps = collections.OrderedDict() + + def test_app_instantiation(): """Test that App is instantiated properly.""" - app = App() + app = TestApp() assert isinstance(app.components, collections.OrderedDict) assert not app.components + assert app.app_id == 'test-app' + assert app._all_apps['test-app'] == app + assert len(app._all_apps) == 1 + + +def test_get(): + """Test that an app can be correctly retrieved.""" + app = TestApp() + assert App.get(app.app_id) == app def test_app_add(): """Test adding a components to an App.""" - app = App() + app = TestApp() component = Component('test-component') return_value = app.add(component) assert len(app.components) == 1