How to use the mixer.generators function in mixer

To help you get started, we’ve selected a few mixer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / mixer / mixer / fakers.py View on Github external
::

        print get_city()  # -> North Carter

    """
    prf, sfx, city = g.get_choice(CITY_PREFIXIES), g.get_choice(CITY_SUFFIXIES), g.get_choice(CITIES) #noqa

    return g.get_choice((
        city,
        "{0} {1}".format(prf, city),
        "{0} {1}".format(prf, get_firstname()),
        "{0} {1}".format(get_lastname(), sfx),
    ))

#: Generator's fabric for :meth:`mixer.fakers.get_city`
gen_city = g.loop(get_city)


def get_lorem(length=None, **kwargs):
    """ Get a text (based on lorem ipsum.

    :return str:

    ::

        print get_lorem()  # -> atque rerum et aut reiciendis...

    """
    lorem = ' '.join(g.get_choices(LOREM_CHOICES))
    if length:
        lorem = lorem[:length]
        lorem, _ = lorem.rsplit(' ', 1)
github klen / mixer / mixer / backend / yadm.py View on Github external
:param field_name: Field name
        :param fake: Force fake data

        :return generator:

        """
        ftype = type(yadm_field)
        kwargs = {} if kwargs is None else kwargs

        if getattr(yadm_field, 'choices', None):
            if isinstance(yadm_field.choices[0], tuple):
                choices, _ = list(zip(*yadm_field.choices))
            else:
                choices = list(yadm_field.choices)

            return partial(gen.get_choice, choices)

        elif isinstance(yadm_field, ReferenceField):
            ftype = yadm_field.reference_document_class

        elif isinstance(yadm_field, EmbeddedDocumentField):
            ftype = yadm_field.embedded_document_class

        elif ftype is DecimalField:
            sign, (ii,), dd = yadm_field.precision.as_tuple()
            kwargs['d'] = abs(dd)
            kwargs['positive'] = not sign
            kwargs['i'] = ii + 1

        elif ftype in (SetField, ListField):
            kwargs.update({'_typemixer': self, '_scheme': yadm_field})
github klen / mixer / mixer / fakers.py View on Github external
def get_hostname(host=None, zone=None, **kwargs):
    """ Get a hostname.

    :return str:

    ::

        print get_hostname()  # -> twitter.az

    """
    params = dict(
        host=host or g.get_choice(HOSTNAMES),
        zone=zone or g.get_choice(HOSTZONES)
    )
    return g.get_choice((
        '{host}.{zone}'.format(**params),
        'www.{host}.{zone}'.format(**params)
    ))
github klen / mixer / mixer / fakers.py View on Github external
def get_firstname(**kwargs):
    """ Get a first name.

    :return str:

    ::

        print get_firstname()  # -> Johnson

    """
    return g.get_choice(FIRSTNAMES)
github klen / mixer / mixer / fakers.py View on Github external
def get_username(length=100, choices=DEFAULT_USERNAME_MASK_CHOICES, **kwargs):
    """ Get a username.

    :return str:

    ::

        print get_username()  # -> boss1985

    """
    gen = g.gen_choice(USERNAMES)
    params = dict(
        one=next(gen),
        two=next(gen),
        num=g.get_integer(low=1900, high=2020),
    )
    mask = g.get_choice(choices)
    username = mask.format(**params)
    return username[:length]
github klen / mixer / mixer / fakers.py View on Github external
def get_username(length=100, choices=DEFAULT_USERNAME_MASK_CHOICES, **kwargs):
    """ Get a username.

    :return str:

    ::

        print get_username()  # -> boss1985

    """
    gen = g.gen_choice(USERNAMES)
    params = dict(
        one=next(gen),
        two=next(gen),
        num=g.get_integer(low=1900, high=2020),
    )
    mask = g.get_choice(choices)
    username = mask.format(**params)
    return username[:length]
github klen / mixer / mixer / fakers.py View on Github external
def get_latlon(**kwargs):
    """ Get a value simular to latitude (longitude).

    :return float:

    ::

        print get_latlon()  # -> 137.60858

    """
    return float(
        decimal.Decimal(str(g.get_float(-180, 180))).quantize(GEOCOORD_MASK))
github klen / mixer / mixer / fakers.py View on Github external
def get_ip4(**kwargs):
    """ Get IPv4 address.

    :return str:

    ::

        print get_ip4()  # 192.168.1.1

    """
    gen = g.gen_positive_integer(255)
    return '{0}.{1}.{2}.{3}'.format(next(gen), next(gen), next(gen), next(gen))