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. from django.conf import settings
  6. class LoginTestCase(TestCase):
  7. def test_it_sends_link(self):
  8. check = Check()
  9. check.save()
  10. session = self.client.session
  11. session["welcome_code"] = str(check.code)
  12. session.save()
  13. form = {"email": "[email protected]"}
  14. r = self.client.post("/accounts/login/", form)
  15. assert r.status_code == 302
  16. # An user should have been created
  17. self.assertEqual(User.objects.count(), 1)
  18. # And email sent
  19. self.assertEqual(len(mail.outbox), 1)
  20. self.assertEqual(mail.outbox[0].subject, 'Log in to {0}'.format(getattr(settings, "SITE_NAME")))
  21. # And check should be associated with the new user
  22. check_again = Check.objects.get(code=check.code)
  23. assert check_again.user
  24. def test_it_pops_bad_link_from_session(self):
  25. self.client.session["bad_link"] = True
  26. self.client.get("/accounts/login/")
  27. assert "bad_link" not in self.client.session