예제 #1
0
파일: filters.py 프로젝트: boegel/vsc-ldap
class LdapFilterGenerator(PayCheckGenerator):
    """Generates random LdapFilter instances"""

    def __init__(self):
        #super(LdapFilterGenerator, self).__init__()

        self.attributes = [
            'cn',
            'status',
            'institute',
            'memberUid',
            'moderator',
        ]

        self.operators = (
            LdapFilter.__and__,
            LdapFilter.__or__,
            LdapFilter.negate,
        )

        self.depth = IntGenerator(min=1, max=len(self.attributes))
        self.operator_choice = ChoiceGenerator(self.operators)
        self.value_generator = LdapAttributeStringGenerator(16)
        self.side_generator = BooleanGenerator()

    def next(self):

        ldap_filter = None
        attributes = copy.deepcopy(self.attributes)
        attribute_choice = SingleChoiceGenerator(attributes)

        size = random.randint(1, self.depth.next())

        for d in xrange(0, size):

            op = self.operator_choice.next()
            at = attribute_choice.next()

            new = LdapFilter("%s=%s" % (at, self.value_generator.next()))

            if not ldap_filter:
                ldap_filter = LdapFilter(new)
            else:
                if op == LdapFilter.negate:
                    ldap_filter = op(ldap_filter)
                else:
                    if self.side_generator.next():
                        ldap_filter = op(new, ldap_filter)
                    else:
                        ldap_filter = op(ldap_filter, new)

        return ldap_filter
예제 #2
0
파일: filters.py 프로젝트: boegel/vsc-ldap
    def __init__(self):
        #super(LdapFilterGenerator, self).__init__()

        self.attributes = [
            'cn',
            'status',
            'institute',
            'memberUid',
            'moderator',
        ]

        self.operators = (
            LdapFilter.__and__,
            LdapFilter.__or__,
            LdapFilter.negate,
        )

        self.depth = IntGenerator(min=1, max=len(self.attributes))
        self.operator_choice = ChoiceGenerator(self.operators)
        self.value_generator = LdapAttributeStringGenerator(16)
        self.side_generator = BooleanGenerator()