Example #1
0
    def setUp(self):
        super(BounceTestCase, self).setUp()

        self.check = Check(user=self.alice, status="up")
        self.check.save()

        self.channel = Channel(user=self.alice, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()
Example #2
0
    def setUp(self):
        super(BounceTestCase, self).setUp()

        self.check = Check(project=self.project, status="up")
        self.check.save()

        self.channel = Channel(project=self.project, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.email_verified = True
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()
Example #3
0
    def test_it_shows_disabled_email(self):
        check = Check(project=self.project, status="up")
        check.save()

        channel = Channel(project=self.project, kind="email")
        channel.value = "*****@*****.**"
        channel.save()

        n = Notification(owner=check, channel=channel, error="Invalid address")
        n.save()

        self.client.login(username="******", password="******")
        r = self.client.get("/integrations/")
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, "Disabled")
Example #4
0
    def setUp(self):
        super().setUp()

        self.check = Check(project=self.project, status="up")
        self.check.save()

        self.channel = Channel(project=self.project, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.email_verified = True
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()

        self.url = "/api/v1/notifications/%s/status" % self.n.code
Example #5
0
    def test_it_shows_pushover_notification(self):
        ch = Channel.objects.create(kind="po", project=self.project)

        Notification(owner=self.check, channel=ch, check_status="down").save()

        self.client.login(username="******", password="******")
        r = self.client.get(self.url)
        self.assertContains(r, "Sent a Pushover notification", status_code=200)
Example #6
0
    def test_it_shows_webhook_notification(self):
        ch = Channel(kind="webhook", project=self.project)
        ch.value = "foo/$NAME"
        ch.save()

        Notification(owner=self.check, channel=ch, check_status="down").save()

        self.client.login(username="******", password="******")
        r = self.client.get(self.url)
        self.assertContains(r, "Called webhook foo/$NAME", status_code=200)
Example #7
0
    def test_it_shows_email_notification(self):
        ch = Channel(kind="email", project=self.project)
        ch.value = json.dumps({"value": "*****@*****.**", "up": True, "down": True})
        ch.save()

        Notification(owner=self.check, channel=ch, check_status="down").save()

        self.client.login(username="******", password="******")
        r = self.client.get(self.url)
        self.assertContains(r, "Sent email to [email protected]", status_code=200)
Example #8
0
    def test_it_shows_pushover_notifications(self):
        ch = Channel(kind="po", user=self.alice)
        ch.save()

        Notification(owner=self.check, channel=ch, check_status="down").save()

        url = "/checks/%s/log/" % self.check.code

        self.client.login(username="******", password="******")
        r = self.client.get(url)
        self.assertContains(r, "Sent a Pushover notification", status_code=200)
Example #9
0
class BounceTestCase(BaseTestCase):
    def setUp(self):
        super(BounceTestCase, self).setUp()

        self.check = Check(user=self.alice, status="up")
        self.check.save()

        self.channel = Channel(user=self.alice, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()

    def test_it_works(self):
        url = "/api/v1/notifications/%s/bounce" % self.n.code
        r = self.client.post(url, "foo", content_type="text/plain")
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "foo")

    def test_it_checks_ttl(self):
        self.n.created = self.n.created - timedelta(minutes=60)
        self.n.save()

        url = "/api/v1/notifications/%s/bounce" % self.n.code
        r = self.client.post(url, "foo", content_type="text/plain")
        self.assertEqual(r.status_code, 400)

    def test_it_handles_long_payload(self):
        url = "/api/v1/notifications/%s/bounce" % self.n.code
        payload = "A" * 500
        r = self.client.post(url, payload, content_type="text/plain")
        self.assertEqual(r.status_code, 200)
Example #10
0
    def test_it_prunes(self):
        check = Check.objects.create(project=self.project, n_pings=101)
        Ping.objects.create(owner=check, n=101)
        Ping.objects.create(owner=check, n=1)

        n = Notification(owner=check)
        n.channel = Channel.objects.create(project=self.project, kind="email")
        n.check_status = "down"
        n.save()
        n.created = check.created - td(minutes=10)
        n.save()

        check.prune()

        self.assertTrue(Ping.objects.filter(n=101).exists())
        self.assertFalse(Ping.objects.filter(n=1).exists())

        self.assertEqual(Notification.objects.count(), 0)
Example #11
0
class BounceTestCase(BaseTestCase):
    def setUp(self):
        super(BounceTestCase, self).setUp()

        self.check = Check(project=self.project, status="up")
        self.check.save()

        self.channel = Channel(project=self.project, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.email_verified = True
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()

    def test_it_works(self):
        url = "/api/v1/notifications/%s/bounce" % self.n.code
        r = self.client.post(url, "foo", content_type="text/plain")
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "foo")

        self.channel.refresh_from_db()
        self.assertFalse(self.channel.email_verified)

    def test_it_checks_ttl(self):
        self.n.created = self.n.created - timedelta(minutes=60)
        self.n.save()

        url = "/api/v1/notifications/%s/bounce" % self.n.code
        r = self.client.post(url, "foo", content_type="text/plain")
        self.assertEqual(r.status_code, 403)

    def test_it_handles_long_payload(self):
        url = "/api/v1/notifications/%s/bounce" % self.n.code
        payload = "A" * 500
        r = self.client.post(url, payload, content_type="text/plain")
        self.assertEqual(r.status_code, 200)

    def test_it_handles_missing_notification(self):
        fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
        url = "/api/v1/notifications/%s/bounce" % fake_code
        r = self.client.post(url, "", content_type="text/plain")
        self.assertEqual(r.status_code, 404)

    def test_it_requires_post(self):
        url = "/api/v1/notifications/%s/bounce" % self.n.code
        r = self.client.get(url)
        self.assertEqual(r.status_code, 405)
Example #12
0
class NotificationStatusTestCase(BaseTestCase):
    def setUp(self):
        super().setUp()

        self.check = Check(project=self.project, status="up")
        self.check.save()

        self.channel = Channel(project=self.project, kind="email")
        self.channel.value = "*****@*****.**"
        self.channel.email_verified = True
        self.channel.save()

        self.n = Notification(owner=self.check, channel=self.channel)
        self.n.save()

        self.url = "/api/v1/notifications/%s/status" % self.n.code

    def test_it_handles_twilio_failed_status(self):
        r = self.csrf_client.post(self.url, {"MessageStatus": "failed"})
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "Delivery failed (status=failed).")

        self.channel.refresh_from_db()
        self.assertEqual(self.channel.last_error,
                         "Delivery failed (status=failed).")
        self.assertTrue(self.channel.email_verified)

    def test_it_handles_twilio_undelivered_status(self):
        r = self.csrf_client.post(self.url, {"MessageStatus": "undelivered"})
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "Delivery failed (status=undelivered).")

        self.channel.refresh_from_db()
        self.assertIn("status=undelivered", self.channel.last_error)

    def test_it_handles_twilio_delivered_status(self):
        r = self.csrf_client.post(self.url, {"MessageStatus": "delivered"})
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "")

        self.channel.refresh_from_db()
        self.assertEqual(self.channel.last_error, "")

    def test_it_checks_ttl(self):
        self.n.created = self.n.created - timedelta(minutes=61)
        self.n.save()

        r = self.csrf_client.post(self.url, {"MessageStatus": "failed"})
        self.assertEqual(r.status_code, 200)

        # The notification should not have the error field set:
        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "")

    def test_it_handles_missing_notification(self):
        fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
        url = f"/api/v1/notifications/{fake_code}/status"
        r = self.csrf_client.post(url, {"MessageStatus": "failed"})
        self.assertEqual(r.status_code, 200)

    def test_it_requires_post(self):
        r = self.csrf_client.get(self.url)
        self.assertEqual(r.status_code, 405)

    def test_it_handles_error_key(self):
        r = self.csrf_client.post(self.url, {"error": "Something went wrong."})
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "Something went wrong.")

        self.channel.refresh_from_db()
        self.assertEqual(self.channel.last_error, "Something went wrong.")
        self.assertTrue(self.channel.email_verified)

    def test_it_handles_mark_not_verified_key(self):
        payload = {"error": "Received complaint.", "mark_not_verified": "1"}

        r = self.csrf_client.post(self.url, payload)
        self.assertEqual(r.status_code, 200)

        self.channel.refresh_from_db()
        self.assertEqual(self.channel.last_error, "Received complaint.")
        self.assertFalse(self.channel.email_verified)

    def test_it_handles_twilio_call_status_failed(self):
        r = self.csrf_client.post(self.url, {"CallStatus": "failed"})
        self.assertEqual(r.status_code, 200)

        self.n.refresh_from_db()
        self.assertEqual(self.n.error, "Delivery failed (status=failed).")

        self.channel.refresh_from_db()
        self.assertEqual(self.channel.last_error,
                         "Delivery failed (status=failed).")
        self.assertTrue(self.channel.email_verified)