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.

52 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(user=self.alice, 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",
  20. status_code=200)
  21. def test_it_checks_channel_kind(self):
  22. self.channel.kind = "webhook"
  23. self.channel.save()
  24. token = self.channel.make_token()
  25. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  26. r = self.client.get(url)
  27. self.assertEqual(r.status_code, 400)
  28. def test_post_works(self):
  29. token = self.channel.make_token()
  30. url = "/integrations/%s/unsub/%s/" % (self.channel.code, token)
  31. r = self.client.post(url)
  32. self.assertContains(r, "has been unsubscribed", status_code=200)
  33. def test_it_serves_confirmation_form(self):
  34. token = self.channel.make_token()
  35. url = "/integrations/%s/unsub/%s/?ask=1" % (self.channel.code, token)
  36. r = self.client.get(url)
  37. self.assertContains(r, "Please press the button below")