feat(api): add create_app factory for gunicorn entrypoint
This commit is contained in:
parent
74d496b2bc
commit
d32e4ba58b
@ -199,6 +199,17 @@ class CM_API:
|
|||||||
return thread
|
return thread
|
||||||
|
|
||||||
|
|
||||||
|
def create_app():
|
||||||
|
"""WSGI factory used by gunicorn (`app.cm_api:create_app()`).
|
||||||
|
|
||||||
|
Returns the Flask app object so gunicorn can serve it. The
|
||||||
|
surrounding CM_API class still owns route registration and DB
|
||||||
|
connection management — this just hands gunicorn the underlying
|
||||||
|
Flask instance.
|
||||||
|
"""
|
||||||
|
return CM_API().app
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
api = CM_API()
|
api = CM_API()
|
||||||
api.run(port = 3000)
|
api.run(port = 3000)
|
||||||
|
|||||||
@ -289,5 +289,24 @@ class CmdInteractiveTests(unittest.TestCase):
|
|||||||
self.assertIn("CM Bot CLI", out.getvalue())
|
self.assertIn("CM Bot CLI", out.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
class CreateAppFactoryTests(unittest.TestCase):
|
||||||
|
"""The gunicorn entrypoint loads `app.cm_api:create_app()`. The factory
|
||||||
|
must exist as a module-level callable that returns the Flask app
|
||||||
|
object — not the CM_API wrapper class."""
|
||||||
|
|
||||||
|
def test_create_app_returns_flask_instance(self):
|
||||||
|
from flask import Flask
|
||||||
|
from app.cm_api import create_app
|
||||||
|
|
||||||
|
wsgi = create_app()
|
||||||
|
self.assertIsInstance(wsgi, Flask)
|
||||||
|
|
||||||
|
def test_create_app_registers_acc_route(self):
|
||||||
|
from app.cm_api import create_app
|
||||||
|
wsgi = create_app()
|
||||||
|
rules = {r.rule for r in wsgi.url_map.iter_rules()}
|
||||||
|
self.assertIn("/acc/", rules)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user