3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # pylint: disable=invalid-name
22 from tools.script.create_rpm_data import RpmDataBuilder
23 from tools.repository import BuildConfigParser
24 from tools.executor import Result
25 import tools.repository
26 from tools.script.create_rpm_data_test_data import \
27 yum_installed_output, \
30 basesystem_combined, \
32 centos_logos_combined, \
33 dejavu_fonts_common_combined, yum_available_output, \
34 crypto_rpms_json, boms_output
36 from tools.test_data_rpm import basesystem_rpm_info, cpp_rpm_info, centos_logos_rpm_info, \
37 dejavu_fonts_common_rpm_info
38 from tools.test_data_yum import basesystem_yum_info, cpp_yum_info, centos_logos_yum_info, \
39 dejavu_fonts_common_yum_info
40 from tools.yum import YumConfig
43 @mock.patch.object(YumConfig, 'write')
44 @mock.patch.object(tools.yum, 'run')
45 @mock.patch.object(BuildConfigParser, 'items')
46 def test_complete_parse(mock_config, mock_reporeader, _):
47 logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
48 mock_config.side_effect = [
49 [('base', 'test-url-for-base'),
50 ('none1', 'test-url-for-none1'),
51 ('none2', 'test-url-for-none2')],
52 [('purkki-3rdparty', 'test-url-for-purkki-3rdparty#test-extra-option=test-value')],
53 [('base', 'src-test-url-for-base'),
54 ('none1', 'src-test-url-for-none1'),
55 ('none2', 'src-test-url-for-none2')],
56 [('purkki-3rdparty', 'src-test-url-for-purkki-3rdparty#test-extra-option2=test-value2')]
58 mock_reporeader.side_effect = [Result(0, '', ''), # yum clean all
59 Result(0, '', ''), # rm -rf /var/yum/cache
60 Result(0, yum_available_output, '')]
61 os.environ['BUILD_URL'] = 'test-url/'
62 os.environ['WORKSPACE'] = '/foo/path'
63 result = RpmDataBuilder('fake_build_config_path',
68 assert mock_reporeader.call_count == 3
69 assert result == expected_output
72 @pytest.mark.parametrize('yum_info, rpm_info, expected_combined', [
73 (basesystem_yum_info, basesystem_rpm_info, basesystem_combined),
74 (cpp_yum_info, cpp_rpm_info, cpp_combined),
75 (centos_logos_yum_info, centos_logos_rpm_info, centos_logos_combined),
76 (dejavu_fonts_common_yum_info, dejavu_fonts_common_rpm_info, dejavu_fonts_common_combined),
78 def test_combine_rpm_data(yum_info, rpm_info, expected_combined):
79 result = RpmDataBuilder('fake_build_config_path',
83 {}).read_installed_rpms()
84 assert result[0] == expected_combined