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.8 KiB

  1. from datetime import timedelta
  2. from hc.api.models import Channel, Check, Notification
  3. from hc.test import BaseTestCase
  4. class BounceTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(BounceTestCase, self).setUp()
  7. self.check = Check(user=self.alice, status="up")
  8. self.check.save()
  9. self.channel = Channel(user=self.alice, kind="email")
  10. self.channel.value = "[email protected]"
  11. self.channel.email_verified = True
  12. self.channel.save()
  13. self.n = Notification(owner=self.check, channel=self.channel)
  14. self.n.save()
  15. def test_it_works(self):
  16. url = "/api/v1/notifications/%s/bounce" % self.n.code
  17. r = self.client.post(url, "foo", content_type="text/plain")
  18. self.assertEqual(r.status_code, 200)
  19. self.n.refresh_from_db()
  20. self.assertEqual(self.n.error, "foo")
  21. self.channel.refresh_from_db()
  22. self.assertFalse(self.channel.email_verified)
  23. def test_it_checks_ttl(self):
  24. self.n.created = self.n.created - timedelta(minutes=60)
  25. self.n.save()
  26. url = "/api/v1/notifications/%s/bounce" % self.n.code
  27. r = self.client.post(url, "foo", content_type="text/plain")
  28. self.assertEqual(r.status_code, 403)
  29. def test_it_handles_long_payload(self):
  30. url = "/api/v1/notifications/%s/bounce" % self.n.code
  31. payload = "A" * 500
  32. r = self.client.post(url, payload, content_type="text/plain")
  33. self.assertEqual(r.status_code, 200)
  34. def test_it_handles_missing_notification(self):
  35. fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
  36. url = "/api/v1/notifications/%s/bounce" % fake_code
  37. r = self.client.post(url, "", content_type="text/plain")
  38. self.assertEqual(r.status_code, 404)