-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved email validator by performing a basic sanity check
instead of a more restrictive check. fixes #17
- Loading branch information
1 parent
8673049
commit 38003e3
Showing
7 changed files
with
62 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from expects import expect | ||
|
||
from booby import errors | ||
|
||
|
||
class String(object): | ||
def test_should_pass_if_value_is_none(self): | ||
self.validator(None) | ||
|
||
def test_should_fail_if_value_is_not_a_string(self): | ||
expect(lambda: self.validator(1)).to.raise_error( | ||
errors.ValidationError, 'should be a string') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
from expects import expect | ||
from . import mixins | ||
|
||
from booby import validators, errors | ||
|
||
|
||
class TestEmail(mixins.String): | ||
def test_should_pass_if_value_is_valid_email(self): | ||
self.validator('[email protected]') | ||
|
||
def test_should_pass_if_value_contains_plus_sign(self): | ||
self.validator('[email protected]') | ||
|
||
def test_should_pass_if_value_contains_minus_sign(self): | ||
self.validator('[email protected]') | ||
|
||
def test_should_pass_if_domain_is_tld(self): | ||
self.validator('foo@example') | ||
|
||
def test_should_fail_if_nothing_before_at_sign(self): | ||
expect(lambda: self.validator('@example')).to.raise_error( | ||
errors.ValidationError, 'should be a valid email') | ||
|
||
def test_should_fail_if_value_doesnt_have_at_sign(self): | ||
expect(lambda: self.validator('foo%example.com')).to.raise_error( | ||
errors.ValidationError, 'should be a valid email') | ||
|
||
def test_should_fail_if_empty_string(self): | ||
expect(lambda: self.validator('')).to.raise_error( | ||
errors.ValidationError, 'should be a valid email') | ||
|
||
def setup(self): | ||
self.validator = validators.Email() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
from __future__ import unicode_literals | ||
|
||
from expects import expect | ||
from . import mixins | ||
from .._helpers import stub_validator | ||
|
||
from booby import validators, fields, models, errors | ||
|
||
from ._helpers import stub_validator | ||
|
||
|
||
class TestRequired(object): | ||
def test_when_value_is_none_then_raises_validation_error(self): | ||
|
@@ -33,16 +33,7 @@ def setup(self): | |
self.validator = validators.In(['foo', 'bar']) | ||
|
||
|
||
class StringMixin(object): | ||
def test_when_value_is_not_string_then_raises_validation_error(self): | ||
expect(lambda: self.validator(1)).to.raise_error( | ||
errors.ValidationError, 'should be a string') | ||
|
||
def test_when_value_is_none_then_does_not_raise(self): | ||
self.validator(None) | ||
|
||
|
||
class TestString(StringMixin): | ||
class TestString(mixins.String): | ||
def test_when_value_is_a_string_then_does_not_raise(self): | ||
self.validator('foo') | ||
|
||
|
@@ -147,21 +138,5 @@ def setup(self): | |
self.validator = validators.List() | ||
|
||
|
||
class TestEmail(StringMixin): | ||
def test_when_value_doesnt_match_email_pattern_then_raises_validation_error(self): | ||
expect(lambda: self.validator('foo@example')).to.raise_error( | ||
errors.ValidationError, 'should be a valid email') | ||
|
||
def test_when_value_doesnt_have_at_sign_then_raises_validation_error(self): | ||
expect(lambda: self.validator('foo%example.com')).to.raise_error( | ||
errors.ValidationError, 'should be a valid email') | ||
|
||
def test_when_value_is_a_valid_email_then_does_not_raise(self): | ||
self.validator('[email protected]') | ||
|
||
def setup(self): | ||
self.validator = validators.Email() | ||
|
||
|
||
class User(models.Model): | ||
name = fields.String() |