示例#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")
示例#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")
示例#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")
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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")
示例#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")
示例#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")
示例#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)
示例#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")
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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")
示例#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)