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.
17 from tools.convert import CsvConverter
18 from tools.script.create_rpm_data_test_data import expected_output
19 from tools.script.process_rpmdata import main
22 def gen_input(tmpdir, rpmdata):
23 p = tmpdir.join('rpmdata.json')
28 def test_no_output(tmpdir):
29 main(['--rpmdata-path', gen_input(tmpdir, {})])
32 def test_components(tmpdir):
33 input_content = [expected_output[0],
35 input_ = json.dumps(input_content)
36 output_json = tmpdir.join('components.json')
37 output_csv = tmpdir.join('components.csv')
38 main(['--rpmdata-path', gen_input(tmpdir, input_),
39 '--output-components', str(output_json),
40 '--output-components-csv', str(output_csv)])
41 additions = [{'FOSS': u'yes',
42 'Source RPM': 'internal-pkg-4-4.src.rpm',
43 'Name': '@types/d3-axis',
44 'Source URL': 'http://some.url/1',
46 'Crypto capable': True},
48 'Source RPM': 'internal-pkg-4-4.src.rpm',
49 'Name': '@types/d3-array@*',
50 'Source URL': 'http://some.url/2',
52 assert json.loads(output_json.read()) == input_content + additions
53 assert output_csv.read() == _gen_components_csv(input_content + additions)
56 def _gen_components_csv(_list):
57 csv = CsvConverter(_list, preferred_field_order=['Name', 'Version', 'Release', 'Source RPM'])
58 return csv.convert_to_ms_excel(text_fields=['Version'])