handle rate limit

This commit is contained in:
Florian Bezannier
2021-11-11 23:32:54 +01:00
parent 0de9cfbb00
commit ef57d42425
4 changed files with 40 additions and 15 deletions
+13 -1
View File
@@ -22,7 +22,7 @@ from charge_control import ChargeControls
from test.utils import DATA_DIR, record_position, latitude, longitude, date0, date1, date2, date3, record_charging, \
vehicule_list, get_new_test_db, get_date, date4
from trip import Trips
from libs.utils import get_temp, parse_hour
from libs.utils import get_temp, parse_hour, rate_limit, RateLimitException
from web.db import Database
from web.figures import get_figures, get_battery_curve_fig, get_altitude_fig
from deepdiff import DeepDiff
@@ -253,6 +253,18 @@ class TestUnit(unittest.TestCase):
expected_res = [[2, 0, 0], [3, 14, 0], [0, 0, 2], [0, 30, 0]]
assert expected_res == [parse_hour(h) for h in ["PT2H", "PT3H14", "PT2S", "PT30M"]]
def test_rate_limit(self):
@rate_limit(2, 10)
def test_fct():
pass
test_fct()
test_fct()
try:
test_fct()
raise Exception("It should have raise RateLimitException")
except RateLimitException:
pass
if __name__ == '__main__':
my_logger(handler_level=os.environ.get("DEBUG_LEVEL", 20))