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

Commit

Permalink
Added tests, simplified verify_email
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk authored and chadwhitacre committed Sep 19, 2014
1 parent 9573fca commit 6188205
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ def change_email(self, email):
return result

def verify_email(self, hash_string):
confirmed = self.email.confirmed if hasattr(self.email, 'confirmed') else ''
if confirmed:
return 0 # Verified
original_hash = self.email.hash if hasattr(self.email, 'hash') else ''
email_ctime = self.email.ctime if hasattr(self.email, 'ctime') else ''
confirmed = self.email.confirmed if hasattr(self.email, 'confirmed') else ''
if (original_hash == hash_string) and ((utcnow() - email_ctime) < timedelta(hours=24)):
self.update_email(self.email.address,True)
return 0 # Verified
Expand All @@ -596,7 +598,6 @@ def get_verification_link(self):
link = "%s://%s/%s/verify-email.html?hash=%s" % (gratipay.canonical_scheme, gratipay.canonical_host, username, hash_string)
return link


def update_goal(self, goal):
typecheck(goal, (Decimal, None))
with self.db.get_cursor() as c:
Expand Down
23 changes: 14 additions & 9 deletions tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,27 @@ def test_john_is_plural(self):
assert actual == expected

def test_can_change_email(self):
self.alice.update_email('[email protected]')
self.alice.change_email('[email protected]')
expected = '[email protected]'
actual = self.alice.email.address
assert actual == expected

def test_cannot_confirm_email_in_one_step(self):
self.alice.update_email('[email protected]', True)
actual = self.alice.email.confirmed
assert actual == False

def test_can_confirm_email_in_second_step(self):
def test_can_verify_email(self):
self.alice.update_email('[email protected]')
self.alice.update_email('[email protected]', True)
actual = self.alice.email.confirmed
hash_string = Participant.from_username('alice').email.hash
self.alice.verify_email(hash_string)
actual = Participant.from_username('alice').email.confirmed
assert actual == True

def test_cannot_verify_email_with_wrong_hash(self):
self.alice.update_email('[email protected]')
hash_string = "some wrong hash"
self.alice.verify_email(hash_string)
actual = Participant.from_username('alice').email.confirmed
assert actual == False

# TODO - Add a test for expired hashes. (We don't have control over the ctime of emails)

def test_cant_take_over_claimed_participant_without_confirmation(self):
with self.assertRaises(NeedConfirmation):
self.alice.take_over(('twitter', str(self.bob.id)))
Expand Down

0 comments on commit 6188205

Please sign in to comment.