Debian Codegraph @

test/unit/container/setup/appx_test.py

raw
1 import io
2 from pytest import raises
3 from unittest.mock import (
4 patch, MagicMock
5 )
6
7 from kiwi.container.setup.appx import ContainerSetupAppx
8 from kiwi.defaults import Defaults
9
10 from kiwi.exceptions import KiwiContainerSetupError
11
12
13 class TestContainerSetupAppx:
14 @patch('os.path.exists')
15 def setup(self, mock_exists):
16 mock_exists.return_value = True
17 self.appx = ContainerSetupAppx(
18 'root_dir', {
19 'metadata_path': '../data/appx',
20 'image_version': '1.99.1',
21 'history': {
22 'created_by': 'SUSE',
23 'author': 'Marcus',
24 'application_id': '123',
25 'package_version': '2003.12.0.0',
26 'comment': 'Some Information',
27 'launcher': 'openSUSE-Tumbleweed.exe'
28 }
29 }
30 )
31
32 @patch('os.path.exists')
33 def setup_method(self, cls, mock_exists):
34 self.setup()
35
36 def test_setup_raises_no_manifest_file(self):
37 with patch('os.path.exists', return_value=True):
38 appx = ContainerSetupAppx(
39 'root_dir', {'metadata_path': 'artificial'}
40 )
41 with patch('os.path.exists', return_value=False):
42 with raises(KiwiContainerSetupError):
43 appx.setup()
44
45 @patch('lxml.etree.parse')
46 def test_setup_raises_xml_operations(self, mock_parse):
47 mock_parse.side_effect = Exception
48 with raises(KiwiContainerSetupError):
49 self.appx.setup()
50
51 def test_setup(self):
52 Defaults.set_platform_name('x86_64')
53 with patch('builtins.open', create=True) as mock_open:
54 mock_open.return_value = MagicMock(spec=io.IOBase)
55 file_handle = mock_open.return_value.__enter__.return_value
56 self.appx.setup()
57 # we expect all @..@ templates to got replaced
58 assert '@' not in file_handle.write.call_args_list