def test_main_submit_db(self, tmpdir, config_e2e):
        orig_db_file = os.path.join(conf.DATA_PATH, "workitems_ids.sqlite3")
        db_file = os.path.join(str(tmpdir), "workitems_copy.sqlite3")
        shutil.copy(orig_db_file, db_file)

        output_file = tmpdir.join("out.xml")
        args = ["-i", db_file, "-o", str(output_file), "-c", config_e2e]

        with patch("dump2polarion.submit_and_verify", return_value=True), patch(
            "dump2polarion.dumper_cli.utils.init_log"
        ):
            retval = dumper_cli.main(args)
        assert retval == 0

        golden_output = "complete_transform.xml"
        with open(os.path.join(conf.DATA_PATH, golden_output), encoding="utf-8") as golden_xml:
            parsed = golden_xml.read()
        with open(str(output_file), encoding="utf-8") as out_xml:
            produced = out_xml.read()
        assert produced == parsed

        conn = dbtools._open_sqlite(db_file)
        cur = conn.cursor()
        select = "SELECT count(*) FROM testcases WHERE exported == 'yes'"
        cur.execute(select)
        num = cur.fetchone()
        conn.close()
        assert num[0] == 13
Beispiel #2
0
    def test_main_formats(self, tmpdir, config_e2e, data, submit):
        input_name, golden_output, extra_args, transform_func = data
        # copy the sqlite db so the records are not marked as exported
        if 'sqlite3' in input_name:
            orig_db_file = os.path.join(conf.DATA_PATH, input_name)
            db_file = os.path.join(str(tmpdir), 'workitems_copy.sqlite3')
            shutil.copy(orig_db_file, db_file)
            input_file = db_file
        else:
            input_file = os.path.join(conf.DATA_PATH, input_name)
        output_file = tmpdir.join('out.xml')
        args = ['-i', input_file, '-o', str(output_file), '-c', config_e2e]
        args.extend(extra_args)
        if not submit:
            args.append('-n')

        with patch('dump2polarion.submit_and_verify', return_value=True),\
                patch('dump2polarion.dumper_cli.utils.init_log'):
            retval = dumper_cli.main(args, transform_func=transform_func)
        assert retval == 0

        with io.open(os.path.join(conf.DATA_PATH, golden_output),
                     encoding='utf-8') as golden_xml:
            parsed = golden_xml.read()
        with io.open(str(output_file), encoding='utf-8') as out_xml:
            produced = out_xml.read()
        assert produced == parsed
    def test_main_formats(self, tmpdir, config_e2e, data, submit):
        input_name, golden_output, extra_args, transform_func = data
        # copy the sqlite db so the records are not marked as exported
        if "sqlite3" in input_name:
            orig_db_file = os.path.join(conf.DATA_PATH, input_name)
            db_file = os.path.join(str(tmpdir), "workitems_copy.sqlite3")
            shutil.copy(orig_db_file, db_file)
            input_file = db_file
        else:
            input_file = os.path.join(conf.DATA_PATH, input_name)
        output_file = tmpdir.join("out.xml")
        args = ["-i", input_file, "-o", str(output_file), "-c", config_e2e]
        args.extend(extra_args)
        if not submit:
            args.append("-n")

        with patch("dump2polarion.submit_and_verify", return_value=True), patch(
            "dump2polarion.dumper_cli.utils.init_log"
        ):
            retval = dumper_cli.main(args, transform_func=transform_func)
        assert retval == 0

        with open(os.path.join(conf.DATA_PATH, golden_output), encoding="utf-8") as golden_xml:
            parsed = golden_xml.read()
        with open(str(output_file), encoding="utf-8") as out_xml:
            produced = out_xml.read()
        assert produced == parsed
