Пример #1
0
    def send_message(self, to_list, message):
        if not to_list:
            return

        try:
            to_list = self.filter_targets(to_list, message)
        except exception.Error:
            exception.log_warning()
            return

        # global monthly sms limit
        # TODO(termie): this means that no messages will be sent if any
        #               will go over the limit, is this really the behavior
        #               we want?
        for i in range(0, len(to_list)):
            throttle.throttle(None, "sms_global_send", month=settings.THROTTLE_SMS_GLOBAL_MONTH)

        message = encoding.smart_str(message)
        sms_service = component.best["sms_service"]
        sms_service.send_message(to_list, message)
Пример #2
0
  def test_basic(self):
    
    # lather
    # succeed the first two times, fail the third
    throttle.throttle(self.popular, 'test', minute=2)
    throttle.throttle(self.popular, 'test', minute=2)

    def _failPants():
      throttle.throttle(self.popular, 'test', minute=2)

    self.assertRaises(exception.ApiThrottled, _failPants)

    # rinse
    # magically advance time by a couple minutes
    o = test_util.override_clock(clock, seconds=120)
    
    # repeat
    # succeed the first two times, fail the third
    throttle.throttle(self.popular, 'test', minute=2)
    throttle.throttle(self.popular, 'test', minute=2)

    self.assertRaises(exception.ApiThrottled, _failPants)

    o.reset()
Пример #3
0
 def _failPants():
   throttle.throttle(self.popular, 'test', minute=2)