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.

53 lines
1.8 KiB

6 years ago
  1. from hc.api.models import Channel
  2. from hc.test import BaseTestCase
  3. class UnsubscribeEmailTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(UnsubscribeEmailTestCase, self).setUp()
  6. self.channel = Channel(user=self.alice, kind="email")
  7. self.channel.project = self.project
  8. self.channel.value = "[email protected]"
  9. self.channel.save()
  10. def test_it_works(self):
  11. token = self.channel.make_token()
  12. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  13. r = self.client.get(url)
  14. self.assertContains(r, "has been unsubscribed", status_code=200)
  15. q = Channel.objects.filter(code=self.channel.code)
  16. self.assertEqual(q.count(), 0)
  17. def test_it_checks_token(self):
  18. url = "/integrations/%s/unsub/faketoken/" % self.channel.code
  19. r = self.client.get(url)
  20. self.assertContains(r, "link you just used is incorrect",
  21. status_code=200)
  22. def test_it_checks_channel_kind(self):
  23. self.channel.kind = "webhook"
  24. self.channel.save()
  25. token = self.channel.make_token()
  26. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  27. r = self.client.get(url)
  28. self.assertEqual(r.status_code, 400)
  29. def test_post_works(self):
  30. token = self.channel.make_token()
  31. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  32. r = self.client.post(url)
  33. self.assertContains(r, "has been unsubscribed", status_code=200)
  34. def test_it_serves_confirmation_form(self):
  35. token = self.channel.make_token()
  36. url = "/integrations/%s/unsub/%s/?ask=1" % (self.channel.code, token)
  37. r = self.client.get(url)
  38. self.assertContains(r, "Please press the button below")