omaciel / fauxfactory

Generates random data for your tests.
Other
37 stars 26 forks source link

add validator argument #86

Closed rochacbruno closed 7 years ago

rochacbruno commented 7 years ago

Example: we want to generate names, but names cannot start with numbers.

from fauxfactory import gen_string

name = gen_string(
    'alpha', 
    validator=lambda x: not x.startswith(('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')),
    default='foobar',
    tries=10
)

or simpler

name = gen_string(
    'alpha', 
    validator=lambda x: not x[0].isdigit(),
    default='foobar',
    tries=10
)

So fauxfactory should accept validator which should return True, otherwise the value is None or default. If tries is set, then it retries to generate 10 times, if tries = 0 it tries to generate until validator is met!

BONUS: the validator must be callable or re.Pattern instance, so it checks for regex matching.

rochacbruno commented 7 years ago

from: https://github.com/SatelliteQE/robottelo/issues/4407

renzon commented 7 years ago

@omaciel can you add me to this project so I can assign issues to myself? Until there, I am assigning this one to my self.