From 354724075e1160da3c4bea2751d0d1cf06945e4d Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Mon, 30 Mar 2020 22:14:10 +0200 Subject: [PATCH] Moves route assignment to API constructor so it can be properly tested --- teos/api.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/teos/api.py b/teos/api.py index 06c53ae..17cd45b 100644 --- a/teos/api.py +++ b/teos/api.py @@ -82,6 +82,18 @@ class API: self.inspector = inspector self.watcher = watcher 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): """ @@ -322,19 +334,9 @@ class API: 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 logging.getLogger("werkzeug").setLevel(logging.ERROR) os.environ["WERKZEUG_RUN_MAIN"] = "true"