def test_validation_for_pagerduty(self): notification = {"name": "MyPagerduty", "type": "PAGERDUTY", "address": "nzH2LVRdMzun11HNC2oD"} try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
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.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
def test_validation_for_pagerduty(self): notification = { "name": "MyPagerduty", "type": "PAGERDUTY", "address": "nzH2LVRdMzun11HNC2oD" } try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
def test_validation_for_webhook(self): notification = { "name": "MyWebhook", "type": "WEBHOOK", "address": "http://somedomain.com" } try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
def test_validation_for_email(self): notification = { "name": "MyEmail", "type": "EMAIL", "address": "*****@*****.**" } try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
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.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
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.validate(notification) ex = ve.exception self.assertEqual("Address http:// does not have network location", ex.message)
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.validate(notification) ex = ve.exception self.assertEqual("Address //somedomain.com does not have URL scheme", ex.message)
def test_validation_exception_for_email(self): notification = { "name": "MyEmail", "type": "EMAIL", "address": "name@domain." } with self.assertRaises(schemas_exceptions.ValidationException) as ve: schemas_notifications.validate(notification) ex = ve.exception self.assertEqual("Address name@domain. is not of correct format", ex.message)
def _validate_notification(self, notification): """Validates the notification :param notification: An event object. :raises falcon.HTTPBadRequest """ try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException as ex: LOG.debug(ex) raise falcon.HTTPBadRequest('Bad request', ex.message)
def _validate_notification(self, notification): """Validates the notification :param notification: An event object. :raises falcon.HTTPBadRequest """ try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException as ex: LOG.debug(ex) raise falcon.HTTPBadRequest('Bad Request', ex.message)
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.validate(notification) ex = ve.exception self.assertEqual( "Address ftp://somedomain.com scheme is not in ['http', 'https']", ex.message)
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.validate(notification) ex = ve.exception self.assertEqual("Address ftp://somedomain.com scheme is not in ['http', 'https']", ex.message)
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.validate(notification) ex = ve.exception self.assertEqual("Address http:// does not have network location", ex.message)
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.validate(notification) ex = ve.exception self.assertEqual("Address //somedomain.com does not have URL scheme", ex.message)
def test_validation_for_webhook(self): notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://somedomain.com"} try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")
def test_validation_exception_for_email(self): notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain."} with self.assertRaises(schemas_exceptions.ValidationException) as ve: schemas_notifications.validate(notification) ex = ve.exception self.assertEqual("Address name@domain. is not of correct format", ex.message)
def test_validation_for_email(self): notification = {"name": "MyEmail", "type": "EMAIL", "address": "*****@*****.**"} try: schemas_notifications.validate(notification) except schemas_exceptions.ValidationException: self.fail("shouldn't happen")