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.

36 lines
1.1 KiB

  1. from django.contrib.auth.models import User
  2. from django.core import mail
  3. from django.test import TestCase
  4. from hc.api.models import Check
  5. class LoginTestCase(TestCase):
  6. def test_it_sends_link(self):
  7. check = Check()
  8. check.save()
  9. session = self.client.session
  10. session["welcome_code"] = str(check.code)
  11. session.save()
  12. form = {"email": "[email protected]"}
  13. r = self.client.post("/accounts/login/", form)
  14. assert r.status_code == 302
  15. # An user should have been created
  16. self.assertEqual(User.objects.count(), 1)
  17. # And email sent
  18. self.assertEqual(len(mail.outbox), 1)
  19. self.assertEqual(mail.outbox[0].subject, 'Log in to healthchecks.io')
  20. # And check should be associated with the new user
  21. check_again = Check.objects.get(code=check.code)
  22. assert check_again.user
  23. def test_it_pops_bad_link_from_session(self):
  24. self.client.session["bad_link"] = True
  25. self.client.get("/accounts/login/")
  26. assert "bad_link" not in self.client.session