Ejemplo n.º 1
0
 def test_extra_teams_lookup_duplicate_teams(self):
     team = TeamFactory()
     team_extra_1 = TeamFactory()
     team_extra_2 = TeamFactory()
     settings = TeamNotificationSettings(team=team,
                                         type='mock-type',
                                         url='http://example.com/')
     settings.save()
     settings.extra_teams.add(team_extra_1)
     settings.extra_teams.add(team_extra_2)
     settings.extra_teams.add(team_extra_1)
     assert_equal(TeamNotificationSettings.lookup(team), settings)
     assert_equal(TeamNotificationSettings.lookup(team_extra_1), settings)
     assert_equal(TeamNotificationSettings.lookup(team_extra_2), settings)
Ejemplo n.º 2
0
 def test_extra_teams_lookup_primary_first(self):
     team_1 = TeamFactory()
     team_2 = TeamFactory()
     team_3 = TeamFactory()
     settings_1 = TeamNotificationSettings(team=team_1,
                                           type='mock-type',
                                           url='http://example.com/')
     settings_2 = TeamNotificationSettings(team=team_2,
                                           type='mock-type',
                                           url='http://example.com/')
     settings_1.save()
     settings_2.save()
     settings_1.extra_teams.add(team_2)
     settings_1.extra_teams.add(team_3)
     assert_equal(TeamNotificationSettings.lookup(team_1), settings_1)
     assert_equal(TeamNotificationSettings.lookup(team_2), settings_2)
     assert_equal(TeamNotificationSettings.lookup(team_3), settings_1)
Ejemplo n.º 3
0
def call_event_handler(team, name, *args, **kwargs):
    """Call an event handler method

    This method looks up the NotificationHandlerBase subclass for a team,
    then calls on of it's event handler methods.
    """
    notification_setting = TeamNotificationSettings.lookup(team)
    if not notification_setting:
        return
    handler_class = _registry[notification_setting.type]
    handler = handler_class(notification_setting)
    method = getattr(handler, name)
    try:
        method(*args, **kwargs)
    except Exception:
        msg = "Error calling notification {} for {}".format(name, team)
        logger.error(msg, exc_info=True)