Skip to content

Commit 01d7877

Browse files
Merge pull request #91 from Geode-solutions/feat/before_teardown_request
feat(utils_functions): before & teardown requests function wrappers
2 parents 41db35c + 74bd569 commit 01d7877

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/opengeodeweb_back/utils_functions.py

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

3535

36+
def before_request(current_app):
37+
increment_request_counter(current_app)
38+
39+
40+
def teardown_request(current_app):
41+
decrement_request_counter(current_app)
42+
update_last_request_time(current_app)
43+
44+
3645
def kill_task(current_app):
3746
DESKTOP_APP = bool(current_app.config.get("DESKTOP_APP"))
3847
REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER"))

tests/test_utils_functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ 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+
2337
def test_versions():
2438
list_packages = [
2539
"OpenGeode-core",

0 commit comments

Comments
 (0)