Refactorings
This commit is contained in:
parent
66a4c81e0e
commit
db8a24b5d4
|
@ -3,3 +3,4 @@ build
|
|||
dist
|
||||
MANIFEST
|
||||
*.egg-info
|
||||
venv
|
||||
|
|
|
@ -9,7 +9,7 @@ python:
|
|||
- "3.7-dev" # 3.7 development branch
|
||||
# command to install dependencies
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
- pip install -e .
|
||||
# command to run tests
|
||||
script:
|
||||
- nosetests
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
from pyemailval.regex_check import regex_check
|
||||
from pyemailval.mx_check import mx_check
|
||||
from pyemailval.validate_email import validate_email
|
||||
|
||||
validate_email
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
from .regex_check import regex_check
|
||||
|
||||
VALID_EMAIL_ADDRESS_EXAMPLES = [
|
||||
"email@domain.com", # basic valid email
|
||||
"firstname.lastname@domain.com", # dot in address field
|
||||
"email@subdomain.domain.com", # dot in subdomain
|
||||
"firstname+lastname@domain.com", # + in address field
|
||||
"email@123.123.123.123", # domain address is IP address
|
||||
"email@[123.123.123.123]", # square brackets around IP address
|
||||
"\"email\"@domain.com", # quote marks in address fields
|
||||
"1234567890@domain.com", # numbers in address field
|
||||
"email@domain-one.com", # dash in subdomain
|
||||
"_______@domain.com", # underscore in address field
|
||||
"email@domain.name", # .name top level domain name
|
||||
"email@domain.co.jp", # dot in top level domain
|
||||
"firstname-lastname@domain.com" # dash in address field
|
||||
]
|
||||
|
||||
INVALID_EMAIL_ADDRESS_EXAMPLES = [
|
||||
"plainaddress", # missing @ sign and domain
|
||||
"#@%^%#$@#$@#.com", # garbage
|
||||
"@domain.com", # missing username
|
||||
"Joe Smith <email@domain.com>", # encoded html within email is invalid
|
||||
"email.domain.com", # missing @
|
||||
"email@domain@domain.com", # two @ sign
|
||||
".email@domain.com", # leading dot in address is not allowed
|
||||
"email.@domain.com", # trailing dot in address is not allowed
|
||||
"email..email@domain.com", # multiple dots
|
||||
"あいうえお@domain.com", # unicode char as address
|
||||
"email@domain.com (Joe Smith)", # text followed email is not allowed
|
||||
"email@domain", # missing top level domain (.com/.net/.org/etc)
|
||||
"email@-domain.com", # leading dash in front of domain is invalid
|
||||
"email@domain.web", # .web is not a valid top level domain
|
||||
"email@111.222.333.44444", # invalid IP format
|
||||
"email@domain..com", # multiple dot in the domain portion is invalid
|
||||
]
|
||||
|
||||
|
||||
def test_valid_email_structure_regex():
|
||||
for index, valid_email_address in enumerate(VALID_EMAIL_ADDRESS_EXAMPLES):
|
||||
try:
|
||||
assert regex_check(valid_email_address) is True
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
||||
"{} should be valid ({}th email address in the list)"
|
||||
.format(valid_email_address, index))
|
||||
|
||||
def test_invalid_email_structure_regex():
|
||||
for index, invalid_email_address in enumerate(INVALID_EMAIL_ADDRESS_EXAMPLES):
|
||||
try:
|
||||
assert regex_check(invalid_email_address) is False
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
||||
"{} should be invalid ({}th email address in the list)"
|
||||
.format(invalid_email_address, index))
|
|
@ -3,10 +3,7 @@ from .mx_check import mx_check
|
|||
|
||||
|
||||
def validate_email(
|
||||
email_address,
|
||||
check_regex=True,
|
||||
check_mx=True,
|
||||
smtp_timeout=10):
|
||||
email_address, check_regex=True, check_mx=True, smtp_timeout=10):
|
||||
|
||||
if check_regex and not regex_check(email_address):
|
||||
return False
|
||||
|
|
22
setup.py
22
setup.py
|
@ -1,16 +1,16 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="pyemailval",
|
||||
version="0.6",
|
||||
py_modules=("pyemailval",),
|
||||
name='pyemailval',
|
||||
version='0.6',
|
||||
py_modules=('pyemailval',),
|
||||
install_requires=['dnspython', 'nose'],
|
||||
author="Ben Baert",
|
||||
author_email="ben_b@gmx.com",
|
||||
description="pyemailval verifies if an email address really exists.",
|
||||
long_description=open("README.rst").read(),
|
||||
keywords="email validation verification mx verify",
|
||||
url="http://github.com/ben-baert/pyemailval",
|
||||
download_url="http://github.com/ben-baert/pyemailval/archive/0.1.tar.gz",
|
||||
license="LGPL",
|
||||
author='Ben Baert',
|
||||
author_email='laszlo@karolyi.hu',
|
||||
description='pyemailval verifies if an email address really exists.',
|
||||
long_description=open('README.rst').read(),
|
||||
keywords='email validation verification mx verify',
|
||||
url='http://github.com/karolyi/pyemailval',
|
||||
download_url='http://github.com/karolyi/pyemailval/archive/0.1.tar.gz',
|
||||
license='LGPL',
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from .mx_check import _get_domain_from_email_address
|
||||
from pyemailval.regex_check import _get_domain_from_email_address
|
||||
|
||||
|
||||
DOMAINS = {
|
||||
|
@ -14,7 +14,8 @@ DOMAINS = {
|
|||
def test_domain_from_email_address():
|
||||
for email_address, domain in DOMAINS.items():
|
||||
try:
|
||||
domain_from_function = _get_domain_from_email_address(email_address)
|
||||
domain_from_function = _get_domain_from_email_address(
|
||||
email_address)
|
||||
assert domain_from_function == domain
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
|
@ -0,0 +1,57 @@
|
|||
from pyemailval.regex_check import regex_check
|
||||
|
||||
VALID_EMAIL_ADDRESS_EXAMPLES = [
|
||||
'email@domain.com', # basic valid email
|
||||
'firstname.lastname@domain.com', # dot in address field
|
||||
'email@subdomain.domain.com', # dot in subdomain
|
||||
'firstname+lastname@domain.com', # + in address field
|
||||
'email@123.123.123.123', # domain address is IP address
|
||||
'email@[123.123.123.123]', # square brackets around IP address
|
||||
'\'email\'@domain.com', # quote marks in address fields
|
||||
'1234567890@domain.com', # numbers in address field
|
||||
'email@domain-one.com', # dash in subdomain
|
||||
'_______@domain.com', # underscore in address field
|
||||
'email@domain.name', # .name top level domain name
|
||||
'email@domain.co.jp', # dot in top level domain
|
||||
'firstname-lastname@domain.com' # dash in address field
|
||||
]
|
||||
|
||||
INVALID_EMAIL_ADDRESS_EXAMPLES = [
|
||||
'plainaddress', # missing @ sign and domain
|
||||
'#@%^%#$@#$@#.com', # garbage
|
||||
'@domain.com', # missing username
|
||||
'Joe Smith <email@domain.com>', # encoded html within email is invalid
|
||||
'email.domain.com', # missing @
|
||||
'email@domain@domain.com', # two @ sign
|
||||
'.email@domain.com', # leading dot in address is not allowed
|
||||
'email.@domain.com', # trailing dot in address is not allowed
|
||||
'email..email@domain.com', # multiple dots
|
||||
'あいうえお@domain.com', # unicode char as address
|
||||
'email@domain.com (Joe Smith)', # text followed email is not allowed
|
||||
'email@domain', # missing top level domain (.com/.net/.org/etc)
|
||||
'email@-domain.com', # leading dash in front of domain is invalid
|
||||
'email@domain.web', # .web is not a valid top level domain
|
||||
'email@111.222.333.44444', # invalid IP format
|
||||
'email@domain..com', # multiple dot in the domain portion is invalid
|
||||
]
|
||||
|
||||
|
||||
def test_valid_email_structure_regex():
|
||||
for index, valid_email_address in enumerate(VALID_EMAIL_ADDRESS_EXAMPLES):
|
||||
try:
|
||||
assert regex_check(valid_email_address) is True
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
||||
'{} should be valid ({}th email address in the list)'
|
||||
.format(valid_email_address, index))
|
||||
|
||||
|
||||
def test_invalid_email_structure_regex():
|
||||
for index, invalid_email_address in \
|
||||
enumerate(INVALID_EMAIL_ADDRESS_EXAMPLES):
|
||||
try:
|
||||
assert regex_check(invalid_email_address) is False
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
||||
'{} should be invalid ({}th email address in the list)'
|
||||
.format(invalid_email_address, index))
|
Loading…
Reference in New Issue