How to use the mixer.generators.loop 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
def get_name(mask=DEFAULT_NAME_MASK, length=100, **kwargs):
    """ Get a full name.

    :return str:

    ::

        print get_name()  # -> Barbara Clayworth

    """
    name = mask.format(firstname=get_firstname(), lastname=get_lastname())
    return name[:length]

#: Generator's fabric for :meth:`mixer.fakers.get_lastname`
gen_name = g.loop(get_name)


def get_country(**kwargs):
    """ Get a country.

    :return str:

    ::

        print get_country()  # -> Italy

    """
    return g.get_choice(COUNTRIES)

#: Generator's fabric for :meth:`mixer.fakers.get_country`
gen_country = g.loop(get_country)
github klen / mixer / mixer / fakers.py View on Github external
def get_street(**kwargs):
    """ Generate street name. """
    params = dict(
        first_name=get_firstname(),
        last_name=get_lastname(),
        suffix=g.get_choice(STREET_SUFFIXES),
    )

    return g.get_choice((
        '{first_name} {suffix}'.format(**params),
        '{last_name} {suffix}'.format(**params)
    ))

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


def get_address(**kwargs):
    """ Generate address. """
    params = dict(
        street=get_street(),
        number1=g.get_small_positive_integer(high=99),
        number2=g.get_integer(high=999, low=100),
    )

    return g.get_choice((
        '{number1} {street}'.format(**params),
        '{number1} {street} Apt. {number2}'.format(**params),
        '{number1} {street} Suite. {number2}'.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)

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


def get_lastname(**kwargs):
    """ Get a last name.

    :return str:

    ::

        print get_lastname()  # -> Gaspar

    """
    return g.get_choice(LASTNAMES)

#: Generator's fabric for :meth:`mixer.fakers.get_lastname`
gen_lastname = g.loop(get_lastname)
github klen / mixer / mixer / fakers.py View on Github external
def get_address(**kwargs):
    """ Generate address. """
    params = dict(
        street=get_street(),
        number1=g.get_small_positive_integer(high=99),
        number2=g.get_integer(high=999, low=100),
    )

    return g.get_choice((
        '{number1} {street}'.format(**params),
        '{number1} {street} Apt. {number2}'.format(**params),
        '{number1} {street} Suite. {number2}'.format(**params)
    ))

#: Generator's fabric for :meth:`mixer.fakers.get_address`
gen_address = g.loop(get_address)
github klen / mixer / mixer / fakers.py View on Github external
::

        print get_ip_generic()  # 192.168.1.1

    """
    if protocol == 'ipv4':
        choices = get_ip4(**kwargs),
    elif protocol == 'ipv6':
        choices = get_ip6(**kwargs),
    else:
        choices = get_ip4(**kwargs), get_ip6(**kwargs)

    return g.get_choice(choices)

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


def get_url(hostname=None, **kwargs):
    """ Get a URL.

    :return str:

    """
    if hostname is None:
        hostname = get_hostname()

    parts = [hostname]

    parts += g.get_choices(LOREM_CHOICES, g.get_integer(1, 3))

    return '/'.join(parts)
github klen / mixer / mixer / fakers.py View on Github external
return '/'.join(parts)

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


def get_uuid(**kwargs):
    """ Get a UUID.

    :return str:

    """
    return str(uuid.uuid1())

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


def get_phone(template='###-###-###', **kwargs):
    """ Get a phone number.

    :param template: A template for number.
    :return str:

    """
    return get_numerify(template)

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


def get_company(**kwargs):
github klen / mixer / mixer / fakers.py View on Github external
return get_numerify(template)

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


def get_company(**kwargs):
    """ Get a company name.

    :return str:

    """
    return '%s %s' % (get_lastname(), g.get_choice(COMPANY_SYFFIXES))

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


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))

#: Generator's fabric for :meth:`mixer.fakers.get_latlon`
github klen / mixer / mixer / fakers.py View on Github external
def get_simple_username(**kwargs):
    """ Get a simplest username.

    :return str:

    ::

        print get_username()  # -> boss1985

    """
    return get_username(choices=(
        '{one}', '{one}{num}'
    ))

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


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)
    )
github klen / mixer / mixer / fakers.py View on Github external
def get_slug(length=64, **kwargs):
    """ Get a part of URL using human-readable words.

    :returns: Generated string

    ::

        print get_slug()  # -> atque-rerum-et-aut-reiciendis

    """
    return get_short_lorem(length, **kwargs).replace(' ', '-')

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


def get_numerify(template='', symbol='#', **kwargs):
    """ Generate number string from templates.

    :return str:

    ::

        print get_numerify('####-##')  # -> 2345-23

    """
    return ''.join(
        (str(random.randint(0, 9)) if c == '#' else c)
        for c in template
    )
github klen / mixer / mixer / fakers.py View on Github external
def get_country(**kwargs):
    """ Get a country.

    :return str:

    ::

        print get_country()  # -> Italy

    """
    return g.get_choice(COUNTRIES)

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


def get_country_code():
    """ Get a country code.

    :return str:

    ::

        print get_country_code()  # -> ru

    """
    return g.get_choice(COUNTRY_CODES)

gen_country_code = g.loop(get_country_code)