File tree Expand file tree Collapse file tree 7 files changed +87
-53
lines changed Expand file tree Collapse file tree 7 files changed +87
-53
lines changed Original file line number Diff line number Diff line change 88
99from src .opengeodeweb_back .routes import blueprint_routes
1010from src .opengeodeweb_back .utils_functions import handle_exception
11+ from src .opengeodeweb_back import app_config
12+
13+
14+ print ("Hello World" , app_config )
1115
1216
1317""" Global config """
1721FLASK_DEBUG = True if os .environ .get ("FLASK_DEBUG" , default = None ) == "True" else False
1822
1923if FLASK_DEBUG == False :
20- app .config .from_object ("config .ProdConfig" )
24+ app .config .from_object (app_config .ProdConfig )
2125else :
22- app .config .from_object ("config .DevConfig" )
26+ app .config .from_object (app_config .DevConfig )
2327
2428
25- PORT = int (app .config .get ("PORT" ))
29+ print (f"{ app .config = } " , flush = True )
30+ PORT = int (app .config .get ("DEFAULT_PORT" ))
2631ORIGINS = app .config .get ("ORIGINS" )
2732SSL = app .config .get ("SSL" )
2833
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # Standard library imports
2+ import os
3+ import time
4+
5+ # Third party imports
6+ # Local application imports
7+
8+ class Config (object ):
9+ FLASK_DEBUG = os .environ .get ("FLASK_DEBUG" , default = False )
10+ DEFAULT_PORT = "5000"
11+ CORS_HEADERS = "Content-Type"
12+ UPLOAD_FOLDER = "./uploads"
13+ DESKTOP_APP = False
14+ REQUEST_COUNTER = 0
15+ LAST_REQUEST_TIME = time .time ()
16+ LAST_PING_TIME = time .time ()
17+
18+
19+ class ProdConfig (Config ):
20+ SSL = None
21+ ORIGINS = ""
22+ MINUTES_BEFORE_TIMEOUT = "1"
23+ SECONDS_BETWEEN_SHUTDOWNS = "10"
24+ DATA_FOLDER_PATH = "/data/"
25+
26+
27+ class DevConfig (Config ):
28+ SSL = None
29+ ORIGINS = "*"
30+ MINUTES_BEFORE_TIMEOUT = "1"
31+ SECONDS_BETWEEN_SHUTDOWNS = "10"
32+ DATA_FOLDER_PATH = "./data/"
Original file line number Diff line number Diff line change 1111
1212routes = flask .Blueprint ("routes" , __name__ )
1313
14- # @routes.before_request
15- # def before_request():
16- # if "ping" not in flask.request.path:
17- # utils_functions.increment_request_counter(flask.current_app)
18-
19- # @routes.teardown_request
20- # def teardown_request(exception):
21- # if "ping" not in flask.request.path:
22- # utils_functions.decrement_request_counter(flask.current_app)
23- # utils_functions.update_last_request_time(flask.current_app)
14+ @routes .before_request
15+ def before_request ():
16+ if "ping" not in flask .request .path :
17+ utils_functions .increment_request_counter (flask .current_app )
18+
19+ @routes .teardown_request
20+ def teardown_request (exception ):
21+ if "ping" not in flask .request .path :
22+ utils_functions .decrement_request_counter (flask .current_app )
23+ utils_functions .update_last_request_time (flask .current_app )
2424
2525schemas = os .path .join (os .path .dirname (__file__ ), "schemas" )
2626
Original file line number Diff line number Diff line change 1313# Local application imports
1414
1515def increment_request_counter (current_app ):
16- REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
17- REQUEST_COUNTER += 1
18- current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
16+ if "REQUEST_COUNTER" in current_app .config :
17+ REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
18+ REQUEST_COUNTER += 1
19+ current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
1920
2021def decrement_request_counter (current_app ):
21- REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
22- REQUEST_COUNTER -= 1
23- current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
22+ if "REQUEST_COUNTER" in current_app .config :
23+ REQUEST_COUNTER = int (current_app .config .get ("REQUEST_COUNTER" ))
24+ REQUEST_COUNTER -= 1
25+ current_app .config .update (REQUEST_COUNTER = REQUEST_COUNTER )
2426
2527def update_last_request_time (current_app ):
26- LAST_REQUEST_TIME = time .time ()
27- current_app .config .update (LAST_REQUEST_TIME = LAST_REQUEST_TIME )
28+ if "LAST_REQUEST_TIME" in current_app .config :
29+ LAST_REQUEST_TIME = time .time ()
30+ current_app .config .update (LAST_REQUEST_TIME = LAST_REQUEST_TIME )
2831
2932
3033def kill_task (current_app ):
Original file line number Diff line number Diff line change 11import pytest
22from app import app
3+ import time
34
45
56@pytest .fixture
67def client ():
78 app .config ["TESTING" ] = True
89 app .config ["SERVER_NAME" ] = "TEST"
9- app .config ["DATA_FOLDER" ] = "./data/"
10+ app .config ["DATA_FOLDER_PATH" ] = "./data/"
11+ app .config ["REQUEST_COUNTER" ] = 0
12+ app .config ["LAST_REQUEST_TIME" ] = time .time ()
1013 client = app .test_client ()
1114 client .headers = {"Content-type" : "application/json" , "Accept" : "application/json" }
1215 yield client
16+
17+ @pytest .fixture
18+ def app_context ():
19+ with app .app_context ():
20+ yield
Original file line number Diff line number Diff line change 1+ import flask
12from src .opengeodeweb_back import utils_functions
23
34
5+ def test_increment_request_counter (app_context ):
6+ assert flask .current_app .config .get ("REQUEST_COUNTER" ) == 0
7+ utils_functions .increment_request_counter (flask .current_app )
8+ assert flask .current_app .config .get ("REQUEST_COUNTER" ) == 1
9+
10+ def test_decrement_request_counter (app_context ):
11+ assert flask .current_app .config .get ("REQUEST_COUNTER" ) == 1
12+ utils_functions .decrement_request_counter (flask .current_app )
13+ assert flask .current_app .config .get ("REQUEST_COUNTER" ) == 0
14+
15+ def test_update_last_request_time (app_context ):
16+ LAST_REQUEST_TIME = flask .current_app .config .get ("LAST_REQUEST_TIME" )
17+ utils_functions .update_last_request_time (flask .current_app )
18+ assert flask .current_app .config .get ("LAST_REQUEST_TIME" ) >= LAST_REQUEST_TIME
19+
20+
421def test_versions ():
522 list_packages = [
623 "OpenGeode-core" ,
You can’t perform that action at this time.
0 commit comments