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.

55 lines
1.8 KiB

  1. from django.contrib.auth.models import User
  2. from django.core import mail
  3. from django.test import TestCase
  4. from django.test.utils import override_settings
  5. from hc.api.models import Check
  6. from django.conf import settings
  7. class SignupTestCase(TestCase):
  8. def test_it_sends_link(self):
  9. form = {"identity": "[email protected]"}
  10. r = self.client.post("/accounts/signup/", form)
  11. self.assertContains(r, "Account created")
  12. # An user should have been created
  13. self.assertEqual(User.objects.count(), 1)
  14. # And email sent
  15. self.assertEqual(len(mail.outbox), 1)
  16. subject = "Log in to %s" % settings.SITE_NAME
  17. self.assertEqual(mail.outbox[0].subject, subject)
  18. # And check should be associated with the new user
  19. check = Check.objects.get()
  20. self.assertEqual(check.name, "My First Check")
  21. @override_settings(REGISTRATION_OPEN=False)
  22. def test_it_obeys_registration_open(self):
  23. form = {"identity": "[email protected]"}
  24. r = self.client.post("/accounts/signup/", form)
  25. self.assertEqual(r.status_code, 403)
  26. def test_it_ignores_case(self):
  27. form = {"identity": "[email protected]"}
  28. self.client.post("/accounts/signup/", form)
  29. # There should be exactly one user:
  30. q = User.objects.filter(email="[email protected]")
  31. self.assertTrue(q.exists)
  32. def test_it_checks_for_existing_users(self):
  33. alice = User(username="alice", email="[email protected]")
  34. alice.save()
  35. form = {"identity": "[email protected]"}
  36. r = self.client.post("/accounts/signup/", form)
  37. self.assertContains(r, "already exists")
  38. def test_it_checks_syntax(self):
  39. form = {"identity": "alice at example org"}
  40. r = self.client.post("/accounts/signup/", form)
  41. self.assertContains(r, "Enter a valid email address")