Skip to content

Commit

Permalink
[Feature #137592409] Add test for set_password function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kipyegon committed Feb 18, 2017
1 parent 462f4c3 commit 5ab3a7e
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions hc/accounts/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from django.contrib.auth.models import User
from hc.accounts.models import Profile
from django.core.signing import Signer

from django.contrib.auth.hashers import make_password
from django.contrib.auth.hashers import check_password

class ProfileTestCase(BaseTestCase):

Expand All @@ -23,7 +24,7 @@ def test_it_sends_set_password_link(self):
token = self.alice.profile.token

# Assert that the token is set
self.assertTrue(len(token)>10)
self.assertTrue(len(token) > 10)

#Assering that the email has been sent
self.assertEqual(len(mail.outbox), 1)
Expand Down Expand Up @@ -277,3 +278,37 @@ def test_unsubscribe_reports_with_bad_signature(self):
r = self.client.get(url, {'token': 'secret-token'})
self.assertEqual(r.status_code, 400)

def test_it_set_password(self):
self.profile.token = make_password("secret-token")
self.profile.save()
self.client.login(username="alice@example.org", password="password")
url = "/accounts/set_password/secret-token/"
r = self.client.post(url)
self.assertContains(r, "Set a Password")
self.assertTemplateUsed(r, "accounts/set_password.html")

def test_set_password_with_invalid_token(self):
self.profile.token = make_password("secret-token")
self.profile.save()
self.client.login(username="alice@example.org", password="password")
url = "/accounts/set_password/invalid/"
r = self.client.post(url)
self.assertEqual(r.status_code, 400)

def test_set_password_redirects(self):
self.profile.token = make_password("secret-token")
self.profile.save()
self.client.login(username="alice@example.org", password="password")
form = {"password": "password2"}
url = "/accounts/set_password/secret-token/"
r = self.client.post(url, form)
self.assertRedirects(r, "/accounts/profile/")









0 comments on commit 5ab3a7e

Please sign in to comment.