You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  1. from django.core import mail
  2. from hc.test import BaseTestCase
  3. from hc.accounts.models import Profile
  4. class LoginTestCase(BaseTestCase):
  5. def test_it_sends_set_password_link(self):
  6. self.client.login(username="[email protected]", password="password")
  7. form = {"set_password": "1"}
  8. r = self.client.post("/accounts/profile/", form)
  9. assert r.status_code == 302
  10. # profile.token should be set now
  11. profile = Profile.objects.for_user(self.alice)
  12. self.assertTrue(len(profile.token) > 10)
  13. # And an email should have been sent
  14. self.assertEqual(len(mail.outbox), 1)
  15. expected_subject = 'Set password on healthchecks.io'
  16. self.assertEqual(mail.outbox[0].subject, expected_subject)
  17. def test_it_creates_api_key(self):
  18. self.client.login(username="[email protected]", password="password")
  19. form = {"create_api_key": "1"}
  20. r = self.client.post("/accounts/profile/", form)
  21. assert r.status_code == 200
  22. profile = Profile.objects.for_user(self.alice)
  23. self.assertTrue(len(profile.api_key) > 10)
  24. def test_it_revokes_api_key(self):
  25. self.client.login(username="[email protected]", password="password")
  26. form = {"revoke_api_key": "1"}
  27. r = self.client.post("/accounts/profile/", form)
  28. assert r.status_code == 200
  29. profile = Profile.objects.for_user(self.alice)
  30. self.assertEqual(profile.api_key, "")