API Documentation¶
This is a complete list of available methods, along with details about them.
fauxfactory
¶
Generate random data for your tests.
fauxfactory.factories.booleans
¶
Method for generating random boolean values.
fauxfactory.factories.choices
¶
Module to keep methods related to selecting values.
fauxfactory.constants
¶
Constants used by fauxfactory
.
- fauxfactory.constants.VALID_NETMASKS¶
A tuple of netmasks. The tuple index corresponds to a CIDR value. For example, a CIDR of “/1” corresponds to VALID_NETMASKS[1].
fauxfactory.factories.dates
¶
Methods related to generating date/time related values.
- fauxfactory.factories.dates.gen_date(min_date=None, max_date=None)[source]¶
Return a random date value.
- Parameters:
min_date – A valid
datetime.date
object.max_date – A valid
datetime.date
object.
- Raises:
ValueError
if arguments are not validdatetime.date
objects.- Returns:
Random
datetime.date
object.
- fauxfactory.factories.dates.gen_datetime(min_date=None, max_date=None)[source]¶
Return a random datetime value.
- Parameters:
min_date – A valid
datetime.datetime
object.max_date – A valid
datetime.datetime
object.
- Raises:
ValueError
if arguments are not validdatetime.datetime
objects.- Returns:
Random
datetime.datetime
object.
fauxfactory.helpers
¶
Collection of helper methods and functions.
- class fauxfactory.helpers.UnicodePlane(min, max)¶
- max¶
Alias for field number 1
- min¶
Alias for field number 0
- fauxfactory.helpers.base_repr(number, base)[source]¶
Return the base representation of a decimal number.
As shared here: https://stackoverflow.com/a/2267446
Conversion steps:
Divide the number by the base
Get the integer quotient for the next iteration
Get the remainder for the hex digit
Repeat the steps until quotient is equal to zero
- Parameters:
number – (int) The decimal number to be converted.
base – The base to convert.
- Returns:
The base representation of <number>.
- fauxfactory.helpers.check_validation(fcn)[source]¶
Decorate functions requiring validation.
Simple decorator to validate values generated by function fnc according to parameters validator, default and tries.
- Parameters:
fcn – function to be enhanced
- Returns:
decorated function
fauxfactory.factories.internet
¶
Methods related to generating internet related values.
- fauxfactory.factories.internet.gen_alpha(length=10, start=None, separator='')[source]¶
Return a random string made up of alpha characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of alpha characters.
- Return type:
str
- fauxfactory.factories.internet.gen_choice(choices)[source]¶
Return a random choice from the available choices.
- Parameters:
choices (list) – List of choices from which select a random value.
- Raises:
ValueError
ifchoices
isNone
or notIterable
or adict
.- Returns:
A random element from
choices
.
- fauxfactory.factories.internet.gen_domain(name=None, subdomain=None, tlds=None)[source]¶
Generate a random domain name.
- Parameters:
name (str) – Name for your host.
subdomain (str) – Name for the subdomain.
tlds (str) – Top Level Domain Server.
- Returns:
A random domain name.
- Return type:
str
- fauxfactory.factories.internet.gen_email(name=None, domain=None, tlds=None)[source]¶
Generate a random email address.
- Parameters:
name (str) – Email name.
domain (str) – Domain name.
tlds (str) – Top Level Domain Server.
- Returns:
An email address.
- Return type:
str
- fauxfactory.factories.internet.gen_ipaddr(ip3=False, ipv6=False, prefix=())[source]¶
Generate a random IP address.
You can also specify an IP address prefix if you are interested in local network address generation, etc.
- Parameters:
ip3 (bool) – Whether to generate a 3 or 4 group IP.
ipv6 (bool) – Whether to generate IPv6 or IPv4
prefix (list) – A prefix to be used for an IP (e.g. [10, 0, 1]). It must be an iterable with strings or integers. Can be left unspecified or empty.
- Returns:
An IP address.
- Return type:
str
- Raises:
ValueError
ifprefix
would lead to no random fields at all. This means the length that triggers theValueError
is 4 for regular IPv4, 3 for IPv4 with ip3 and 8 for IPv6. It will be raised in any case the prefix length reaches or exceeds those values.
- fauxfactory.factories.internet.gen_mac(delimiter=':', multicast=None, locally=None)[source]¶
Generate a random MAC address.
For more information about how unicast or multicast and globally unique and locally administered MAC addresses are generated check this link https://en.wikipedia.org/wiki/MAC_address.
- Parameters:
delimiter (str) – Valid MAC delimiter (e.g ‘:’, ‘-‘).
multicast (bool) – Indicates if the generated MAC address should be unicast or multicast. If no value is provided a random one will be chosen.
locally (bool) – Indicates if the generated MAC address should be globally unique or locally administered. If no value is provided a random one will be chosen.
- Returns:
A random MAC address.
- Return type:
str
- fauxfactory.factories.internet.gen_netmask(min_cidr=1, max_cidr=31)[source]¶
Generate a random valid netmask.
For more info: http://www.iplocation.net/tools/netmask.php
- Parameters:
min_cidr (int) – Inferior CIDR limit
max_cidr (int) – Superior CIDR limit
- Returns:
The netmask is chosen from
fauxfactory.constants.VALID_NETMASKS
respecting the CIDR range- Return type:
str
- Raises:
ValueError
ifmin_cidr
ormax_cidr
have an invalid value. For example,max_cidr
cannot be 33.
- fauxfactory.factories.internet.gen_url(scheme=None, subdomain=None, tlds=None)[source]¶
Generate a random URL address.
- Parameters:
scheme (str) – Either http, https or ftp.
subdomain (str) – A valid subdomain
tlds (str) – A qualified top level domain name (e.g. ‘com’, ‘net’)
- Raises:
ValueError
if arguments are not valid.- Returns:
A random URL address.
- Return type:
str
fauxfactory.factories.numbers
¶
Methods that generate random number values.
- fauxfactory.factories.numbers.gen_hexadecimal(min_value=None, max_value=None, *, base=16)¶
Return a random number (with <base> representation).
- Returns:
A random number with base of <base>.
- Return type:
str
- fauxfactory.factories.numbers.gen_integer(min_value=None, max_value=None)[source]¶
Return a random integer value based on the current platform.
- Parameters:
min_value (int) – The minimum allowed value.
max_value (int) – The maximum allowed value.
- Raises:
ValueError
if arguments are not integers or if they are less or greater than the system’s allowed range for integers.- Returns:
Returns a random integer value.
- Return type:
int
- fauxfactory.factories.numbers.gen_negative_integer()[source]¶
Return a random negative integer based on the current platform.
- Returns:
Returns a random negative integer value.
- Return type:
int
- fauxfactory.factories.numbers.gen_number(min_value=None, max_value=None, base=10)[source]¶
Return a random number (with <base> representation).
- Returns:
A random number with base of <base>.
- Return type:
str
- fauxfactory.factories.numbers.gen_octagonal(min_value=None, max_value=None, *, base=8)¶
Return a random number (with <base> representation).
- Returns:
A random number with base of <base>.
- Return type:
str
fauxfactory.factories.strings
¶
Collection of string generating functions.
- fauxfactory.factories.strings.gen_alpha(length=10, start=None, separator='')[source]¶
Return a random string made up of alpha characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of alpha characters.
- Return type:
str
- fauxfactory.factories.strings.gen_alphanumeric(length=10, start=None, separator='')[source]¶
Return a random string made up of alpha and numeric characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of alpha and numeric characters.
- Return type:
str
- fauxfactory.factories.strings.gen_cjk(length=10, start=None, separator='')[source]¶
Return a random string made up of CJK characters.
(Source: Wikipedia - CJK Unified Ideographs)
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of CJK characters.
- Return type:
str
- fauxfactory.factories.strings.gen_cyrillic(length=10, start=None, separator='')[source]¶
Return a random string made up of Cyrillic characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of Cyrillic characters.
- Return type:
str
- fauxfactory.factories.strings.gen_html(length=10, include_tags=True)[source]¶
Return a random string made up of html characters.
- Parameters:
length (int) – Length for random data.
- Returns:
A random string made up of html characters.
- Return type:
str
- fauxfactory.factories.strings.gen_iplum(words=None, paragraphs=None)[source]¶
Return a lorem ipsum string.
If no arguments are passed, then return the entire default lorem ipsum string.
- Parameters:
words (int) – The number of words to return.
paragraphs (int) – The number of paragraphs to return.
- Raises:
ValueError
ifwords
is not a valid positive integer.- Returns:
A
lorem ipsum
string containing either the number ofwords
orparagraphs
, extending and wrapping around the text as needed to make sure that it has the specified length.- Return type:
str
- fauxfactory.factories.strings.gen_latin1(length=10, start=None, separator='')[source]¶
Return a random string made up of UTF-8 characters.
(Font: Wikipedia - Latin-1 Supplement Unicode Block)
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of
Latin1
characters.- Return type:
str
- fauxfactory.factories.strings.gen_numeric_string(length=10, start=None, separator='')[source]¶
Return a random string made up of numbers.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of numbers.
- Return type:
str
- fauxfactory.factories.strings.gen_special(length=10, start=None, separator='')[source]¶
Return a random special characters string.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of special characters.
- Return type:
str
- fauxfactory.factories.strings.gen_string(str_type, length=None, validator=None, default=None, tries=10)[source]¶
Call other string generation methods.
- Parameters:
str_type (str) – The type of string which should be generated.
length (int) – The length of the generated string. Must be 1 or greater.
validator – Function or regex (str). If a function it must receive one parameter and return True if value can be used and False of another value need to be generated. If str it will be used as regex to validate the generated value. Default is None which will not validate the value.
tries – number of times validator must be called before returning default. Default is 10.
default – If validator returns false a number of tries times, this value is returned instead. Must be defined if validator is not None
- Raises:
ValueError
if an invalidstr_type
is specified.- Returns:
A string.
- Return type:
str
Valid values for
str_type
are as follows:alpha
alphanumeric
cjk
cyrillic
html
latin1
numeric
utf8
punctuation
- fauxfactory.factories.strings.gen_utf8(length=10, smp=True, start=None, separator='')[source]¶
Return a random string made up of UTF-8 letters characters.
Follows RFC 3629.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
smp (bool) – Include Supplementary Multilingual Plane (SMP) characters
- Returns:
A random string made up of
UTF-8
letters characters.- Return type:
str
fauxfactory.factories.systems
¶
Collection of computer systems generating functions.
- fauxfactory.factories.systems.gen_alpha(length=10, start=None, separator='')[source]¶
Return a random string made up of alpha characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of alpha characters.
- Return type:
str
- fauxfactory.factories.systems.gen_alphanumeric(length=10, start=None, separator='')[source]¶
Return a random string made up of alpha and numeric characters.
- Parameters:
length (int) – Length for random data.
start (str) – Random data start with.
separator (str) – Separator character for start and random data.
- Returns:
A random string made up of alpha and numeric characters.
- Return type:
str
- fauxfactory.factories.systems.gen_choice(choices)[source]¶
Return a random choice from the available choices.
- Parameters:
choices (list) – List of choices from which select a random value.
- Raises:
ValueError
ifchoices
isNone
or notIterable
or adict
.- Returns:
A random element from
choices
.
- fauxfactory.factories.systems.gen_domain(name=None, subdomain=None, tlds=None)[source]¶
Generate a random domain name.
- Parameters:
name (str) – Name for your host.
subdomain (str) – Name for the subdomain.
tlds (str) – Top Level Domain Server.
- Returns:
A random domain name.
- Return type:
str
- fauxfactory.factories.systems.gen_integer(min_value=None, max_value=None)[source]¶
Return a random integer value based on the current platform.
- Parameters:
min_value (int) – The minimum allowed value.
max_value (int) – The maximum allowed value.
- Raises:
ValueError
if arguments are not integers or if they are less or greater than the system’s allowed range for integers.- Returns:
Returns a random integer value.
- Return type:
int
- fauxfactory.factories.systems.gen_ipaddr(ip3=False, ipv6=False, prefix=())[source]¶
Generate a random IP address.
You can also specify an IP address prefix if you are interested in local network address generation, etc.
- Parameters:
ip3 (bool) – Whether to generate a 3 or 4 group IP.
ipv6 (bool) – Whether to generate IPv6 or IPv4
prefix (list) – A prefix to be used for an IP (e.g. [10, 0, 1]). It must be an iterable with strings or integers. Can be left unspecified or empty.
- Returns:
An IP address.
- Return type:
str
- Raises:
ValueError
ifprefix
would lead to no random fields at all. This means the length that triggers theValueError
is 4 for regular IPv4, 3 for IPv4 with ip3 and 8 for IPv6. It will be raised in any case the prefix length reaches or exceeds those values.
- fauxfactory.factories.systems.gen_mac(delimiter=':', multicast=None, locally=None)[source]¶
Generate a random MAC address.
For more information about how unicast or multicast and globally unique and locally administered MAC addresses are generated check this link https://en.wikipedia.org/wiki/MAC_address.
- Parameters:
delimiter (str) – Valid MAC delimiter (e.g ‘:’, ‘-‘).
multicast (bool) – Indicates if the generated MAC address should be unicast or multicast. If no value is provided a random one will be chosen.
locally (bool) – Indicates if the generated MAC address should be globally unique or locally administered. If no value is provided a random one will be chosen.
- Returns:
A random MAC address.
- Return type:
str
- fauxfactory.factories.systems.gen_netmask(min_cidr=1, max_cidr=31)[source]¶
Generate a random valid netmask.
For more info: http://www.iplocation.net/tools/netmask.php
- Parameters:
min_cidr (int) – Inferior CIDR limit
max_cidr (int) – Superior CIDR limit
- Returns:
The netmask is chosen from
fauxfactory.constants.VALID_NETMASKS
respecting the CIDR range- Return type:
str
- Raises:
ValueError
ifmin_cidr
ormax_cidr
have an invalid value. For example,max_cidr
cannot be 33.
- fauxfactory.factories.systems.gen_system_facts(name=None)[source]¶
Generate system facts.
See https://docs.puppet.com/facter/3.6/core_facts.html for more information.
- Parameters:
name (str) – Name to be used as the system’s hostname.
- Returns:
A Dictionary representing a system’s facts.
- Return type:
dict