Пример #1
0
def detect_observed_field(loc):
    """Detect observed fields; sleep if needed

    Used after filling most form fields, this function will inspect the filled field for
    one of the known CFME observed field attribues, and if found, sleep long enough for the observed
    field's AJAX request to go out, and then block until no AJAX requests are in flight.

    Observed fields occasionally declare their own wait interval before firing their AJAX request.
    If found, that interval will be used instead of the default.

    """
    try:
        if is_displayed(loc):
            el = element(loc)
        else:
            # Element not visible, sort out
            return
    except StaleElementReferenceException:
        return

    # Default wait period, based on the default UI wait (700ms)
    # plus a little padding to let the AJAX fire before we wait_for_ajax
    default_wait = .8
    # Known observed field attributes
    observed_field_markers = (
        'data-miq_observe',
        'data-miq_observe_date',
        'data-miq_observe_checkbox',
    )
    for attr in observed_field_markers:
        try:
            observed_field_attr = el.get_attribute(attr)
            break
        except NoSuchAttributeException:
            pass
    else:
        # Failed to detect an observed text field, short out
        return

    try:
        attr_dict = json.loads(observed_field_attr)
        interval = float(attr_dict.get('interval', default_wait))
        # Pad the detected interval, as with default_wait
        interval += .1
    except (TypeError, ValueError):
        # ValueError and TypeError happens if the attribute value couldn't be decoded as JSON
        # ValueError also happens if interval couldn't be coerced to float
        # In either case, we've detected an observed text field and should wait
        interval = default_wait

    logger.trace('  Observed field detected, pausing %.1f seconds', interval)
    sleep(interval)
    wait_for_ajax()
Пример #2
0
def detect_observed_field(loc):
    """Detect observed fields; sleep if needed

    Used after filling most form fields, this function will inspect the filled field for
    one of the known CFME observed field attribues, and if found, sleep long enough for the observed
    field's AJAX request to go out, and then block until no AJAX requests are in flight.

    Observed fields occasionally declare their own wait interval before firing their AJAX request.
    If found, that interval will be used instead of the default.

    """
    try:
        if is_displayed(loc):
            el = element(loc)
        else:
            # Element not visible, sort out
            return
    except StaleElementReferenceException:
        return

    # Default wait period, based on the default UI wait (700ms)
    # plus a little padding to let the AJAX fire before we wait_for_ajax
    default_wait = .8
    # Known observed field attributes
    observed_field_markers = (
        'data-miq_observe',
        'data-miq_observe_date',
        'data-miq_observe_checkbox',
    )
    for attr in observed_field_markers:
        try:
            observed_field_attr = el.get_attribute(attr)
            break
        except NoSuchAttributeException:
            pass
    else:
        # Failed to detect an observed text field, short out
        return

    try:
        attr_dict = json.loads(observed_field_attr)
        interval = float(attr_dict.get('interval', default_wait))
        # Pad the detected interval, as with default_wait
        interval += .1
    except (TypeError, ValueError):
        # ValueError and TypeError happens if the attribute value couldn't be decoded as JSON
        # ValueError also happens if interval couldn't be coerced to float
        # In either case, we've detected an observed text field and should wait
        interval = default_wait

    logger.trace('  Observed field detected, pausing %.1f seconds', interval)
    sleep(interval)
    wait_for_ajax()
Пример #3
0
def pytest_pycollect_makeitem(collector, name, obj):
    """pytest hook that adds docstring metadata (if found) to a test's meta mark"""
    if not isinstance(obj, FunctionType):
        return

    # __doc__ can be empty or nonexistent, make sure it's an empty string in that case
    metadata = get_meta(obj)
    # this is just bad - apply the marks better once we go pytest 3.6+
    # ideally we would check a FunctionDefinition, but pytest isnt there yet
    # sw we have to rely on a working solution
    pytest.mark.meta(from_docs=metadata)(obj)
    if metadata:
        test_path = get_rel_path(collector.fspath)
        logger.debug('Parsed docstring metadata on {} in {}'.format(name, test_path))
        logger.trace('{} doc metadata: {}'.format(name, str(metadata)))
Пример #4
0
def pytest_pycollect_makeitem(collector, name, obj):
    """pytest hook that adds docstring metadata (if found) to a test's meta mark"""
    if not isinstance(obj, FunctionType):
        return

    # __doc__ can be empty or nonexistent, make sure it's an empty string in that case
    metadata = get_meta(obj)
    # this is just bad - apply the marks better once we go pytest 3.6+
    # ideally we would check a FunctionDefinition, but pytest isnt there yet
    # sw we have to rely on a working solution
    pytest.mark.meta(from_docs=metadata)(obj)
    if metadata:
        test_path = get_rel_path(collector.fspath)
        logger.debug('Parsed docstring metadata on {} in {}'.format(name, test_path))
        logger.trace('{} doc metadata: {}'.format(name, str(metadata)))
