Пример #1
0
    def test_chainception(self):
        """
        You can also chain FilterChains together.
        """
        fc1 = f.NotEmpty | f.Choice(choices=('Lucky', 'Dusty', 'Ned'))
        fc2 = f.NotEmpty | f.MinLength(4)

        self.filter_type = lambda: fc1 | fc2

        self.assertFilterPasses('Lucky')
        self.assertFilterErrors('El Guapo', [f.Choice.CODE_INVALID])
        self.assertFilterErrors('Ned', [f.MinLength.CODE_TOO_SHORT])
Пример #2
0
    def test_stop_after_invalid_value(self):
        """
        A FilterChain stops processing the incoming value after any
        filter fails.
        """
        # This FilterChain will pretty much reject anything that you
        # throw at it.
        self.filter_type =\
            lambda: f.MaxLength(3) | f.MinLength(8) | f.Required

        # Note that the value 'foobar' fails both the MaxLength and the
        # MinLength filters, but the FilterChain stops processing
        # after MaxLength fails.
        self.assertFilterErrors('foobar', [f.MaxLength.CODE_TOO_LONG])
Пример #3
0
 def Filter2():
     return f.Split(r'\s+') | f.MinLength(2)
Пример #4
0
 def MyFilter(min_length=12):
     return f.Unicode | f.MinLength(min_length)
Пример #5
0
 def MyFilter():
     return f.Unicode | f.Strip | f.MinLength(12)