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.

48 lines
1.6 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.save()
  12. self.n = Notification(owner=self.check, channel=self.channel)
  13. self.n.save()
  14. def test_it_works(self):
  15. url = "/api/v1/notifications/%s/bounce" % self.n.code
  16. r = self.client.post(url, "foo", content_type="text/plain")
  17. self.assertEqual(r.status_code, 200)
  18. self.n.refresh_from_db()
  19. self.assertEqual(self.n.error, "foo")
  20. def test_it_checks_ttl(self):
  21. self.n.created = self.n.created - timedelta(minutes=60)
  22. self.n.save()
  23. url = "/api/v1/notifications/%s/bounce" % self.n.code
  24. r = self.client.post(url, "foo", content_type="text/plain")
  25. self.assertEqual(r.status_code, 403)
  26. def test_it_handles_long_payload(self):
  27. url = "/api/v1/notifications/%s/bounce" % self.n.code
  28. payload = "A" * 500
  29. r = self.client.post(url, payload, content_type="text/plain")
  30. self.assertEqual(r.status_code, 200)
  31. def test_it_handles_missing_notification(self):
  32. fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
  33. url = "/api/v1/notifications/%s/bounce" % fake_code
  34. r = self.client.post(url, "", content_type="text/plain")
  35. self.assertEqual(r.status_code, 404)