|
1 | 1 | from unittest.mock import (
|
2 |
| - patch, Mock |
| 2 | + patch |
3 | 3 | )
|
4 | 4 |
|
5 | 5 | from suse_migration_services.migration_target import MigrationTarget
|
|
8 | 8 | class TestMigrationTarget(object):
|
9 | 9 | @patch('platform.machine')
|
10 | 10 | @patch('os.path.isfile')
|
11 |
| - @patch('suse_migration_services.command.Command.run') |
12 |
| - def test_get_migration_target( |
13 |
| - self, mock_Command_run, mock_os_path_isfile, |
| 11 | + @patch('suse_migration_services.migration_target.glob') |
| 12 | + def test_get_migration_target_empty( |
| 13 | + self, mock_glob, mock_os_path_isfile, |
14 | 14 | mock_platform_machine
|
15 | 15 | ):
|
16 | 16 | mock_platform_machine.return_value = 'x86_64'
|
17 |
| - sles15_migration = Mock() |
18 |
| - sles15_migration.returncode = 0 |
19 |
| - mock_Command_run.return_value = sles15_migration |
| 17 | + mock_glob.return_value = [] |
| 18 | + mock_os_path_isfile.return_value = False |
| 19 | + assert MigrationTarget.get_migration_target() == {} |
| 20 | + |
| 21 | + @patch('platform.machine') |
| 22 | + @patch('os.path.isfile') |
| 23 | + @patch('suse_migration_services.migration_target.glob') |
| 24 | + def test_get_migration_target_sles15( |
| 25 | + self, mock_glob, mock_os_path_isfile, |
| 26 | + mock_platform_machine |
| 27 | + ): |
| 28 | + mock_platform_machine.return_value = 'x86_64' |
| 29 | + mock_glob.return_value = [ |
| 30 | + '/migration-image/SLES15-Migration.x86_64-2.1.9-Build6.64.99.iso' |
| 31 | + ] |
20 | 32 | mock_os_path_isfile.return_value = False
|
21 | 33 | assert MigrationTarget.get_migration_target() == {
|
22 | 34 | 'identifier': 'SLES',
|
23 |
| - 'version': '15.3', |
| 35 | + 'version': '15.4', |
24 | 36 | 'arch': 'x86_64'
|
25 | 37 | }
|
26 | 38 |
|
27 | 39 | @patch('platform.machine')
|
28 | 40 | @patch('os.path.isfile')
|
29 |
| - @patch('suse_migration_services.command.Command.run') |
| 41 | + @patch('suse_migration_services.migration_target.glob') |
30 | 42 | def test_get_migration_target_sles16(
|
31 |
| - self, mock_Command_run, mock_os_path_isfile, |
| 43 | + self, mock_glob, mock_os_path_isfile, |
32 | 44 | mock_platform_machine
|
33 | 45 | ):
|
| 46 | + mock_glob.return_value = [ |
| 47 | + '/migration-image/SLES16-Migration.x86_64-2.1.23-Build2.1.iso' |
| 48 | + ] |
34 | 49 | mock_platform_machine.return_value = 'x86_64'
|
35 |
| - sles15_migration_not_found = Mock() |
36 |
| - sles15_migration_not_found.returncode = 1 # SLES15-Migration not found |
37 |
| - sles16_migration_found = Mock() |
38 |
| - sles16_migration_found.returncode = 0 # SLES16-Migration found |
39 |
| - mock_Command_run.side_effect = [sles15_migration_not_found, sles16_migration_found] |
40 | 50 | mock_os_path_isfile.return_value = False # No /etc/sle-migration-service.yml
|
41 | 51 | assert MigrationTarget.get_migration_target() == {
|
42 | 52 | 'identifier': 'SLES',
|
|
0 commit comments