def main(args=None): """Main function for cli.""" args = get_args(args) submit_args = get_submit_args(args) init_log(args.log_level) dump2polarion_config = configuration.get_config( args.dump2polarion_config) if args.dump2polarion_config else None testcases = args.testcases or _TEST_CASE_XML testsuites = args.testsuites or _TEST_RUN_XML try: gen_pytest_xmls(args) if args.use_svn: missing = get_missing_from_svn(testcases, args.use_svn) else: missing = get_missing_from_log(args, submit_args, dump2polarion_config) filtered_xmls = filters.get_filtered_xmls(testcases, testsuites, missing) save_filtered_xmls(args, testcases, testsuites, filtered_xmls) submit_filtered_xmls(args, submit_args, dump2polarion_config, filtered_xmls) except NothingToDoException as einfo: logger.info(einfo) return 0 except TestcasesException as err: logger.fatal(err) return 1 return 0
def submit_and_verify( xml_str=None, xml_file=None, xml_root=None, config=None, session=None, dry_run=None, **kwargs ): """Submits data to the Polarion Importer and checks that it was imported.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) submit_config = SubmitConfig(xml_root, config, **kwargs) session = session or utils.get_session(submit_config.credentials, config) submit_response = submit(xml_root, submit_config, session, dry_run=dry_run, **kwargs) except Dump2PolarionException as err: logger.error(err) return None valid_response = submit_response.validate_response() if not valid_response or kwargs.get("no_verify"): return submit_response.response response = verify_submit( session, submit_config.queue_url, submit_config.log_url, submit_response.job_ids, timeout=kwargs.get("verify_timeout"), log_file=kwargs.get("log_file"), ) return response
def submit(xml_str=None, xml_file=None, xml_root=None, config=None, **kwargs): """Submits results to the Polarion Importer.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) credentials = _get_credentials(config, **kwargs) submit_target = _get_submit_target(xml_root, config) utils.xunit_fill_testrun_id(xml_root, kwargs.get('testrun_id')) xml_input = utils.etree_to_string(xml_root) except Dump2PolarionException as err: logger.error(err) return logger.info("Submitting results to {}".format(submit_target)) files = {'file': ('results.xml', xml_input)} try: response = requests.post(submit_target, files=files, auth=credentials, verify=False) # pylint: disable=broad-except except Exception as err: logger.error(err) response = None if response is None: logger.error("Failed to submit results to {}".format(submit_target)) elif response: logger.info("Results received by the Importer (HTTP status {})".format( response.status_code)) else: logger.error("HTTP status {}: failed to submit results to {}".format( response.status_code, submit_target)) return response
def submit_and_verify(xml_str=None, xml_file=None, xml_root=None, config=None, session=None, **kwargs): """Submits data to the Polarion Importer and checks that it was imported.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) credentials = _get_credentials(config, **kwargs) queue_url = _get_queue_url(xml_root, config) session = session or utils.get_session(credentials, config) except Dump2PolarionException as err: logger.error(err) return response = submit(xml_root=xml_root, config=config, session=session, **kwargs) if not response: return False job_ids = get_job_ids(response) if not kwargs.get('no_verify') and job_ids: response = verify_submit(session, queue_url, job_ids, timeout=kwargs.get('verify_timeout'), log_file=kwargs.get('log_file')) return bool(response)
def submit(xml_str=None, xml_file=None, xml_root=None, config=None, session=None, **kwargs): """Submits data to the Polarion Importer.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) credentials = _get_credentials(config, **kwargs) submit_target = _get_submit_target(xml_root, config) utils.xunit_fill_testrun_id(xml_root, kwargs.get('testrun_id')) xml_input = utils.etree_to_string(xml_root) session = session or utils.get_session(credentials, config) except Dump2PolarionException as err: logger.error(err) return logger.info("Submitting data to {}".format(submit_target)) files = {'file': ('results.xml', xml_input)} try: response = session.post(submit_target, files=files) # pylint: disable=broad-except except Exception as err: logger.error(err) response = None return validate_response(response, submit_target)
def test_populate(self, config): conf_file = os.path.join(conf.DATA_PATH, config) cfg = configuration.get_config(conf_file) polarion_url = cfg.get("polarion_url") for key in configuration.URLS: assert key in cfg if polarion_url and cfg.get(key): assert polarion_url in cfg[key]
def submit_and_verify(xml_str=None, xml_file=None, xml_root=None, config=None, **kwargs): """Submits results to the Polarion Importer and checks that it was imported.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) response_property = utils.fill_response_property(xml_root) except Dump2PolarionException as err: logger.error(err) return False verification_skipped = False if kwargs.get('no_verify'): verification_func = None else: msgbus_login = kwargs.get('msgbus_user') or config.get( 'msgbus_username') or kwargs.get('user') or config.get( 'username') or os.environ.get('POLARION_USERNAME') msgbus_pwd = kwargs.get('msgbus_password') or config.get( 'msgbus_password') or kwargs.get('password') or config.get( 'password') or os.environ.get('POLARION_PASSWORD') verification_func = msgbus.get_verification_func( config.get('message_bus'), response_property, user=msgbus_login, password=msgbus_pwd, log_file=kwargs.get('msgbus_log')) if not verification_func: verification_skipped = True response = submit(xml_root=xml_root, config=config, **kwargs) if verification_func: response = verification_func(skip=not response, timeout=kwargs.get('verify_timeout')) elif verification_skipped: # we wanted to verify the import but it didn't happen for some reason response = False return bool(response)
def submit_and_verify(xml_str=None, xml_file=None, xml_root=None, config=None, **kwargs): """Submits results to the Polarion Importer and checks that it was imported.""" try: config = config or configuration.get_config() xml_root = _get_xml_root(xml_root, xml_str, xml_file) credentials = _get_credentials(config, **kwargs) queue_url = _get_queue_url(xml_root, config) except Dump2PolarionException as err: logger.error(err) return verify_import = True job_id = None if not kwargs.get('no_verify'): verification_queue = verify.QueueSearch(user=credentials[0], password=credentials[1], queue_url=queue_url) verify_import = verification_queue.queue_init() response = submit(xml_root=xml_root, config=config, **kwargs) if not verify_import: # we wanted to verify the import but it didn't happen for some reason return False if response: job_id = get_job_id(response) if not kwargs.get('no_verify') and job_id: response = verification_queue.verify_submit( job_id, timeout=kwargs.get('verify_timeout'), log_file=kwargs.get('log_file')) return bool(response)
def test_user(self, config_e2e): cfg = configuration.get_config(config_e2e) assert cfg["xunit_import_properties"]["polarion-dry-run"] is False assert cfg["username"] == "user1" assert cfg["polarion-project-id"] == "RHCF3"
def test_keys_missing(self): project_id = {"polarion-project-id": "RHCF3"} with pytest.raises(Dump2PolarionException) as excinfo: configuration.get_config(config_values=project_id) assert "Failed to find following keys in config file" in str( excinfo.value)
def test_default_no_project(self): with pytest.raises(Dump2PolarionException) as excinfo: configuration.get_config(load_project_conf=False) assert "No configuration file or values passed" in str(excinfo.value)
def test_default_w_project(self): with pytest.raises(Dump2PolarionException) as excinfo: configuration.get_config() assert "Failed to find configuration file" in str(excinfo.value)
def test_nonexistant(self): with pytest.raises(Dump2PolarionException) as excinfo: configuration.get_config("nonexistant") assert "Cannot open config file nonexistant" in str(excinfo.value)
def test_user(self): conf_file = os.path.join(conf.DATA_PATH, 'dump2polarion.yaml') cfg = configuration.get_config(conf_file) assert cfg['xunit_import_properties']['polarion-dry-run'] is True assert cfg['username'] == 'user1' assert cfg['xunit_import_properties']['polarion-project-id'] == 'RHCF3'
def test_default(self): with pytest.raises(Dump2PolarionException) as excinfo: configuration.get_config() assert 'Failed to find following keys in config file' in str( excinfo.value)
def test_user(self, config_e2e): cfg = configuration.get_config(config_e2e) assert cfg['xunit_import_properties']['polarion-dry-run'] is False assert cfg['username'] == 'user1' assert cfg['xunit_import_properties']['polarion-project-id'] == 'RHCF3'