Skip to content

Commit 63af3ae

Browse files
feat(utils_functions): before & teardown requests function wrappers
1 parent 048a0ab commit 63af3ae

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/opengeodeweb_back/utils_functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def update_last_request_time(current_app):
3232
LAST_REQUEST_TIME = time.time()
3333
current_app.config.update(LAST_REQUEST_TIME=LAST_REQUEST_TIME)
3434

35+
def before_request(current_app):
36+
increment_request_counter(current_app)
37+
38+
def teardown_request(current_app):
39+
decrement_request_counter(current_app)
40+
update_last_request_time(current_app)
3541

3642
def kill_task(current_app):
3743
DESKTOP_APP = bool(current_app.config.get("DESKTOP_APP"))

tests/test_utils_functions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ def test_update_last_request_time(app_context):
2020
assert flask.current_app.config.get("LAST_REQUEST_TIME") >= LAST_REQUEST_TIME
2121

2222

23+
def test_before_request(app_context):
24+
assert flask.current_app.config.get("REQUEST_COUNTER") == 0
25+
utils_functions.before_request(flask.current_app)
26+
assert flask.current_app.config.get("REQUEST_COUNTER") == 1
27+
28+
29+
def test_teardown_request(app_context):
30+
LAST_REQUEST_TIME = flask.current_app.config.get("LAST_REQUEST_TIME")
31+
assert flask.current_app.config.get("REQUEST_COUNTER") == 1
32+
utils_functions.teardown_request(flask.current_app)
33+
assert flask.current_app.config.get("REQUEST_COUNTER") == 0
34+
assert flask.current_app.config.get("LAST_REQUEST_TIME") >= LAST_REQUEST_TIME
35+
36+
37+
2338
def test_versions():
2439
list_packages = [
2540
"OpenGeode-core",

0 commit comments

Comments
 (0)