Beispiel #4
0
    def test_main_noresults(self, config_e2e, captured_log):
        input_file = os.path.join(conf.DATA_PATH, 'noresults.csv')
        args = ['-i', input_file, '-c', config_e2e]

        with patch('dump2polarion.submit_and_verify', return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert 'No results read from' in captured_log.getvalue()
Beispiel #5
0
    def test_main_submit_ready(self, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, 'complete_transform.xml')
        args = ['-i', input_file, '-c', config_e2e]

        with patch('dump2polarion.submit_and_verify', return_value=True), \
                patch('dump2polarion.dumper_cli.utils.init_log'):
            retval = dumper_cli.main(args)
        assert retval == 0
    def test_main_noconfig(self, captured_log):
        input_file = os.path.join(conf.DATA_PATH, "noreport.csv")
        args = ["-i", input_file, "-c", "nonexistent"]

        with patch("dump2polarion.submit_and_verify", return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert "Cannot open config file" in captured_log.getvalue()
    def test_main_noresults(self, config_e2e, captured_log):
        input_file = os.path.join(conf.DATA_PATH, "noresults.csv")
        args = ["-i", input_file, "-c", config_e2e]

        with patch("dump2polarion.submit_and_verify", return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert "No results read from" in captured_log.getvalue()
    def test_main_unconfigured(self, captured_log):
        input_file = os.path.join(conf.DATA_PATH, "noreport.csv")
        args = ["-i", input_file]

        with patch("dump2polarion.submit_and_verify", return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert "Failed to find configuration file" in captured_log.getvalue()
Beispiel #9
0
    def test_main_noreport(self, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, 'noreport.csv')
        args = ['-i', input_file, '-c', config_e2e]

        with patch('dump2polarion.submit_and_verify', return_value=True), \
                patch('dump2polarion.dumper_cli.utils.init_log'):
            retval = dumper_cli.main(args)
        assert retval == 0
Beispiel #10
0
    def test_main_noconfig(self, captured_log):
        input_file = os.path.join(conf.DATA_PATH, 'noreport.csv')
        args = ['-i', input_file, '-c', 'nonexistent']

        with patch('dump2polarion.submit_and_verify', return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert 'Cannot open config file' in captured_log.getvalue()
    def test_main_noreport(self, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, "noreport.csv")
        args = ["-i", input_file, "-c", config_e2e]

        with patch("dump2polarion.submit_and_verify", return_value=True), patch(
            "dump2polarion.dumper_cli.utils.init_log"
        ):
            retval = dumper_cli.main(args)
        assert retval == 0
    def test_main_submit_ready(self, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, "complete_transform.xml")
        args = ["-i", input_file, "-c", config_e2e]

        with patch("dump2polarion.submit_and_verify", return_value=True), patch(
            "dump2polarion.dumper_cli.utils.init_log"
        ):
            retval = dumper_cli.main(args)
        assert retval == 0
Beispiel #13
0
    def test_main_unconfigured(self, captured_log):
        input_file = os.path.join(conf.DATA_PATH, 'noreport.csv')
        args = ['-i', input_file]

        with patch('dump2polarion.submit_and_verify', return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert 'Failed to find following keys in config file' in captured_log.getvalue(
        )
    def test_main_missing_testrun(self, tmpdir, config_e2e, captured_log):
        input_file = os.path.join(conf.DATA_PATH, "junit-report.xml")
        output_file = tmpdir.join("out.xml")
        args = ["-i", input_file, "-o", str(output_file), "-c", config_e2e, "-n"]

        with patch("dump2polarion.submit_and_verify", return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert "The testrun id was not specified" in captured_log.getvalue()

        with pytest.raises(IOError) as excinfo:
            open(str(output_file))
        assert "No such file or directory" in str(excinfo.value)
Beispiel #15
0
    def test_main_missing_testrun(self, tmpdir, config_e2e, captured_log):
        input_file = os.path.join(conf.DATA_PATH, 'junit-report.xml')
        output_file = tmpdir.join('out.xml')
        args = [
            '-i', input_file, '-o',
            str(output_file), '-c', config_e2e, '-n'
        ]

        with patch('dump2polarion.submit_and_verify', return_value=True):
            retval = dumper_cli.main(args)
        assert retval == 1
        assert 'The testrun id was not specified' in captured_log.getvalue()

        with pytest.raises(IOError) as excinfo:
            open(str(output_file))
        assert 'No such file or directory' in str(excinfo.value)
    def test_main_submit_failed(self, tmpdir, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, "workitems_ids.csv")
        output_file = tmpdir.join("out.xml")
        args = ["-i", input_file, "-o", str(output_file), "-c", config_e2e]

        with patch("dump2polarion.submit_and_verify", return_value=False), patch(
            "dump2polarion.dumper_cli.utils.init_log"
        ):
            retval = dumper_cli.main(args)
        assert retval == 2

        golden_output = "complete_transform.xml"
        with open(os.path.join(conf.DATA_PATH, golden_output), encoding="utf-8") as golden_xml:
            parsed = golden_xml.read()
        with open(str(output_file), encoding="utf-8") as out_xml:
            produced = out_xml.read()
        assert produced == parsed
Beispiel #17
0
    def test_main_submit_failed(self, tmpdir, config_e2e):
        input_file = os.path.join(conf.DATA_PATH, 'workitems_ids.csv')
        output_file = tmpdir.join('out.xml')
        args = ['-i', input_file, '-o', str(output_file), '-c', config_e2e]

        with patch('dump2polarion.submit_and_verify', return_value=False), \
                patch('dump2polarion.dumper_cli.utils.init_log'):
            retval = dumper_cli.main(args)
        assert retval == 2

        golden_output = 'complete_transform.xml'
        with io.open(os.path.join(conf.DATA_PATH, golden_output),
                     encoding='utf-8') as golden_xml:
            parsed = golden_xml.read()
        with io.open(str(output_file), encoding='utf-8') as out_xml:
            produced = out_xml.read()
        assert produced == parsed
Beispiel #18
0
        return
    if zval < 10:
        pad_build = build_base[-1].zfill(2)
        return build_base[:-1] + pad_build
    return build_base


def tweak_args():
    """Tweaks args for polarion dumper."""
    new_argv = sys.argv[1:]

    for index, arg in enumerate(new_argv):
        if arg in ('-t', '--testrun-id'):
            break
    else:
        index = None

    testrun_id = get_testrun_id(new_argv[index + 1])
    if not testrun_id:
        print("Cannot find testrun id.", file=sys.stderr)
        sys.exit(1)

    # replace `-t appliance_version` with `-t testrun_id`
    new_argv[index + 1] = testrun_id

    return new_argv


if __name__ == '__main__':
    sys.exit(main(tweak_args()))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Polarion dumper CLI
"""

import sys

from dump2polarion.dumper_cli import main

if __name__ == '__main__':
    sys.exit(main())