Add tests for invalid webhook and email addresses

This includes passing the type as not all upper case

Change-Id: I9d4690dc01bd3e911743f558cf2536222c944fcc
This commit is contained in:
Michael James Hoppal 2016-08-15 13:16:41 -06:00 committed by Michael James Hoppal
parent baed5c7828
commit 53c1220068
1 changed files with 116 additions and 0 deletions

View File

@ -48,6 +48,32 @@ class TestNotificationMethods(base.BaseMonascaTest):
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
def test_create_email_notification_method_with_lower_case_type(self):
notification = helpers.create_notification(name='lower case email notification',
type='email')
resp, response_body = self.monasca_client.create_notifications(
notification)
self.assertEqual(201, resp.status)
id = response_body['id']
resp, response_body = self.monasca_client.\
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
def test_create_email_notification_method_with_mixed_case_type(self):
notification = helpers.create_notification(name='mixed case email notification',
type='EmAil')
resp, response_body = self.monasca_client.create_notifications(
notification)
self.assertEqual(201, resp.status)
id = response_body['id']
resp, response_body = self.monasca_client.\
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
def test_create_notification_method_period_not_defined(self):
notification = helpers.create_notification(period=None)
@ -151,6 +177,96 @@ class TestNotificationMethods(base.BaseMonascaTest):
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_email_address(self):
notification = helpers.create_notification(address="name@")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_scheme_webhook(self):
notification = helpers.create_notification(type="WEBHOOK",
address="ftp://localhost")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_webhook_address(self):
notification = helpers.create_notification(type="WEBHOOK",
address="localhost:123")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
# The below tests are making sure that we accept passing in case insensitive types and that we still validate the
# address if the types are case insensitive
@test.attr(type="gate")
def test_create_notification_method_webhook_with_lower_case_type(self):
notification = helpers.create_notification(type='webhook',
address='http://mytest.test:4533')
resp, response_body = self.monasca_client.create_notifications(
notification)
self.assertEqual(201, resp.status)
id = response_body['id']
resp, response_body = self.monasca_client.\
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
def test_create_notification_method_webhook_with_mixed_case_type(self):
notification = helpers.create_notification(type='webHooK',
address='http://mytest.test:4533')
resp, response_body = self.monasca_client.create_notifications(
notification)
self.assertEqual(201, resp.status)
id = response_body['id']
resp, response_body = self.monasca_client.\
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_email_address_type_all_lower_case(self):
notification = helpers.create_notification(type="email",
address="name@")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_email_address_type_all_mixed_case(self):
notification = helpers.create_notification(type="EmAil",
address="name@")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_webhook_address_type_mixed_case(self):
notification = helpers.create_notification(type="WebHook",
address="localhost:123")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_webhook_address_type_lower_case(self):
notification = helpers.create_notification(type="webhook",
address="localhost:123")
self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity),
self.monasca_client.create_notifications,
notification)
@test.attr(type="gate")
@test.attr(type=['negative'])
def test_create_notification_method_with_invalid_type(self):