예제 #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)