mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Moves route assignment to API constructor so it can be properly tested
This commit is contained in:
24
teos/api.py
24
teos/api.py
@@ -82,6 +82,18 @@ class API:
|
|||||||
self.inspector = inspector
|
self.inspector = inspector
|
||||||
self.watcher = watcher
|
self.watcher = watcher
|
||||||
self.gatekeeper = gatekeeper
|
self.gatekeeper = gatekeeper
|
||||||
|
self.app = app
|
||||||
|
|
||||||
|
# Adds all the routes to the functions listed above.
|
||||||
|
routes = {
|
||||||
|
"/register": (self.register, ["POST"]),
|
||||||
|
"/add_appointment": (self.add_appointment, ["POST"]),
|
||||||
|
"/get_appointment": (self.get_appointment, ["POST"]),
|
||||||
|
"/get_all_appointments": (self.get_all_appointments, ["GET"]),
|
||||||
|
}
|
||||||
|
|
||||||
|
for url, params in routes.items():
|
||||||
|
app.add_url_rule(url, view_func=params[0], methods=params[1])
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
"""
|
"""
|
||||||
@@ -322,19 +334,9 @@ class API:
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
This function starts the Flask server used to run the API. Adds all the routes to the functions listed above.
|
This function starts the Flask server used to run the API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
routes = {
|
|
||||||
"/register": (self.register, ["POST"]),
|
|
||||||
"/add_appointment": (self.add_appointment, ["POST"]),
|
|
||||||
"/get_appointment": (self.get_appointment, ["POST"]),
|
|
||||||
"/get_all_appointments": (self.get_all_appointments, ["GET"]),
|
|
||||||
}
|
|
||||||
|
|
||||||
for url, params in routes.items():
|
|
||||||
app.add_url_rule(url, view_func=params[0], methods=params[1])
|
|
||||||
|
|
||||||
# Setting Flask log to ERROR only so it does not mess with our logging. Also disabling flask initial messages
|
# Setting Flask log to ERROR only so it does not mess with our logging. Also disabling flask initial messages
|
||||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
||||||
os.environ["WERKZEUG_RUN_MAIN"] = "true"
|
os.environ["WERKZEUG_RUN_MAIN"] = "true"
|
||||||
|
|||||||
Reference in New Issue
Block a user