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

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. from django.contrib.auth.models import User
  2. from django.test import TestCase
  3. from hc.api.models import Channel
  4. class VerifyEmailTestCase(TestCase):
  5. def setUp(self):
  6. self.alice = User(username="alice")
  7. self.alice.set_password("password")
  8. self.alice.save()
  9. self.channel = Channel(user=self.alice, kind="email")
  10. self.channel.value = "[email protected]"
  11. self.channel.save()
  12. def test_it_works(self):
  13. token = self.channel.make_token()
  14. url = "/integrations/%s/verify/%s/" % (self.channel.code, token)
  15. r = self.client.post(url)
  16. assert r.status_code == 200, r.status_code
  17. channel = Channel.objects.get(code=self.channel.code)
  18. assert channel.email_verified
  19. def test_it_handles_bad_token(self):
  20. url = "/integrations/%s/verify/bad-token/" % self.channel.code
  21. r = self.client.post(url)
  22. assert r.status_code == 200, r.status_code
  23. channel = Channel.objects.get(code=self.channel.code)
  24. assert not channel.email_verified
  25. def test_missing_channel(self):
  26. # Valid UUID, and even valid token but there is no channel for it:
  27. code = "6837d6ec-fc08-4da5-a67f-08a9ed1ccf62"
  28. token = self.channel.make_token()
  29. url = "/integrations/%s/verify/%s/" % (code, token)
  30. r = self.client.post(url)
  31. assert r.status_code == 404