X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=tools%2Fscript%2Fprocess_rpmdata_test.py;fp=tools%2Fscript%2Fprocess_rpmdata_test.py;h=d704bf71f14cb9956a5a1209314fb8398af54860;hb=4ded4f2a805e9447be90751d7d4fb7e11552e545;hp=0000000000000000000000000000000000000000;hpb=3b1226294aa9e47692e15279e669d159675deeb9;p=ta%2Fbuild-tools.git diff --git a/tools/script/process_rpmdata_test.py b/tools/script/process_rpmdata_test.py new file mode 100755 index 0000000..d704bf7 --- /dev/null +++ b/tools/script/process_rpmdata_test.py @@ -0,0 +1,58 @@ +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json + +from tools.convert import CsvConverter +from tools.script.create_rpm_data_test_data import expected_output +from tools.script.process_rpmdata import main + + +def gen_input(tmpdir, rpmdata): + p = tmpdir.join('rpmdata.json') + p.write(rpmdata) + return str(p) + + +def test_no_output(tmpdir): + main(['--rpmdata-path', gen_input(tmpdir, {})]) + + +def test_components(tmpdir): + input_content = [expected_output[0], + expected_output[3]] + input_ = json.dumps(input_content) + output_json = tmpdir.join('components.json') + output_csv = tmpdir.join('components.csv') + main(['--rpmdata-path', gen_input(tmpdir, input_), + '--output-components', str(output_json), + '--output-components-csv', str(output_csv)]) + additions = [{'FOSS': u'yes', + 'Source RPM': 'internal-pkg-4-4.src.rpm', + 'Name': '@types/d3-axis', + 'Source URL': 'http://some.url/1', + 'Version': '1.0.10', + 'Crypto capable': True}, + {'FOSS': u'Yes', + 'Source RPM': 'internal-pkg-4-4.src.rpm', + 'Name': '@types/d3-array@*', + 'Source URL': 'http://some.url/2', + 'Version': '1.2.1'}] + assert json.loads(output_json.read()) == input_content + additions + assert output_csv.read() == _gen_components_csv(input_content + additions) + + +def _gen_components_csv(_list): + csv = CsvConverter(_list, preferred_field_order=['Name', 'Version', 'Release', 'Source RPM']) + return csv.convert_to_ms_excel(text_fields=['Version'])