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.

50 lines
1.7 KiB

  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(project=self.project, kind="email")
  7. self.channel.value = "[email protected]"
  8. self.channel.save()
  9. def test_it_works(self):
  10. token = self.channel.make_token()
  11. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  12. r = self.client.get(url)
  13. self.assertContains(r, "has been unsubscribed", status_code=200)
  14. q = Channel.objects.filter(code=self.channel.code)
  15. self.assertEqual(q.count(), 0)
  16. def test_it_checks_token(self):
  17. url = "/integrations/%s/unsub/faketoken/" % self.channel.code
  18. r = self.client.get(url)
  19. self.assertContains(r, "link you just used is incorrect", status_code=200)
  20. def test_it_checks_channel_kind(self):
  21. self.channel.kind = "webhook"
  22. self.channel.save()
  23. token = self.channel.make_token()
  24. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  25. r = self.client.get(url)
  26. self.assertEqual(r.status_code, 400)
  27. def test_post_works(self):
  28. token = self.channel.make_token()
  29. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  30. r = self.client.post(url)
  31. self.assertContains(r, "has been unsubscribed", status_code=200)
  32. def test_it_serves_confirmation_form(self):
  33. token = self.channel.make_token()
  34. url = "/integrations/%s/unsub/%s/?ask=1" % (self.channel.code, token)
  35. r = self.client.get(url)
  36. self.assertContains(r, "Please press the button below")