def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.event_processors = {} self.user_notification.smtp_server = 'smtp_server' self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry
def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry self.notification_object = IonObject(RT.NotificationRequest, name="notification")
class UserNotificationTest(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry self.notification_object = IonObject(RT.NotificationRequest, name="notification") def test_create_one_user_notification(self): # mocks self.mock_rr_client.create.return_value = ('notification_id','rev') self.mock_rr_client.read.return_value = ('user_1_info') # execution notification_id = self.user_notification.create_notification(self.notification_object, 'user_1') # assertions self.assertEquals(notification_id,'notification_id') self.assertTrue(self.mock_rr_client.create.called) def test_update_user_notification(self): # mocks # execution # assertions pass def test_delete_user_notification(self): # mocks # execution # assertions pass
class UserNotificationTest(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.event_processors = {} self.user_notification.smtp_server = 'smtp_server' self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry @unittest.skip('Bad test - figure out how to patch out the greenlet start...') def test_create_one_user_notification(self): # mocks user = Mock() objects = [Mock()] user_id = 'user_id' self.mock_rr_client.create.return_value = ('notification_id','rev') self.mock_rr_client.read.return_value = user self.mock_rr_client.find_objects.return_value = objects, None delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest(name='Setting_email', origin = 'origin', origin_type = 'origin_type', event_type= 'event_type', event_subtype = 'event_subtype' , delivery_config= delivery_config) # execution notification_id = self.user_notification.create_notification(notification_request, user_id) # assertions #@todo - change to asserting called with! self.assertEquals('notification_id', notification_id) self.assertTrue(self.mock_rr_client.create.called) self.assertTrue(self.mock_rr_client.find_objects.return_value) def test_create_notification_validation(self): #------------------------------------------------------------------------------------------------------ # Test with no user provided #------------------------------------------------------------------------------------------------------ delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest(name='Setting_email', origin = 'origin', origin_type = 'origin_type', event_type= 'event_type', event_subtype = 'event_subtype' , delivery_config= delivery_config) with self.assertRaises(BadRequest) as br: notification_id = self.user_notification.create_notification(notification=notification_request) self.assertEquals( br.exception.message, '''User id not provided.''' ) #@todo when validation for subscription properties is added test it here... def test_create_email(self): #------------------------------------------------------------------------------------------------------ #Setup for the create email test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser', period=2323) #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals(notification_request.delivery_config.delivery['email'], 'email') self.assertEquals(notification_request.delivery_config.delivery['mode'], DeliveryMode.DIGEST) self.assertEquals(notification_request.delivery_config.delivery['period'], 2323) self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') #------------------------------------------------------------------------------------------------------ # Test with email missing... #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with user id missing - that is caught in the create_notification method #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', email='email', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser') notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, '') self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.type, NotificationType.EMAIL) #------------------------------------------------------------------------------------------------------ # Test with no mode - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', message_header='message_header', parser='parser') def test_create_sms(self): #------------------------------------------------------------------------------------------------------ #Setup for the create sms test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone='401-XXX-XXXX', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals(notification_request.delivery_config.delivery['phone_number'], '401-XXX-XXXX') self.assertEquals(notification_request.delivery_config.delivery['provider'], 'provider') self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') self.assertEquals(notification_request.type, NotificationType.SMS) #------------------------------------------------------------------------------------------------------ # Test with phone missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with provider missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone = '401-XXX-XXXX', message_header='message_header', parser='parser') def test_create_detection_filter(self): self.user_notification.create_notification = mocksignature(self.user_notification.create_notification) notification_id = 'an id' self.user_notification.create_notification.return_value = notification_id res = self.user_notification.create_detection_filter( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', filter_config = 'filter_config') self.assertEquals(res, notification_id) def test_update_user_notification(self): pass #@todo implement test for update def test_delete_user_notification(self): pass
class UserNotificationTest(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.event_processors = {} self.user_notification.smtp_server = 'smtp_server' self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry @unittest.skip( 'Bad test - figure out how to patch out the greenlet start...') def test_create_one_user_notification(self): # mocks user = Mock() objects = [Mock()] user_id = 'user_id' self.mock_rr_client.create.return_value = ('notification_id', 'rev') self.mock_rr_client.read.return_value = user self.mock_rr_client.find_objects.return_value = objects, None delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest( name='Setting_email', origin='origin', origin_type='origin_type', event_type='event_type', event_subtype='event_subtype', delivery_config=delivery_config) # execution notification_id = self.user_notification.create_notification( notification_request, user_id) # assertions #@todo - change to asserting called with! self.assertEquals('notification_id', notification_id) self.assertTrue(self.mock_rr_client.create.called) self.assertTrue(self.mock_rr_client.find_objects.return_value) def test_create_notification_validation(self): #------------------------------------------------------------------------------------------------------ # Test with no user provided #------------------------------------------------------------------------------------------------------ delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest( name='Setting_email', origin='origin', origin_type='origin_type', event_type='event_type', event_subtype='event_subtype', delivery_config=delivery_config) with self.assertRaises(BadRequest) as br: notification_id = self.user_notification.create_notification( notification=notification_request) self.assertEquals(br.exception.message, '''User id not provided.''') #@todo when validation for subscription properties is added test it here... def test_create_email(self): #------------------------------------------------------------------------------------------------------ #Setup for the create email test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', mode=DeliveryMode.DIGEST, message_header='message_header', parser='parser', period=2323) #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals( notification_request.delivery_config.delivery['email'], 'email') self.assertEquals( notification_request.delivery_config.delivery['mode'], DeliveryMode.DIGEST) self.assertEquals( notification_request.delivery_config.delivery['period'], 2323) self.assertEquals( notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals( notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') #------------------------------------------------------------------------------------------------------ # Test with email missing... #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', mode=DeliveryMode.DIGEST, message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with user id missing - that is caught in the create_notification method #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', email='email', mode=DeliveryMode.DIGEST, message_header='message_header', parser='parser') notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, '') self.assertEquals( notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals( notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.type, NotificationType.EMAIL) #------------------------------------------------------------------------------------------------------ # Test with no mode - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', message_header='message_header', parser='parser') def test_create_sms(self): #------------------------------------------------------------------------------------------------------ #Setup for the create sms test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_sms( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone='401-XXX-XXXX', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals( notification_request.delivery_config.delivery['phone_number'], '401-XXX-XXXX') self.assertEquals( notification_request.delivery_config.delivery['provider'], 'provider') self.assertEquals( notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals( notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') self.assertEquals(notification_request.type, NotificationType.SMS) #------------------------------------------------------------------------------------------------------ # Test with phone missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with provider missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone='401-XXX-XXXX', message_header='message_header', parser='parser') def test_create_detection_filter(self): self.user_notification.create_notification = mocksignature( self.user_notification.create_notification) notification_id = 'an id' self.user_notification.create_notification.return_value = notification_id res = self.user_notification.create_detection_filter( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', filter_config='filter_config') self.assertEquals(res, notification_id) def test_update_user_notification(self): pass #@todo implement test for update def test_delete_user_notification(self): pass
class UserNotificationTest(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock('user_notification') self.user_notification = UserNotificationService() self.user_notification.event_processors = {} self.user_notification.smtp_server = 'smtp_server' self.user_notification.clients = mock_clients self.mock_rr_client = self.user_notification.clients.resource_registry @unittest.skip('Bad test - figure out how to patch out the greenlet start...') def test_create_one_user_notification(self): # mocks user = Mock() objects = [Mock()] user_id = 'user_id' self.mock_rr_client.create.return_value = ('notification_id','rev') self.mock_rr_client.read.return_value = user self.mock_rr_client.find_objects.return_value = objects, None delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest(name='Setting_email', origin = 'origin', origin_type = 'origin_type', event_type= 'event_type', event_subtype = 'event_subtype' , delivery_config= delivery_config) # execution notification_id = self.user_notification.create_notification(notification_request, user_id) # assertions #@todo - change to asserting called with! self.assertEquals('notification_id', notification_id) self.assertTrue(self.mock_rr_client.create.called) self.assertTrue(self.mock_rr_client.find_objects.return_value) def test_create_notification_validation(self): #------------------------------------------------------------------------------------------------------ # Test with no user provided #------------------------------------------------------------------------------------------------------ delivery_config = DeliveryConfig() # Create a notification object notification_request = NotificationRequest(name='Setting_email', origin = 'origin', origin_type = 'origin_type', event_type= 'event_type', event_subtype = 'event_subtype' , delivery_config= delivery_config) with self.assertRaises(BadRequest) as br: notification_id = self.user_notification.create_notification(notification=notification_request) self.assertEquals( br.exception.message, '''User id not provided.''' ) #@todo when validation for subscription properties is added test it here... def test_create_email(self): #------------------------------------------------------------------------------------------------------ #Setup for the create email test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser', period=2323) #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals(notification_request.delivery_config.delivery['email'], 'email') self.assertEquals(notification_request.delivery_config.delivery['mode'], DeliveryMode.DIGEST) self.assertEquals(notification_request.delivery_config.delivery['period'], 2323) self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') #------------------------------------------------------------------------------------------------------ # Test with email missing... #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with user id missing - that is caught in the create_notification method #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', email='email', mode = DeliveryMode.DIGEST, message_header='message_header', parser='parser') notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, '') self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.type, NotificationType.EMAIL) #------------------------------------------------------------------------------------------------------ # Test with no mode - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_email(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', email='email', message_header='message_header', parser='parser') def test_match(self): parser = QueryLanguage() #------------------------------------------------------------------------------------------------------ # Check that when field is outside range (less than lower bound), match() returns false #------------------------------------------------------------------------------------------------------ field = 'voltage' lower_bound = 5 upper_bound = 10 instrument = 'instrument_1' search_string1 = "SEARCH '%s' VALUES FROM %s TO %s FROM '%s'"\ % (field, lower_bound, upper_bound, instrument) query = parser.parse(search_string1) event = ExampleDetectableEvent('TestEvent', voltage=4) self.assertFalse(QueryLanguage.match(event, query['query'])) #------------------------------------------------------------------------------------------------------ # Check that when field is outside range (is higher than upper bound), match() returns false #------------------------------------------------------------------------------------------------------ event = ExampleDetectableEvent('TestEvent', voltage=11) self.assertFalse(QueryLanguage.match(event, query['query'])) #------------------------------------------------------------------------------------------------------ # Check that when field is inside range, match() returns true #------------------------------------------------------------------------------------------------------ event = ExampleDetectableEvent('TestEvent', voltage=6) self.assertTrue(QueryLanguage.match(event, query['query'])) #------------------------------------------------------------------------------------------------------ # Check that when field is exactly of the value mentioned in a query, match() returns true #------------------------------------------------------------------------------------------------------ value = 15 search_string2 = "search '%s' is '%s' from '%s'" % (field, value, instrument) query = parser.parse(search_string2) event = ExampleDetectableEvent('TestEvent', voltage=15) self.assertTrue(QueryLanguage.match(event, query['query'])) #------------------------------------------------------------------------------------------------------ # Check that when value is not exactly what is mentioned in a query, match() returns false #------------------------------------------------------------------------------------------------------ event = ExampleDetectableEvent('TestEvent', voltage=14) self.assertFalse(QueryLanguage.match(event, query['query'])) def test_evaluate_condition(self): parser = QueryLanguage() #------------------------------------------------------------------------------------------------------ # Set up the search strings for different queries: # These include main query, a list of or queries and a list of and queries #------------------------------------------------------------------------------------------------------ field = 'voltage' instrument = 'instrument' #------------------------------------------------------------------------------------------------------ # main query #------------------------------------------------------------------------------------------------------ lower_bound = 5 upper_bound = 10 search_string1 = "SEARCH '%s' VALUES FROM %s TO %s FROM '%s'"\ % (field, lower_bound, upper_bound, instrument) #------------------------------------------------------------------------------------------------------ # or queries #------------------------------------------------------------------------------------------------------ value = 15 search_string2 = "or search '%s' is '%s' from '%s'" % (field, value, instrument) value = 17 search_string3 = "or search '%s' is '%s' from '%s'" % (field, value, instrument) lower_bound = 20 upper_bound = 30 search_string4 = "or SEARCH '%s' VALUES FROM %s TO %s FROM '%s'"\ % (field, lower_bound, upper_bound, instrument) #------------------------------------------------------------------------------------------------------ # and queries #------------------------------------------------------------------------------------------------------ lower_bound = 5 upper_bound = 6 search_string5 = "and SEARCH '%s' VALUES FROM %s TO %s FROM '%s'"\ % (field, lower_bound, upper_bound, instrument) lower_bound = 6 upper_bound = 7 search_string6 = "and SEARCH '%s' VALUES FROM %s TO %s FROM '%s'"\ % (field, lower_bound, upper_bound, instrument) #------------------------------------------------------------------------------------------------------ # Construct queries by parsing different search strings and test the evaluate_condition() # for each such complex query #------------------------------------------------------------------------------------------------------ search_string = search_string1+search_string2+search_string3+search_string4+search_string5+search_string6 query = parser.parse(search_string) # the main query as well as the 'and' queries pass for this case event = ExampleDetectableEvent('TestEvent', voltage=6) self.assertTrue(QueryLanguage.evaluate_condition(event, query)) # check true conditions. If any one of the 'or' conditions passes, evaluate_condition() # will return True event = ExampleDetectableEvent('TestEvent', voltage=15) self.assertTrue(QueryLanguage.evaluate_condition(event, query)) event = ExampleDetectableEvent('TestEvent', voltage=17) self.assertTrue(QueryLanguage.evaluate_condition(event, query)) event = ExampleDetectableEvent('TestEvent', voltage=25) self.assertTrue(QueryLanguage.evaluate_condition(event, query)) # check fail conditions arising from the 'and' condition (happens if any one of the 'and' conditions fail) # note: the 'and' queries are attached to the main query event = ExampleDetectableEvent('TestEvent', voltage=5) self.assertFalse(QueryLanguage.evaluate_condition(event, query)) event = ExampleDetectableEvent('TestEvent', voltage=7) self.assertFalse(QueryLanguage.evaluate_condition(event, query)) event = ExampleDetectableEvent('TestEvent', voltage=9) self.assertFalse(QueryLanguage.evaluate_condition(event, query)) def test_create_sms(self): #------------------------------------------------------------------------------------------------------ #Setup for the create sms test #------------------------------------------------------------------------------------------------------ cn = Mock() notification_id = 'an id' args_list = {} kwargs_list = {} def side_effect(*args, **kwargs): args_list.update(args) kwargs_list.update(kwargs) return notification_id cn.side_effect = side_effect self.user_notification.create_notification = cn #------------------------------------------------------------------------------------------------------ # Test with complete arguments #------------------------------------------------------------------------------------------------------ res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone='401-XXX-XXXX', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Assert results about complete arguments #------------------------------------------------------------------------------------------------------ self.assertEquals(res, notification_id) notification_request = kwargs_list['notification'] user_id = kwargs_list['user_id'] self.assertEquals(user_id, 'user_id') self.assertEquals(notification_request.delivery_config.delivery['phone_number'], '401-XXX-XXXX') self.assertEquals(notification_request.delivery_config.delivery['provider'], 'provider') self.assertEquals(notification_request.delivery_config.processing['message_header'], 'message_header') self.assertEquals(notification_request.delivery_config.processing['parsing'], 'parser') self.assertEquals(notification_request.event_type, 'event_type') self.assertEquals(notification_request.event_subtype, 'event_subtype') self.assertEquals(notification_request.origin, 'origin') self.assertEquals(notification_request.origin_type, 'origin_type') self.assertEquals(notification_request.type, NotificationType.SMS) #------------------------------------------------------------------------------------------------------ # Test with phone missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', provider='provider', message_header='message_header', parser='parser') #------------------------------------------------------------------------------------------------------ # Test with provider missing - what should that do? - bad request? #------------------------------------------------------------------------------------------------------ with self.assertRaises(BadRequest): res = self.user_notification.create_sms(event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', phone = '401-XXX-XXXX', message_header='message_header', parser='parser') def test_create_detection_filter(self): self.user_notification.create_notification = mocksignature(self.user_notification.create_notification) notification_id = 'an id' self.user_notification.create_notification.return_value = notification_id res = self.user_notification.create_detection_filter( event_type='event_type', event_subtype='event_subtype', origin='origin', origin_type='origin_type', user_id='user_id', filter_config = 'filter_config') self.assertEquals(res, notification_id) def test_update_user_notification(self): pass #@todo implement test for update def test_delete_user_notification(self): pass