Exemple #1
0
def its_value_condition_match_the_search_regex_regex(step, condition,
                                                     search_regex):
    if hasattr(step.context.stash,
               'resource_list') and not step.context.stash.resource_list:
        return

    regex = r'{}'.format(search_regex)

    if step.context.stash.__class__ in (str, unicode):
        matches = re.match(regex, step.context.stash)

        if condition == 'must':
            assert matches is not None, \
                '{} {} tests failed on {} regex: {}'.format(step.context.name,
                                                            step.context.type,
                                                            regex,
                                                            step.context.stash)
        elif condition == "must not":
            assert matches is None, \
                '{} {} tests failed on {} regex: {}'.format(step.context.name,
                                                            step.context.type,
                                                            regex,
                                                            step.context.stash)
    else:
        normalise_tag_values(step.context.stash)

        for property in step.context.stash.properties:
            if type(property.property_value) in [str, unicode]:
                property.property_value = [property.property_value]
            elif type(property.property_value) is dict:
                property.property_value = property.property_value.values()

            for value in property.property_value:
                matches = re.match(regex, value)

                if condition == 'must':
                    assert matches is not None, \
                        '{} property in {} does not match with {} regex. It is set to {} instead.'.format(property.property_name,
                                                                                                      property.resource_name,
                                                                                                      search_regex,
                                                                                                      value)
                elif condition == 'must not':
                    assert matches is not None, \
                        '{} property in {} does not match with {} regex. It is set to {} instead.'.format(property.property_name,
                                                                                                          property.resource_name,
                                                                                                          search_regex,
                                                                                                          value)
Exemple #2
0
def its_value_condition_match_the_search_regex_regex(step_obj, condition,
                                                     search_regex):
    regex = r'{}'.format(search_regex)

    if step_obj.context.stash.__class__ is str:
        matches = re.match(regex, step_obj.context.stash)

        if condition == 'must':
            assert matches is not None, \
                '{} {} tests failed on {} regex: {}'.format(step_obj.context.name,
                                                            step_obj.context.type,
                                                            regex,
                                                            step_obj.context.stash)
        elif condition == "must not":
            assert matches is None, \
                '{} {} tests failed on {} regex: {}'.format(step_obj.context.name,
                                                            step_obj.context.type,
                                                            regex,
                                                            step_obj.context.stash)
    else:
        normalise_tag_values(step_obj.context.stash)

        for prop in step_obj.context.stash.properties:
            if type(prop.property_value) is str:
                prop.property_value = [prop.property_value]
            elif type(prop.property_value) is dict:
                prop.property_value = prop.property_value.values()

            for value in prop.property_value:
                matches = re.match(regex, value)

                if condition == 'must':
                    assert matches is not None, \
                        '{} property in {} does not match with {} regex. It is set to {} instead.' \
                        ''.format(prop.property_name,
                                  prop.resource_name,
                                  search_regex,
                                  value)
                elif condition == 'must not':
                    assert matches is not None, \
                        '{} property in {} does not match with {} regex. It is set to {} instead.' \
                        ''.format(prop.property_name,
                                  prop.resource_name,
                                  search_regex,
                                  value)
def func(step, search_regex):
    if hasattr(step.context.stash,
               'resource_list') and not step.context.stash.resource_list:
        return

    normalise_tag_values(step.context.stash)
    regex = r'/{}/'.format(search_regex)

    for property in step.context.stash.properties:
        if type(property.property_value) in [str, unicode]:
            property.property_value = [property.property_value]
        elif type(property.property_value) is dict:
            property.property_value = property.property_value.values()

        for value in property.property_value:
            matches = re.match(regex, value)
            assert matches is not None, \
                '{} property in {} does not match with {} regex. It is set to {} instead.'.format(property.property_name,
                                                                                                  property.resource_name,
                                                                                                  search_regex,
                                                                                                  value)