diff --git a/.gitignore b/.gitignore index 97d2d68..b2da71a 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,6 @@ pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports -htmlcov/ .tox/ .nox/ .coverage diff --git a/bin/debian-package-installer.py b/bin/debian-package-installer.py index 4a967aa..734b5b7 100644 --- a/bin/debian-package-installer.py +++ b/bin/debian-package-installer.py @@ -9,7 +9,8 @@ from apt.cache import Cache from aptsources.sourceslist import SourcesList -from common_utility import JsonLoader, SessionProvider, FileDownloader +from common_utility import SessionProvider, FileDownloader +from common_utility.jsonLoader import JsonLoader from context_logger import get_logger, setup_logging from package_downloader import DebDownloader, AssetDownloader, RepositoryProvider diff --git a/package_installer/packageInstaller.py b/package_installer/packageInstaller.py index 4e2dab1..e00ee7a 100644 --- a/package_installer/packageInstaller.py +++ b/package_installer/packageInstaller.py @@ -5,7 +5,7 @@ from typing import Optional from apt import Cache -from common_utility import IJsonLoader +from common_utility.jsonLoader import IJsonLoader from context_logger import get_logger from package_downloader import PackageConfig diff --git a/package_installer/sourceAdder.py b/package_installer/sourceAdder.py index a5c32c9..c3fc520 100644 --- a/package_installer/sourceAdder.py +++ b/package_installer/sourceAdder.py @@ -5,7 +5,8 @@ from urllib.parse import urlparse from aptsources.sourceslist import SourcesList, SourceEntry -from common_utility import IJsonLoader, IFileDownloader +from common_utility import IFileDownloader +from common_utility.jsonLoader import IJsonLoader from context_logger import get_logger from package_installer import SourceConfig, IKeyAdder diff --git a/tests/packageInstallerTest.py b/tests/packageInstallerTest.py index 184f4d8..5bd5742 100644 --- a/tests/packageInstallerTest.py +++ b/tests/packageInstallerTest.py @@ -3,8 +3,9 @@ from unittest.mock import MagicMock from apt import Cache +from common_utility.jsonLoader import IJsonLoader from context_logger import setup_logging -from package_downloader import PackageConfig, IJsonLoader +from package_downloader import PackageConfig from package_installer import PackageInstaller, IAptInstaller, IDebInstaller, ISourceAdder @@ -27,11 +28,7 @@ def test_install_packages_initialize_apt_cache(self): package_installer.install_packages() # Then - apt_cache.assert_has_calls([ - mock.call.open(), - mock.call.update(), - mock.call.open() - ]) + apt_cache.assert_has_calls([mock.call.open(), mock.call.update(), mock.call.open()]) def test_install_packages_from_apt_repository(self): # Given @@ -43,10 +40,16 @@ def test_install_packages_from_apt_repository(self): package_installer.install_packages() # Then - apt_installer.install.assert_has_calls([ - mock.call(config_list[0]), mock.call().__bool__(), - mock.call(config_list[1]), mock.call().__bool__(), - mock.call(config_list[2]), mock.call().__bool__()]) + apt_installer.install.assert_has_calls( + [ + mock.call(config_list[0]), + mock.call().__bool__(), + mock.call(config_list[1]), + mock.call().__bool__(), + mock.call(config_list[2]), + mock.call().__bool__(), + ] + ) def test_install_packages_from_dep_package(self): # Given @@ -59,14 +62,19 @@ def test_install_packages_from_dep_package(self): package_installer.install_packages() # Then - apt_installer.install.assert_has_calls([ - mock.call(config_list[0]), - mock.call(config_list[1]), - mock.call(config_list[2])]) - deb_installer.install.assert_has_calls([ - mock.call(config_list[0]), mock.call().__bool__(), - mock.call(config_list[1]), mock.call().__bool__(), - mock.call(config_list[2]), mock.call().__bool__()]) + apt_installer.install.assert_has_calls( + [mock.call(config_list[0]), mock.call(config_list[1]), mock.call(config_list[2])] + ) + deb_installer.install.assert_has_calls( + [ + mock.call(config_list[0]), + mock.call().__bool__(), + mock.call(config_list[1]), + mock.call().__bool__(), + mock.call(config_list[2]), + mock.call().__bool__(), + ] + ) def test_install_packages_fail_to_install(self): # Given @@ -80,14 +88,12 @@ def test_install_packages_fail_to_install(self): package_installer.install_packages() # Then - apt_installer.install.assert_has_calls([ - mock.call(config_list[0]), - mock.call(config_list[1]), - mock.call(config_list[2])]) - deb_installer.install.assert_has_calls([ - mock.call(config_list[0]), - mock.call(config_list[1]), - mock.call(config_list[2])]) + apt_installer.install.assert_has_calls( + [mock.call(config_list[0]), mock.call(config_list[1]), mock.call(config_list[2])] + ) + deb_installer.install.assert_has_calls( + [mock.call(config_list[0]), mock.call(config_list[1]), mock.call(config_list[2])] + ) def test_install_packages_with_mixed_outcome(self): # Given @@ -101,21 +107,14 @@ def test_install_packages_with_mixed_outcome(self): package_installer.install_packages() # Then - apt_installer.install.assert_has_calls([ - mock.call(config_list[0]), - mock.call(config_list[1]), - mock.call(config_list[2])]) - deb_installer.install.assert_has_calls([ - mock.call(config_list[1]), - mock.call(config_list[2])]) + apt_installer.install.assert_has_calls( + [mock.call(config_list[0]), mock.call(config_list[1]), mock.call(config_list[2])] + ) + deb_installer.install.assert_has_calls([mock.call(config_list[1]), mock.call(config_list[2])]) def create_config_list(): - return [ - PackageConfig(package='package1'), - PackageConfig(package='package2'), - PackageConfig(package='package3') - ] + return [PackageConfig(package='package1'), PackageConfig(package='package2'), PackageConfig(package='package3')] def create_components(config_list): diff --git a/tests/sourceAdderTest.py b/tests/sourceAdderTest.py index df9c4c1..c9633d9 100644 --- a/tests/sourceAdderTest.py +++ b/tests/sourceAdderTest.py @@ -3,8 +3,9 @@ from unittest.mock import MagicMock from aptsources.sourceslist import SourcesList +from common_utility.jsonLoader import IJsonLoader from context_logger import setup_logging -from package_downloader import IJsonLoader, IFileDownloader +from package_downloader import IFileDownloader from package_installer import IKeyAdder, SourceAdder, SourceConfig @@ -54,25 +55,29 @@ def test_add_sources_fails_to_add_key(self): def create_components(): json_loader = MagicMock(spec=IJsonLoader) json_loader.load_list.return_value = [ - SourceConfig(name='source1', source='deb http://url1 stable main', - key_id='0123456789ABCDEF012345671111111111111111', - key_file='http://url1/dists/stable/public1.key', - key_server='keyserver.test1.com'), - SourceConfig(name='source2', source='deb http://url2 stable main', - key_id='0123456789ABCDEF012345672222222222222222', - key_file='http://url2/dists/stable/public2.key'), - SourceConfig(name='source3', source='deb http://url3 stable main', - key_id='0123456789ABCDEF012345673333333333333333', - key_file='/path/to/public3.key') + SourceConfig( + name='source1', + source='deb http://url1 stable main', + key_id='0123456789ABCDEF012345671111111111111111', + key_file='http://url1/dists/stable/public1.key', + key_server='keyserver.test1.com', + ), + SourceConfig( + name='source2', + source='deb http://url2 stable main', + key_id='0123456789ABCDEF012345672222222222222222', + key_file='http://url2/dists/stable/public2.key', + ), + SourceConfig( + name='source3', + source='deb http://url3 stable main', + key_id='0123456789ABCDEF012345673333333333333333', + key_file='/path/to/public3.key', + ), ] sources_list = MagicMock(spec=SourcesList) key_adder = MagicMock(spec=IKeyAdder) - key_adder.get_available_key_ids.side_effect = [ - [], - ['1111111111111111'], - ['2222222222222222'], - ['3333333333333333'] - ] + key_adder.get_available_key_ids.side_effect = [[], ['1111111111111111'], ['2222222222222222'], ['3333333333333333']] file_downloader = MagicMock(spec=IFileDownloader) file_downloader.download.return_value = '/path/to/public2.key'