def do(self, action, options=None): """ This method executes the defined action in the given event. :param action: :param options: Contains the flask parameters g, request, response and the handler_def configuration :type options: dict :return: """ ret = True #g = options.get("g") handler_def = options.get("handler_def") handler_options = handler_def.get("options", {}) counter_name = handler_options.get("counter_name") if action == "increase_counter": increase(counter_name) log.debug(u"Increased the counter {0!s}.".format(counter_name)) elif action == "decrease_counter": allow_negative = handler_options.get("allow_negative_values") decrease(counter_name, allow_negative) log.debug(u"Decreased the counter {0!s}.".format(counter_name)) elif action == "reset_counter": reset(counter_name) log.debug(u"Reset the counter {0!s} to 0.".format(counter_name)) return ret
def do(self, action, options=None): """ This method executes the defined action in the given event. :param action: :param options: Contains the flask parameters g, request, response and the handler_def configuration :type options: dict :return: """ ret = True #g = options.get("g") handler_def = options.get("handler_def") handler_options = handler_def.get("options", {}) counter_name = handler_options.get("counter_name") if action == "increase_counter": r = increase(counter_name) log.debug(u"Increased the counter {0!s} to {1!s}.".format(counter_name, r)) elif action == "decrease_counter": allow_negative = handler_options.get("allow_negative_values") r = decrease(counter_name, allow_negative) log.debug(u"Decreased the counter {0!s} to {1!s}.".format(counter_name, r)) elif action == "reset_counter": reset(counter_name) log.debug(u"Reset the counter {0!s} to 0.".format(counter_name)) return ret
def test_03_decrease_and_reset(self): r = decrease("hallo_counter3", allow_negative=True) self.assertEqual(r, -1) reset("hallo_counter3") counter = EventCounter.query.filter_by(counter_name="hallo_counter3").first() self.assertEqual(counter.counter_value, 0)
def test_03_decrease_and_reset(self): r = decrease("hallo_counter3", allow_negative=True) self.assertEqual(r, -1) reset("hallo_counter3") counter = EventCounter.query.filter_by( counter_name="hallo_counter3").first() self.assertEqual(counter.counter_value, 0)
def do(self, params): event_counter = params.get("event_counter") stats_key = params.get("stats_key") reset_event_counter = params.get("reset_event_counter") counter_value = read(event_counter) if is_true(reset_event_counter) and counter_value: reset(event_counter) # now write the current value of the counter if counter_value is None: log.warning(u"Trying to create statistics of a counter_value '{0}', " u"that does not exist.".format(event_counter)) else: write_stats(stats_key, counter_value) return True
def test_04_reset_non_existing_counter(self): reset("hallo_counter4") counter = EventCounter.query.filter_by( counter_name="hallo_counter4").first() self.assertEqual(counter.counter_value, 0)
def test_04_reset_non_existing_counter(self): reset("hallo_counter4") counter = EventCounter.query.filter_by(counter_name="hallo_counter4").first() self.assertEqual(counter.counter_value, 0)