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
6 years ago
  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", project=self.project)
  8. self.check.save()
  9. self.channel = Channel(user=self.alice, kind="email",
  10. project=self.project)
  11. self.channel.value = "[email protected]"
  12. self.channel.email_verified = True
  13. self.channel.save()
  14. self.n = Notification(owner=self.check, channel=self.channel)
  15. self.n.save()
  16. def test_it_works(self):
  17. url = "/api/v1/notifications/%s/bounce" % self.n.code
  18. r = self.client.post(url, "foo", content_type="text/plain")
  19. self.assertEqual(r.status_code, 200)
  20. self.n.refresh_from_db()
  21. self.assertEqual(self.n.error, "foo")
  22. self.channel.refresh_from_db()
  23. self.assertFalse(self.channel.email_verified)
  24. def test_it_checks_ttl(self):
  25. self.n.created = self.n.created - timedelta(minutes=60)
  26. self.n.save()
  27. url = "/api/v1/notifications/%s/bounce" % self.n.code
  28. r = self.client.post(url, "foo", content_type="text/plain")
  29. self.assertEqual(r.status_code, 403)
  30. def test_it_handles_long_payload(self):
  31. url = "/api/v1/notifications/%s/bounce" % self.n.code
  32. payload = "A" * 500
  33. r = self.client.post(url, payload, content_type="text/plain")
  34. self.assertEqual(r.status_code, 200)
  35. def test_it_handles_missing_notification(self):
  36. fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
  37. url = "/api/v1/notifications/%s/bounce" % fake_code
  38. r = self.client.post(url, "", content_type="text/plain")
  39. self.assertEqual(r.status_code, 404)