Skip to content

Commit

Permalink
Merge 9806aee into 713949c
Browse files Browse the repository at this point in the history
  • Loading branch information
elyezer committed Oct 6, 2014
2 parents 713949c + 9806aee commit ec36ef7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions fauxfactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,17 +512,19 @@ def gen_mac(delimiter=":"):
return _make_unicode(mac)


def gen_netmask():
def gen_netmask(min_cidr=1, max_cidr=31):
"""Generates a random valid netmask.
For more info: http://www.iplocation.net/tools/netmask.php
:param int min_cidr: Inferior CIDR limit
:param int max_cidr: Superior CIDR limit
:returns: The netmask is chosen from
:data:`fauxfactory.constants.VALID_NETMASKS`.
:data:`fauxfactory.constants.VALID_NETMASKS` respecting the CIDR range
:rtype: str
"""
return random.choice(VALID_NETMASKS)
return VALID_NETMASKS[random.randint(min_cidr, max_cidr)]


def gen_numeric_string(length=10):
Expand Down
4 changes: 4 additions & 0 deletions fauxfactory/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
'org',
]

# The tuple index corresponds to a CIDR number
# E.g. CIDR 1 == VALID_NETMASKS[1]
VALID_NETMASKS = (
u'0.0.0.0',
u'128.0.0.0',
u'192.0.0.0',
u'224.0.0.0',
Expand Down Expand Up @@ -74,6 +77,7 @@
u'255.255.255.248',
u'255.255.255.252',
u'255.255.255.254',
u'255.255.255.255',
)

HTML_TAGS = [
Expand Down
4 changes: 2 additions & 2 deletions tests/test_netmasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


NETMASK_REGEX = re.compile(
'((255.){3}(0|128|192|224|240|248|252|254))|'
'((255.){3}(0|128|192|224|240|248|252|254|255))|'
'((255.){2}(0|128|192|224|240|248|252|254).0)|'
'(255.(0|128|192|224|240|248|252|254)(.0){2})|'
'((128|192|224|240|248|252|254)(.0){3})'
'((0|128|192|224|240|248|252|254)(.0){3})'
)


Expand Down

0 comments on commit ec36ef7

Please sign in to comment.