Permalink
Browse files

Merge pull request #391 from swarbhanu/fix_uns_for_ux

UNS is now working fine with UX
  • Loading branch information...
daf committed Dec 6, 2012
2 parents a36f493 + d13ee72 commit d44e61c55ea2c0d7fa607008bad82474cde34b26
@@ -38,7 +38,6 @@ def on_start(self):
self.reverse_user_info = None
self.user_info = None
- self.smtp_client = setting_up_smtp_client()
#------------------------------------------------------------------------------------
# Start by loading the user info and reverse user info dictionaries
@@ -99,19 +98,19 @@ def process_event(self, msg, headers):
user_ids = []
if self.reverse_user_info:
+ log.debug("Notification worker checking for users interested in %s" % msg.type_)
user_ids = check_user_notification_interest(event = msg, reverse_user_info = self.reverse_user_info)
- log.debug("Type of event received by notification worker: %s" % msg.type_)
- log.debug("Event received by notification worker: %s" % msg)
log.debug("Notification worker deduced the following users were interested in the event: %s, event_type: %s, origin: %s" % (user_ids, msg.type_, msg.origin ))
-
#------------------------------------------------------------------------------------
# Send email to the users
#------------------------------------------------------------------------------------
for user_id in user_ids:
msg_recipient = self.user_info[user_id]['user_contact'].email
+ self.smtp_client = setting_up_smtp_client()
send_email(message = msg, msg_recipient = msg_recipient, smtp_client = self.smtp_client )
+ self.smtp_client.quit()
def on_stop(self):
# close subscribers safely
@@ -81,7 +81,7 @@ def setUp(self):
self.user_notification.smtp_server = 'smtp_server'
self.user_notification.smtp_client = 'smtp_client'
self.user_notification.event_publisher = EventPublisher()
- self.user_notification.event_processor = EmailEventProcessor('an_smtp_client')
+ self.user_notification.event_processor = EmailEventProcessor()
def test_create_notification(self):
'''
@@ -101,7 +101,7 @@ def test_create_notification(self):
self.user_notification.notifications = {}
self.user_notification.event_processor.add_notification_for_user = mocksignature(self.user_notification.event_processor.add_notification_for_user)
-
+ self.user_notification.update_user_info_dictionary = mocksignature(self.user_notification.update_user_info_dictionary)
self.user_notification.event_publisher.publish_event = mocksignature(self.user_notification.event_publisher.publish_event)
self.user_notification._notification_in_notifications = mocksignature(self.user_notification._notification_in_notifications)
@@ -219,8 +219,8 @@ def test_delete_user_notification(self):
notification_id = 'notification_id_1'
- self.user_notification.event_processor.stop_notification_subscriber = mocksignature(self.user_notification.event_processor.stop_notification_subscriber)
self.user_notification.event_publisher.publish_event = mocksignature(self.user_notification.event_publisher.publish_event)
+ self.user_notification.user_info = {}
#-------------------------------------------------------------------------------------------------------------------
# Create a notification object
@@ -327,8 +327,6 @@ def test_pub_reload_user_info_event(self):
Test that the publishing of reload user info event occurs every time a create, update
or delete notification occurs.
'''
- proc1 = self.container.proc_manager.procs_by_name['user_notification']
-
#--------------------------------------------------------------------------------------
# Create subscribers for reload events
#--------------------------------------------------------------------------------------
@@ -492,23 +490,23 @@ def test_user_info_UNS(self):
notification_request_2 = self.rrc.read(notification_id_2)
# check user_info dictionary
- self.assertEquals(proc1.event_processor.user_info[user_id_1]['user_contact'].email, 'user_1@gmail.com' )
- self.assertEquals(proc1.event_processor.user_info[user_id_1]['notifications'], [notification_request_correct])
+ self.assertEquals(proc1.user_info[user_id_1]['user_contact'].email, 'user_1@gmail.com' )
+ self.assertEquals(proc1.user_info[user_id_1]['notifications'], [notification_request_correct])
- self.assertEquals(proc1.event_processor.user_info[user_id_2]['user_contact'].email, 'user_2@gmail.com' )
- self.assertEquals(proc1.event_processor.user_info[user_id_2]['notifications'], [notification_request_2])
+ self.assertEquals(proc1.user_info[user_id_2]['user_contact'].email, 'user_2@gmail.com' )
+ self.assertEquals(proc1.user_info[user_id_2]['notifications'], [notification_request_2])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin']['instrument_1'], [user_id_1])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin']['instrument_2'], [user_id_2])
+ self.assertEquals(proc1.reverse_user_info['event_origin']['instrument_1'], [user_id_1])
+ self.assertEquals(proc1.reverse_user_info['event_origin']['instrument_2'], [user_id_2])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_type']['ResourceLifecycleEvent'], [user_id_1])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_type']['DetectionEvent'], [user_id_2])
+ self.assertEquals(proc1.reverse_user_info['event_type']['ResourceLifecycleEvent'], [user_id_1])
+ self.assertEquals(proc1.reverse_user_info['event_type']['DetectionEvent'], [user_id_2])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_subtype']['subtype_1'], [user_id_1])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_subtype']['subtype_2'], [user_id_2])
+ self.assertEquals(proc1.reverse_user_info['event_subtype']['subtype_1'], [user_id_1])
+ self.assertEquals(proc1.reverse_user_info['event_subtype']['subtype_2'], [user_id_2])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin_type']['type_1'], [user_id_1])
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin_type']['type_2'], [user_id_2])
+ self.assertEquals(proc1.reverse_user_info['event_origin_type']['type_1'], [user_id_1])
+ self.assertEquals(proc1.reverse_user_info['event_origin_type']['type_2'], [user_id_2])
log.debug("The event processor received the notification topics after a create_notification() for two users")
log.debug("Verified that the event processor correctly updated its user info dictionaries")
@@ -519,21 +517,29 @@ def test_user_info_UNS(self):
self.unsc.create_notification(notification=notification_request_2, user_id=user_id_1)
# Check in UNS ------------>
- self.assertEquals(proc1.event_processor.user_info[user_id_1]['user_contact'].email, 'user_1@gmail.com' )
+ self.assertEquals(proc1.user_info[user_id_1]['user_contact'].email, 'user_1@gmail.com' )
+
+ notifications = proc1.user_info[user_id_1]['notifications']
+ origins = []
+ event_types = []
+ for notific in notifications:
+ origins.append(notific.origin)
+ event_types.append(notific.event_type)
- self.assertEquals(proc1.event_processor.user_info[user_id_1]['notifications'], [notification_request_correct, notification_request_2])
+ self.assertEquals(set(origins), set(['instrument_1', 'instrument_2']))
+ self.assertEquals(set(event_types), set(['ResourceLifecycleEvent', 'DetectionEvent']))
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin']['instrument_1'], [user_id_1])
- self.assertEquals(set(proc1.event_processor.reverse_user_info['event_origin']['instrument_2']), set([user_id_2, user_id_1]))
+ self.assertEquals(proc1.reverse_user_info['event_origin']['instrument_1'], [user_id_1])
+ self.assertEquals(set(proc1.reverse_user_info['event_origin']['instrument_2']), set([user_id_2, user_id_1]))
- self.assertEquals(proc1.event_processor.reverse_user_info['event_type']['ResourceLifecycleEvent'], [user_id_1])
- self.assertEquals(set(proc1.event_processor.reverse_user_info['event_type']['DetectionEvent']), set([user_id_2, user_id_1]))
+ self.assertEquals(proc1.reverse_user_info['event_type']['ResourceLifecycleEvent'], [user_id_1])
+ self.assertEquals(set(proc1.reverse_user_info['event_type']['DetectionEvent']), set([user_id_2, user_id_1]))
- self.assertEquals(proc1.event_processor.reverse_user_info['event_subtype']['subtype_1'], [user_id_1])
- self.assertEquals(set(proc1.event_processor.reverse_user_info['event_subtype']['subtype_2']), set([user_id_2, user_id_1]))
+ self.assertEquals(proc1.reverse_user_info['event_subtype']['subtype_1'], [user_id_1])
+ self.assertEquals(set(proc1.reverse_user_info['event_subtype']['subtype_2']), set([user_id_2, user_id_1]))
- self.assertEquals(proc1.event_processor.reverse_user_info['event_origin_type']['type_1'], [user_id_1])
- self.assertEquals(set(proc1.event_processor.reverse_user_info['event_origin_type']['type_2']), set([user_id_2, user_id_1]))
+ self.assertEquals(proc1.reverse_user_info['event_origin_type']['type_1'], [user_id_1])
+ self.assertEquals(set(proc1.reverse_user_info['event_origin_type']['type_2']), set([user_id_2, user_id_1]))
log.debug("The event processor received the notification topics after another create_notification() for the first user")
log.debug("Verified that the event processor correctly updated its user info dictionaries")
@@ -552,19 +558,19 @@ def test_user_info_UNS(self):
notification_request_correct = self.rrc.read(notification_id_1)
# check that the updated notification is in the user info dictionary
- self.assertTrue(notification_request_correct in proc1.event_processor.user_info[user_id_1]['notifications'] )
+ self.assertTrue(notification_request_correct in proc1.user_info[user_id_1]['notifications'] )
# check that the notifications in the user info dictionary got updated
update_worked = False
- for notification in proc1.event_processor.user_info[user_id_1]['notifications']:
+ for notification in proc1.user_info[user_id_1]['notifications']:
if notification.origin == "newly_changed_instrument":
update_worked = True
break
self.assertTrue(update_worked)
# reverse_user_info
- self.assertTrue(user_id_1 in proc1.event_processor.reverse_user_info['event_origin']["newly_changed_instrument"])
+ self.assertTrue(user_id_1 in proc1.reverse_user_info['event_origin']["newly_changed_instrument"])
log.debug("Verified that the event processor correctly updated its user info dictionaries after an update_notification()")
@@ -681,8 +687,24 @@ def received_reload(msg, headers):
notification_request_2 = self.rrc.read(notification_id_2)
+ #--------------------------------------------------------------------------------------------------------------------------
+ # Check that the two notifications created for the same user got properly reloaded in the user_info dictionaries of the workers
+ #--------------------------------------------------------------------------------------------------------------------------
+ notifications = reloaded_user_info[user_id]['notifications']
+ origins = []
+ event_types = []
+ for notific in notifications:
+ origins.append(notific.origin)
+ event_types.append(notific.event_type)
+
+ shouldbe_origins = []
+ shouldbe_event_types = []
+ for notific in [notification_request_correct, notification_request_2]:
+ shouldbe_origins.append(notific.origin)
+ shouldbe_event_types.append(notific.event_type)
- self.assertEquals(reloaded_user_info[user_id]['notifications'], [notification_request_correct, notification_request_2] )
+ self.assertEquals(set(origins), set(shouldbe_origins))
+ self.assertEquals(set(event_types), set(shouldbe_event_types))
self.assertEquals(reloaded_reverse_user_info['event_origin']['instrument_1'], [user_id] )
self.assertEquals(reloaded_reverse_user_info['event_origin']['instrument_2'], [user_id] )
@@ -1375,7 +1397,7 @@ def cleanup_timer(scheduler, schedule_id):
ar_1 = gevent.event.AsyncResult()
ar_2 = gevent.event.AsyncResult()
- def send_email(events_for_message, user_id):
+ def send_email(events_for_message, user_id, *args, **kwargs):
log.warning("(in asyncresult) events_for_message: %s" % events_for_message)
ar_1.set(events_for_message)
ar_2.set(user_id)
Oops, something went wrong.

0 comments on commit d44e61c

Please sign in to comment.