Skip to content

Commit

Permalink
Update JsonLoader import (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaGombosER authored Sep 13, 2024
1 parent 0112ff7 commit 76ea598
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 59 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
Expand Down
3 changes: 2 additions & 1 deletion bin/debian-package-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package_installer/packageInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion package_installer/sourceAdder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 37 additions & 38 deletions tests/packageInstallerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
39 changes: 22 additions & 17 deletions tests/sourceAdderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit 76ea598

Please sign in to comment.