Пример #5
0
    def _nothing_in_flight():
        """Checks if there is no ajax in flight and also logs current status
        """
        prev_log_msg = _thread_local.ajax_log_msg

        # 5.5.z and 5.7.0.4+
        if not store.current_appliance.is_miqqe_patch_candidate:
            try:
                anything_in_flight = in_flight(
                    "return ManageIQ.qe.anythingInFlight()")
            except Exception as e:
                # if jQuery in error message, a non-cfme page (proxy error) is displayed
                # should be handled by something else
                if "jquery" not in str(e).lower():
                    raise
                return True
            running = execute_script("return ManageIQ.qe.inFlight()")
            log_msg = ', '.join(
                ["{}: {}".format(k, str(v)) for k, v in running.iteritems()])
        # 5.6.z, 5.7.0.{1,2,3}
        else:
            try:
                running = in_flight(js.in_flight)
            except Exception as e:
                # if jQuery in error message, a non-cfme page (proxy error) is displayed
                # should be handled by something else
                if "jquery" not in str(e).lower():
                    raise
                return True
            anything_in_flight = False
            anything_in_flight |= running["jquery"] > 0
            anything_in_flight |= running["prototype"] > 0
            anything_in_flight |= running["spinner"]
            anything_in_flight |= running["document"] != "complete"
            anything_in_flight |= running["autofocus"] > 0
            anything_in_flight |= running["debounce"] > 0
            anything_in_flight |= running["miqQE"] > 0
            log_msg = ', '.join(
                ["{}: {}".format(k, str(v)) for k, v in running.iteritems()])

        # Log the message only if it's different from the last one
        if prev_log_msg != log_msg:
            _thread_local.ajax_log_msg = log_msg
            logger.trace('Ajax running: %s', log_msg)
        if (not anything_in_flight) and prev_log_msg:
            logger.trace('Ajax done')

        return not anything_in_flight
Пример #6
0
    def _nothing_in_flight():
        """Checks if there is no ajax in flight and also logs current status
        """
        prev_log_msg = _thread_local.ajax_log_msg

        # 5.5.z and 5.7.0.4+
        if not store.current_appliance.is_miqqe_patch_candidate:
            try:
                anything_in_flight = in_flight("return ManageIQ.qe.anythingInFlight()")
            except Exception as e:
                # if jQuery in error message, a non-cfme page (proxy error) is displayed
                # should be handled by something else
                if "jquery" not in str(e).lower():
                    raise
                return True
            running = execute_script("return ManageIQ.qe.inFlight()")
            log_msg = ', '.join(["{}: {}".format(k, str(v)) for k, v in running.iteritems()])
        # 5.6.z, 5.7.0.{1,2,3}
        else:
            try:
                running = in_flight(js.in_flight)
            except Exception as e:
                # if jQuery in error message, a non-cfme page (proxy error) is displayed
                # should be handled by something else
                if "jquery" not in str(e).lower():
                    raise
                return True
            anything_in_flight = False
            anything_in_flight |= running["jquery"] > 0
            anything_in_flight |= running["prototype"] > 0
            anything_in_flight |= running["spinner"]
            anything_in_flight |= running["document"] != "complete"
            anything_in_flight |= running["autofocus"] > 0
            anything_in_flight |= running["debounce"] > 0
            anything_in_flight |= running["miqQE"] > 0
            log_msg = ', '.join(["{}: {}".format(k, str(v)) for k, v in running.iteritems()])

        # Log the message only if it's different from the last one
        if prev_log_msg != log_msg:
            _thread_local.ajax_log_msg = log_msg
            logger.trace('Ajax running: %s', log_msg)
        if (not anything_in_flight) and prev_log_msg:
            logger.trace('Ajax done')

        return not anything_in_flight
Пример #7
0
def pytest_pycollect_makeitem(collector, name, obj):
    """pytest hook that adds docstring metadata (if found) to a test's meta mark"""
    if not isinstance(obj, FunctionType) and not hasattr(obj, 'meta'):
        # This relies on the meta mark having already been applied to
        # all test functions before this hook is called
        return

    # __doc__ can be empty or nonexistent, make sure it's an empty string in that case
    metadata = get_meta(obj)

    if not hasattr(obj.meta, 'kwargs'):
        obj.meta.kwargs = dict()
    obj.meta.kwargs.update({'from_docs': metadata})
    if metadata:
        test_path = get_rel_path(collector.fspath)
        logger.debug('Parsed docstring metadata on {} in {}'.format(
            name, test_path))
        logger.trace('{} doc metadata: {}'.format(name, str(metadata)))
Пример #8
0
def pytest_pycollect_makeitem(collector, name, obj):
    """pytest hook that adds docstring metadata (if found) to a test's meta mark"""
    if not isinstance(obj, FunctionType) and not hasattr(obj, 'meta'):
        # This relies on the meta mark having already been applied to
        # all test functions before this hook is called
        return

    # __doc__ can be empty or nonexistent, make sure it's an empty string in that case
    metadata = get_meta(obj)

    if not hasattr(obj.meta, 'kwargs'):
        obj.meta.kwargs = dict()
    obj.meta.kwargs.update({
        'from_docs': metadata
    })
    if metadata:
        test_path = get_rel_path(collector.fspath)
        logger.debug('Parsed docstring metadata on {} in {}'.format(name, test_path))
        logger.trace('{} doc metadata: {}'.format(name, str(metadata)))