示例#1
0
文件: tests.py 项目: thi517/unisubs
 def test_get_headers(self):
     settings = TeamNotificationSettings(
         header1='Foo: bar',
         header2='  Foo2:  bar2',  # extra space should be trimmed
     )
     assert_equal(settings.get_headers(), {
         'Foo': 'bar',
         'Foo2': 'bar2',
     })
示例#2
0
 def test_send_notification(self):
     team = TeamFactory()
     settings = TeamNotificationSettings(team=team,
                                         type='mock-type',
                                         url='http://example.com/')
     handler = handlers.NotificationHandlerBase(settings)
     data = {'foo': 'bar'}
     handler.send_notification(data)
     # Note: do_http_post gets replaced with a mock function for the
     # unittests
     assert_equal(handlers.do_http_post.delay.call_args,
                  mock.call(team.id, settings.url, data,
                            settings.get_headers(), settings.auth_username,
                            settings.auth_password))
示例#3
0
文件: tests.py 项目: thi517/unisubs
 def test_extra_teams_lookup(self):
     team = TeamFactory()
     team_extra_1 = TeamFactory()
     team_extra_2 = TeamFactory()
     team_extra_3 = 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)
     assert_equal(TeamNotificationSettings.lookup(team), settings)
     assert_equal(TeamNotificationSettings.lookup(team_extra_1), settings)
     assert_equal(TeamNotificationSettings.lookup(team_extra_2), settings)
     assert_equal(TeamNotificationSettings.lookup(team_extra_3), None)
示例#4
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)
示例#5
0
文件: tests.py 项目: thi517/unisubs
 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)