def test_01_increase_and_decrease(self): r = increase("hallo_counter1") self.assertEqual(r, 1) for x in range(1, 5): increase("hallo_counter1") counter = EventCounter.query.filter_by( counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 5) r = decrease("hallo_counter1") self.assertEqual(r, 4) for x in range(1, 8): decrease("hallo_counter1") counter = EventCounter.query.filter_by( counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 0) # Test reading counter r = read("hallo_counter1") self.assertEqual(r, 0) r = read("unknown counter") self.assertEqual(r, None)
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 test_02_decrease_beyond_zero(self): r = increase("hallo_counter2") self.assertEqual(r, 1) for x in range(1, 8): decrease("hallo_counter2", allow_negative=True) counter = EventCounter.query.filter_by(counter_name="hallo_counter2").first() self.assertEqual(counter.counter_value, -6)
def test_02_decrease_beyond_zero(self): r = increase("hallo_counter2") self.assertEqual(r, 1) for x in range(1, 8): decrease("hallo_counter2", allow_negative=True) counter = EventCounter.query.filter_by( counter_name="hallo_counter2").first() self.assertEqual(counter.counter_value, -6)
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 test_01_increase_and_decrease(self): r = increase("hallo_counter1") self.assertEqual(r, 1) for x in range(1, 5): increase("hallo_counter1") counter = EventCounter.query.filter_by(counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 5) r = decrease("hallo_counter1") self.assertEqual(r, 4) for x in range(1, 8): decrease("hallo_counter1") counter = EventCounter.query.filter_by(counter_name="hallo_counter1").first() self.assertEqual(counter.counter_value, 0) # Test reading counter r = read("hallo_counter1") self.assertEqual(r, 0) r = read("unknown counter") self.assertEqual(r, None)