package: Add parameter to specify skipping package recommendations

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-11-16 08:20:13 -08:00 committed by James Valleroy
parent 057a125531
commit 2157cb33b7
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 24 additions and 2 deletions

View File

@ -27,18 +27,23 @@ class Packages(app.FollowerComponent):
of packages required by an app.
"""
def __init__(self, component_id: str, packages: list[str]):
def __init__(self, component_id: str, packages: list[str],
skip_recommends=False):
"""Initialize a new packages component.
'component_id' should be a unique ID across all components of an app
and across all components.
'packages' is the list of Debian packages managed by this component.
'skip_recommends' is a boolean specifying whether recommended packages
should be installed along with the listed packages.
"""
super().__init__(component_id)
self.component_id = component_id
self._packages = packages
self.skip_recommends = skip_recommends
@property
def packages(self) -> list[str]:

View File

@ -5,8 +5,25 @@ Test module for package module.
from unittest.mock import call, patch
import pytest
from plinth.errors import ActionError
from plinth.package import packages_installed, remove
from plinth.package import Packages, packages_installed, remove
def test_packages_init():
"""Test initialization of packages component."""
component = Packages('test-component', ['foo', 'bar'])
assert component.component_id == 'test-component'
assert component.packages == ['foo', 'bar']
assert not component.skip_recommends
with pytest.raises(ValueError):
Packages(None, [])
component = Packages('test-component', [], skip_recommends=True)
assert component.packages == []
assert component.skip_recommends
def test_packages_installed():