예제 #1
0
def submit_if_ready(args, submit_args, config):
    """Submit the input XML file if it's already in the expected format."""
    __, ext = os.path.splitext(args.input_file)
    if ext.lower() != ".xml":
        return None

    with open(args.input_file, encoding="utf-8") as input_file:
        xml = input_file.read(1024)

    if not ("<testsuites" in xml or "<testcases" in xml
            or "<requirements" in xml):
        return None

    # TODO: better detection of xunit file that is ready for import needed
    if "<testsuites" in xml and 'name="pytest"' in xml:
        return None

    if args.no_submit:
        logger.info("Nothing to do")
        return 0

    # expect importer xml and just submit it
    response = dump2polarion.submit_and_verify(xml_file=args.input_file,
                                               config=config,
                                               **submit_args)
    return 0 if response else 2
예제 #2
0
def main(args=None, transform_func=None):
    """Main function for cli."""
    args = get_args(args)
    submit_args = get_submit_args(args)

    utils.init_log(args.log_level)

    try:
        config = dump2polarion.get_config(args.config_file)
    except Dump2PolarionException as err:
        logger.fatal(err)
        return 1

    submit_outcome = submit_if_ready(args, submit_args, config)
    if submit_outcome is not None:
        # submitted, nothing more to do
        return submit_outcome

    import_time = datetime.datetime.utcnow()

    try:
        records = dump2polarion.do_import(args.input_file,
                                          older_than=import_time)
        testrun_id = get_testrun_id(args, records.testrun)
        exporter = dump2polarion.XunitExport(testrun_id,
                                             records,
                                             config,
                                             transform_func=transform_func)
        output = exporter.export()
    except NothingToDoException as info:
        logger.info(info)
        return 0
    except (EnvironmentError, Dump2PolarionException) as err:
        logger.fatal(err)
        return 1

    if args.output_file or args.no_submit:
        # when no output file is specified, the 'testrun_TESTRUN_ID-TIMESTAMP'
        # file will be created in current directory
        exporter.write_xml(output, args.output_file)

    if not args.no_submit:
        response = dump2polarion.submit_and_verify(output,
                                                   config=config,
                                                   **submit_args)

        __, ext = os.path.splitext(args.input_file)
        if ext.lower() in dbtools.SQLITE_EXT and response:
            dbtools.mark_exported_sqlite(args.input_file, import_time)

        return 0 if response else 2

    return 0
예제 #3
0
def submit_if_ready(args, submit_args, config):
    """Submits the input XML file if it's already in the expected format."""
    __, ext = os.path.splitext(args.input_file)
    if ext.lower() != '.xml':
        return

    with io.open(args.input_file, encoding='utf-8') as input_file:
        xml = input_file.read()

    if '<testsuites' in xml or '<testcases' in xml:
        if args.no_submit:
            logger.info("Nothing to do")
            return 0
        # expect importer xml and just submit it
        response = dump2polarion.submit_and_verify(xml,
                                                   config=config,
                                                   **submit_args)
        return 0 if response else 2