Skip to content

Commit

Permalink
Merge pull request coagulant#55 from hovel/any_email
Browse files Browse the repository at this point in the history
Add any_email shortcut
  • Loading branch information
GeyseR committed Nov 7, 2016
2 parents bbe735b + e312a59 commit 368a8ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions django_any/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def any_email_field(field, **kwargs):
>>> re.match(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", result, re.IGNORECASE) is not None
True
"""
return "%s@%s.%s" % (xunit.any_string(max_length=10),
xunit.any_string(max_length=10),
xunit.any_string(min_length=2, max_length=3))
return xunit.any_email()


@any_field.register(models.FloatField)
Expand Down
15 changes: 15 additions & 0 deletions django_any/xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
The python basic types generators
"""
import re
import random
from string import ascii_letters
from datetime import date, datetime, timedelta
Expand Down Expand Up @@ -146,3 +147,17 @@ def any_decimal(min_value=Decimal(0), max_value=Decimal('99.99'), decimal_places
max_value=float(max_value),
precision=decimal_places)))


def any_email():
"""
Return random email
>>> result = any_email()
>>> type(result)
<type 'str'>
>>> re.match(r"(?:^|\s)[-a-z0-9_.]+@(?:[-a-z0-9]+\.)+[a-z]{2,6}(?:\s|$)", result, re.IGNORECASE) is not None
True
"""
return "%s@%s.%s" % (any_string(max_length=10),
any_string(max_length=10),
any_string(min_length=2, max_length=3))

0 comments on commit 368a8ae

Please sign in to comment.