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.

82 lines
2.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.accounts.models import Profile, Project
  6. from hc.api.models import Channel, Check
  7. from django.conf import settings
  8. class SignupTestCase(TestCase):
  9. def test_it_sends_link(self):
  10. form = {"identity": "[email protected]"}
  11. r = self.client.post("/accounts/signup/", form)
  12. self.assertContains(r, "Account created")
  13. self.assertIn("auto-login", r.cookies)
  14. # An user should have been created
  15. user = User.objects.get()
  16. # A profile should have been created
  17. profile = Profile.objects.get()
  18. self.assertEqual(profile.sms_limit, 5)
  19. self.assertEqual(profile.call_limit, 0)
  20. # And email sent
  21. self.assertEqual(len(mail.outbox), 1)
  22. subject = "Log in to %s" % settings.SITE_NAME
  23. self.assertEqual(mail.outbox[0].subject, subject)
  24. # A project should have been created
  25. project = Project.objects.get()
  26. self.assertEqual(project.owner, user)
  27. self.assertEqual(project.badge_key, user.username)
  28. # And check should be associated with the new user
  29. check = Check.objects.get()
  30. self.assertEqual(check.name, "My First Check")
  31. self.assertEqual(check.project, project)
  32. # A channel should have been created
  33. channel = Channel.objects.get()
  34. self.assertEqual(channel.project, project)
  35. @override_settings(USE_PAYMENTS=False)
  36. def test_it_sets_high_limits(self):
  37. form = {"identity": "[email protected]"}
  38. self.client.post("/accounts/signup/", form)
  39. # A profile should have been created
  40. profile = Profile.objects.get()
  41. self.assertEqual(profile.sms_limit, 500)
  42. self.assertEqual(profile.call_limit, 500)
  43. @override_settings(REGISTRATION_OPEN=False)
  44. def test_it_obeys_registration_open(self):
  45. form = {"identity": "[email protected]"}
  46. r = self.client.post("/accounts/signup/", form)
  47. self.assertEqual(r.status_code, 403)
  48. def test_it_ignores_case(self):
  49. form = {"identity": "[email protected]"}
  50. self.client.post("/accounts/signup/", form)
  51. # There should be exactly one user:
  52. q = User.objects.filter(email="[email protected]")
  53. self.assertTrue(q.exists)
  54. def test_it_checks_for_existing_users(self):
  55. alice = User(username="alice", email="[email protected]")
  56. alice.save()
  57. form = {"identity": "[email protected]"}
  58. r = self.client.post("/accounts/signup/", form)
  59. self.assertContains(r, "already exists")
  60. def test_it_checks_syntax(self):
  61. form = {"identity": "alice at example org"}
  62. r = self.client.post("/accounts/signup/", form)
  63. self.assertContains(r, "Enter a valid email address")