Esempio n. 1
0
def interpolate_xpath(string,
                      case_xpath=None,
                      fixture_xpath=None,
                      module=None,
                      form=None):
    """
    Replace xpath shortcuts with full value.
    """
    if case_xpath is None and any([
            '#case' in string,
            '#parent' in string,
            '#host' in string,
            # DOT_INTERPOLATE_PATTERN throws false positives, so if it flags the string,
            # verify that the string's dots would actually get replaced
            re.search(DOT_INTERPOLATE_PATTERN, string)
            and dot_interpolate(string, "") != string,
    ]):
        # At the moment this function is only used by module and form filters.
        # If that changes, amend the error message accordingly.
        raise CaseXPathValidationError(_(CASE_REFERENCE_VALIDATION_ERROR),
                                       module=module,
                                       form=form)
    replacements = {
        '#user': UsercaseXPath().case(),
        '#session/': session_var('', path=''),
    }
Esempio n. 2
0
        def get_commands(excluded_form_ids):
            @memoized
            def module_uses_case():
                return module.all_forms_require_a_case()

            @memoized
            def domain_uses_usercase():
                return is_usercase_in_use(self.app.domain)

            for form in module.get_suite_forms():
                if form.unique_id in excluded_form_ids:
                    continue

                command = Command(id=id_strings.form_command(form, module))

                if form.requires_case():
                    form_datums = self.entries_helper.get_datums_meta_for_form_generic(
                        form, module)
                    var_name = next(meta.datum.id
                                    for meta in reversed(form_datums)
                                    if meta.action and meta.requires_selection)
                    case = CaseIDXPath(session_var(var_name)).case()
                else:
                    case = None

                if getattr(form, 'form_filter', None):
                    fixture_xpath = (session_var(
                        id_strings.fixture_session_var(module))
                                     if module.fixture_select.active else None)
                    interpolated_xpath = interpolate_xpath(form.form_filter,
                                                           case,
                                                           fixture_xpath,
                                                           module=module,
                                                           form=form)

                    if xpath_references_case(interpolated_xpath) and \
                            (not module_uses_case() or
                            module.put_in_root and not module.root_requires_same_case()):
                        raise CaseXPathValidationError(module=module,
                                                       form=form)

                    if xpath_references_user_case(
                            interpolated_xpath) and not domain_uses_usercase():
                        raise UserCaseXPathValidationError(module=module,
                                                           form=form)

                    command.relevant = interpolated_xpath

                if getattr(module, 'has_schedule',
                           False) and module.all_forms_require_a_case():
                    # If there is a schedule and another filter condition, disregard it...
                    # Other forms of filtering are disabled in the UI

                    schedule_filter_condition = MenuContributor._schedule_filter_conditions(
                        form, module, case)
                    if schedule_filter_condition is not None:
                        command.relevant = schedule_filter_condition

                yield command
Esempio n. 3
0
def interpolate_xpath(string, case_xpath=None, fixture_xpath=None, module=None, form=None):
    """
    Replace xpath shortcuts with full value.
    """
    if case_xpath is None and any([
        '#case' in string,
        '#parent' in string,
        '#host' in string,
        re.search(DOT_INTERPOLATE_PATTERN, string),
    ]):
        # At the moment this function is only used by module and form filters.
        # If that changes, amend the error message accordingly.
        raise CaseXPathValidationError(_(CASE_REFERENCE_VALIDATION_ERROR), module=module, form=form)
    replacements = {
        '#user': UserCaseXPath().case(),
        '#session/': session_var('', path=''),
    }