Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Finish test suite for package linking via email
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Apr 4, 2017
1 parent 9df2002 commit 1f519df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gratipay/models/participant/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _set_primary_email(self, email, cursor):


def finish_email_verification(self, email, nonce):
if '' in (email, nonce):
if '' in (email.strip(), nonce.strip()):
return VERIFICATION_MISSING
with self.db.get_cursor() as cursor:
record = self.get_email(email, cursor)
Expand Down
28 changes: 18 additions & 10 deletions tests/py/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ def test_verify_email_expired_nonce(self):
def test_finish_email_verification(self):
self.hit_email_spt('add-email', '[email protected]')
nonce = self.alice.get_email('[email protected]').nonce
self.finish_email_verification('[email protected]', nonce)
expected = '[email protected]'
actual = P('alice').email_address
assert expected == actual
assert self.finish_email_verification('[email protected]', nonce).code == 200
assert P('alice').email_address == '[email protected]'

def test_empty_email_results_in_missing(self):
for empty in ('', ' '):
result = self.alice.finish_email_verification(empty, 'foobar')
assert result == _email.VERIFICATION_MISSING

def test_empty_nonce_results_in_missing(self):
for empty in ('', ' '):
result = self.alice.finish_email_verification('foobar', empty)
assert result == _email.VERIFICATION_MISSING

def test_email_verification_is_backwards_compatible(self):
"""Test email verification still works with unencoded email in verification link.
Expand Down Expand Up @@ -706,29 +714,29 @@ def test_preverify_preverifies(self):


def test_unverified_address_and_no_packages_succeeds(self):
assert self.check()
self.check()

def test_unverified_address_and_one_package_succeeds(self):
assert self.check('foo')
self.check('foo')

def test_unverified_address_and_multiple_packages_succeeds(self):
assert self.check('foo', 'bar')
self.check('foo', 'bar')

def test_verified_address_and_no_packages_is_a_no_go(self):
self.preverify()
raises(EmailAlreadyVerified, self.check)

def test_verified_address_and_one_package_succeeds(self):
self.preverify()
assert self.check('foo')
self.check('foo')

def test_verified_address_and_multiple_packages_succeeds(self):
self.preverify()
assert self.check('foo', 'bar')
self.check('foo', 'bar')


def test_while_we_are_at_it_that_packages_have_unique_teams_that_survive_comparison(self):
self.test_handles_verified_address_and_multiple_packages()
self.test_verified_address_and_multiple_packages_succeeds()

foo = Package.from_names('npm', 'foo')
bar = Package.from_names('npm', 'bar')
Expand Down

0 comments on commit 1f519df

Please sign in to comment.