Example #1
0
 def test_get_session_cookie_failed(self, config_prop):
     config_prop["auth_url"] = "http://example.com"
     with patch("requests.Session") as mock:
         instance = mock.return_value
         instance.post.return_value = None
         with pytest.raises(Dump2PolarionException) as excinfo:
             utils.get_session("foo", config_prop)
     assert "Cookie was not retrieved" in str(excinfo.value)
Example #2
0
 def test_get_session_cookie_failed(self, config_prop):
     config_prop['auth_url'] = 'http://example.com'
     with patch('requests.Session') as mock:
         instance = mock.return_value
         instance.post.return_value = None
         with pytest.raises(Dump2PolarionException) as excinfo:
             utils.get_session('foo', config_prop)
     assert 'Cookie was not retrieved' in str(excinfo.value)
Example #3
0
 def test_get_session_cookie_success(self, config_prop):
     config_prop["auth_url"] = "http://example.com"
     with patch("requests.Session") as mock:
         instance = mock.return_value
         instance.post.return_value = True
         session = utils.get_session("foo", config_prop)
     assert session.auth != "foo"
Example #4
0
 def test_get_session_cookie_success(self, config_prop):
     config_prop['auth_url'] = 'http://example.com'
     with patch('requests.Session') as mock:
         instance = mock.return_value
         instance.post.return_value = True
         session = utils.get_session('foo', config_prop)
     assert session.auth != 'foo'
Example #5
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
Example #6
0
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)
Example #7
0
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)
Example #8
0
 def test_get_session_oldauth(self, config_prop):
     if "auth_url" in config_prop:
         del config_prop["auth_url"]
     with patch("requests.Session"):
         session = utils.get_session("foo", config_prop)
     assert session.auth == "foo"
Example #9
0
 def test_get_session_oldauth(self, config_prop):
     if 'auth_url' in config_prop:
         del config_prop['auth_url']
     with patch('requests.Session'):
         session = utils.get_session('foo', config_prop)
     assert session.auth == 'foo'