Example #1
0
 def test_validation_for_pagerduty(self):
     notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
                     "address": "nzH2LVRdMzun11HNC2oD"}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #2
0
 def test_validation_for_pagerduty(self):
     notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
                     "address": "nzH2LVRdMzun11HNC2oD"}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #3
0
 def test_validation_for_webhook_non_zero_period(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://somedomain.com",
                     "period": 60}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #4
0
 def test_validation_exception_for_invalid_period_non_int(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": "zero"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Period zero must be a valid integer", ex.message)
Example #5
0
 def test_validation_exception_for_invalid_period_for_pagerduty(self):
     notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
                     "address": "nzH2LVRdMzun11HNC2oD", "period": 60}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Period can only be set with webhooks", ex.message)
Example #6
0
 def test_validation_exception_for_invalid_period_for_pagerduty(self):
     notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
                     "address": "nzH2LVRdMzun11HNC2oD", "period": 60}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Period can only be set with webhooks", ex.message)
Example #7
0
 def test_validation_exception_for_invalid_period_float(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": 1.2}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("expected int for dictionary value @ data['period']", ex.message)
Example #8
0
 def test_validation_exception_for_invalid_period_float(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": 1.2}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("expected int for dictionary value @ data['period']", ex.message)
Example #9
0
 def test_validation_exception_for_webhook_invalid_period(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": "10"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("10 is not a valid period", ex.message)
Example #10
0
 def test_validation_exception_for_invalid_period_non_int(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": "zero"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Period zero must be a valid integer", ex.message)
Example #11
0
 def test_validation_exception_for_invalid_email_address(self):
     notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     ex = ve.exception
     self.assertEqual("Address name@ is not of correct format", ex.message)
Example #12
0
 def test_validation_exception_for_webhook_invalid_period(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com",
                     "period": "10"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("10 is not a valid period, not in [0, 60]", ex.message)
Example #13
0
 def test_validation_for_webhook_non_zero_period(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://somedomain.com",
                     "period": 60}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #14
0
 def test_validation_for_max_name_address(self):
     name = "A" * 250
     self.assertEqual(250, len(name))
     address = "http://" + "A" * 502 + ".io"
     self.assertEqual(512, len(address))
     notification = {"name": name, "type": "WEBHOOK", "address": address}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #15
0
 def test_validation_for_max_name_address(self):
     name = "A" * 250
     self.assertEqual(250, len(name))
     address = "http://" + "A" * 502 + ".io"
     self.assertEqual(512, len(address))
     notification = {"name": name, "type": "WEBHOOK", "address": address}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #16
0
    def _parse_and_validate_notification(self, notification, require_all=False):
        """Validates the notification

        :param notification: An event object.
        :raises falcon.HTTPBadRequest
        """
        try:
            schemas_notifications.parse_and_validate(notification, self.valid_periods, require_all=require_all)
        except schemas_exceptions.ValidationException as ex:
            LOG.exception(ex)
            raise falcon.HTTPBadRequest('Bad Request', ex.message)
Example #17
0
 def test_validation_for_email(self):
     notification = {
         "name": "MyEmail",
         "type": "EMAIL",
         "address": "*****@*****.**"
     }
     try:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #18
0
    def _parse_and_validate_notification(self, notification, require_all=False):
        """Validates the notification

        :param notification: An event object.
        :raises falcon.HTTPBadRequest
        """
        try:
            schemas_notifications.parse_and_validate(notification, self.valid_periods, require_all=require_all)
        except schemas_exceptions.ValidationException as ex:
            LOG.debug(ex)
            raise falcon.HTTPBadRequest("Bad Request", ex.message)
Example #19
0
 def test_validation_exception_for_missing_period(self):
     notification = {
         "name": "MyEmail",
         "type": "EMAIL",
         "address": "name@domain."
     }
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods,
                                                  require_all=True)
     ex = ve.exception
     self.assertEqual("Period is required", ex.message)
Example #20
0
 def test_validation_exception_for_webhook_no_netloc(self):
     notification = {
         "name": "MyWebhook",
         "type": "WEBHOOK",
         "address": "http://"
     }
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     ex = ve.exception
     self.assertEqual("Address http:// does not have network location",
                      ex.message)
Example #21
0
 def test_validation_exception_for_webhook_no_scheme(self):
     notification = {
         "name": "MyWebhook",
         "type": "WEBHOOK",
         "address": "//somedomain.com"
     }
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     ex = ve.exception
     self.assertEqual("Address //somedomain.com does not have URL scheme",
                      ex.message)
Example #22
0
 def test_validation_exception_for_invalid_period_for_email(self):
     notification = {
         "name": "MyEmail",
         "type": "EMAIL",
         "address": "*****@*****.**",
         "period": "60"
     }
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     ex = ve.exception
     self.assertEqual("Period can only be set with webhooks", ex.message)
Example #23
0
 def test_validation_exception_for_webhook_invalid_scheme(self):
     notification = {
         "name": "MyWebhook",
         "type": "WEBHOOK",
         "address": "ftp://somedomain.com"
     }
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification,
                                                  valid_periods)
     ex = ve.exception
     self.assertEqual(
         "Address ftp://somedomain.com scheme is not in ['http', 'https']",
         ex.message)
Example #24
0
 def test_validation_exception_for_invalid_period_for_email(self):
     notification = {"name": "MyEmail", "type": "EMAIL", "address": "*****@*****.**", "period": "60"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Period can only be set with webhooks", ex.message)
Example #25
0
 def test_validation_exception_for_webhook_no_scheme(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "//somedomain.com"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Address //somedomain.com does not have URL scheme", ex.message)
Example #26
0
 def test_validation_exception_for_webhook_no_netloc(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Address http:// does not have network location", ex.message)
Example #27
0
 def test_validation_exception_for_webhook_invalid_scheme(self):
     notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "ftp://somedomain.com"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", ex.message)
Example #28
0
 def test_validation_exception_for_missing_period(self):
     notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain."}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods, require_all=True)
     ex = ve.exception
     self.assertEqual("Period is required", ex.message)
Example #29
0
 def test_validation_for_email(self):
     notification = {"name": "MyEmail", "type": "EMAIL", "address": "*****@*****.**"}
     try:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     except schemas_exceptions.ValidationException:
         self.fail("shouldn't happen")
Example #30
0
 def test_validation_exception_for_invalid_email_address(self):
     notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
     with self.assertRaises(schemas_exceptions.ValidationException) as ve:
         schemas_notifications.parse_and_validate(notification, valid_periods)
     ex = ve.exception
     self.assertEqual("Address name@ is not of correct format", ex.message)