| 1 |
from unittest.mock import ( |
| 2 |
patch, Mock, call |
| 3 |
) |
| 4 |
from pytest import raises |
| 5 |
|
| 6 |
from kiwi.defaults import Defaults |
| 7 |
from kiwi.iso_tools.base import IsoToolsBase |
| 8 |
|
| 9 |
|
| 10 |
class TestIsoToolsBase: |
| 11 |
def setup(self): |
| 12 |
Defaults.set_platform_name('x86_64') |
| 13 |
self.iso_tool = IsoToolsBase('source-dir') |
| 14 |
|
| 15 |
def setup_method(self, cls): |
| 16 |
self.setup() |
| 17 |
|
| 18 |
def test_create_iso(self): |
| 19 |
with raises(NotImplementedError): |
| 20 |
self.iso_tool.create_iso('filename') |
| 21 |
|
| 22 |
def test_list_iso(self): |
| 23 |
with raises(NotImplementedError): |
| 24 |
self.iso_tool.list_iso('isofile') |
| 25 |
|
| 26 |
def test_get_tool_name(self): |
| 27 |
with raises(NotImplementedError): |
| 28 |
self.iso_tool.get_tool_name() |
| 29 |
|
| 30 |
def test_init_iso_creation_parameters(self): |
| 31 |
with raises(NotImplementedError): |
| 32 |
self.iso_tool.init_iso_creation_parameters() |
| 33 |
|
| 34 |
def test_add_efi_loader_parameters(self): |
| 35 |
with raises(NotImplementedError): |
| 36 |
self.iso_tool.add_efi_loader_parameters('loader_file') |
| 37 |
|
| 38 |
def test_has_iso_hybrid_capability(self): |
| 39 |
with raises(NotImplementedError): |
| 40 |
self.iso_tool.has_iso_hybrid_capability() |
| 41 |
|
| 42 |
@patch('kiwi.iso_tools.base.DataSync') |
| 43 |
@patch('kiwi.iso_tools.base.shutil') |
| 44 |
@patch('kiwi.iso_tools.base.Command.run') |
| 45 |
@patch('kiwi.iso_tools.base.Path') |
| 46 |
@patch('os.path.exists') |
| 47 |
def test_setup_media_loader_directory( |
| 48 |
self, mock_exists, mock_Path, mock_command, mock_shutil, mock_sync |
| 49 |
): |
| 50 |
mock_exists.return_value = True |
| 51 |
data = Mock() |
| 52 |
mock_sync.return_value = data |
| 53 |
self.iso_tool.setup_media_loader_directory( |
| 54 |
'root_dir', 'media_dir', 'openSUSE' |
| 55 |
) |
| 56 |
assert mock_shutil.copy.call_args_list == [ |
| 57 |
call( |
| 58 |
'root_dir/usr/share/grub2/i386-pc/eltorito.img', |
| 59 |
'root_dir/image/loader/' |
| 60 |
), |
| 61 |
call( |
| 62 |
'root_dir/usr/share/grub2/i386-pc/boot_hybrid.img', |
| 63 |
'root_dir/image/loader/' |
| 64 |
) |
| 65 |
] |
| 66 |
assert mock_command.call_args_list == [ |
| 67 |
call( |
| 68 |
command=[ |
| 69 |
'bash', '-c', |
| 70 |
'cp root_dir/boot/memtest* ' |
| 71 |
'root_dir/image/loader//memtest' |
| 72 |
], raise_on_error=False |
| 73 |
), |
| 74 |
call( |
| 75 |
[ |
| 76 |
'bash', '-c', |
| 77 |
'cp root_dir/etc/bootsplash/themes/openSUSE/' |
| 78 |
'cdrom/* root_dir/image/loader/' |
| 79 |
] |
| 80 |
), |
| 81 |
call( |
| 82 |
[ |
| 83 |
'gfxboot', |
| 84 |
'--config-file', 'root_dir/image/loader//gfxboot.cfg', |
| 85 |
'--change-config', 'install::autodown=0' |
| 86 |
] |
| 87 |
), |
| 88 |
call( |
| 89 |
[ |
| 90 |
'cp', |
| 91 |
'root_dir/etc/bootsplash/themes/openSUSE/' |
| 92 |
'bootloader/message', 'root_dir/image/loader/' |
| 93 |
] |
| 94 |
) |
| 95 |
] |
| 96 |
mock_sync.assert_called_once_with( |
| 97 |
'root_dir/image/loader/', |
| 98 |
'media_dir/boot/x86_64/loader' |
| 99 |
) |
| 100 |
data.sync_data.assert_called_once_with( |
| 101 |
options=['-a'] |
| 102 |
) |