From 1f519df8ca019d34ea07b4287541b8ba011064b7 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Tue, 4 Apr 2017 11:55:44 -0400 Subject: [PATCH] Finish test suite for package linking via email --- gratipay/models/participant/email.py | 2 +- tests/py/test_email.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gratipay/models/participant/email.py b/gratipay/models/participant/email.py index a5e456dabe..34c41f838e 100644 --- a/gratipay/models/participant/email.py +++ b/gratipay/models/participant/email.py @@ -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) diff --git a/tests/py/test_email.py b/tests/py/test_email.py index 691087bad3..8aa5170d1c 100644 --- a/tests/py/test_email.py +++ b/tests/py/test_email.py @@ -168,10 +168,18 @@ def test_verify_email_expired_nonce(self): def test_finish_email_verification(self): self.hit_email_spt('add-email', 'alice@example.com') nonce = self.alice.get_email('alice@example.com').nonce - self.finish_email_verification('alice@example.com', nonce) - expected = 'alice@example.com' - actual = P('alice').email_address - assert expected == actual + assert self.finish_email_verification('alice@example.com', nonce).code == 200 + assert P('alice').email_address == 'alice@example.com' + + 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. @@ -706,13 +714,13 @@ 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() @@ -720,15 +728,15 @@ def test_verified_address_and_no_packages_is_a_no_go(self): 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')