diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..1945201 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn main:app diff --git a/api.py b/api.py index 5450eaf..9081198 100644 --- a/api.py +++ b/api.py @@ -2,7 +2,8 @@ from flask_restful import Api from endpoints import ( - EPUserLogin, EPQuestPostList, EPQuestPostGet, EPQuestPostPublish, EPQuestPostEdit, EPQuestPostIDCheck + EPRootTest, EPUserLogin, + EPQuestPostList, EPQuestPostGet, EPQuestPostPublish, EPQuestPostEdit, EPQuestPostIDCheck ) from responses import Error500Response @@ -26,6 +27,7 @@ def attach_api(app): def attach_endpoints(api_app): """Attach API endpoints to Flask app.""" + api_app.add_resource(EPRootTest, "/", endpoint="misc.root") api_app.add_resource(EPUserLogin, "/user/login", endpoint="user.login") api_app.add_resource(EPQuestPostList, "/posts/quest", endpoint="posts.quest.list") api_app.add_resource(EPQuestPostGet, "/posts/quest/get", endpoint="posts.quest.get") diff --git a/endpoints/__init__.py b/endpoints/__init__.py index c0f4261..9d67d17 100644 --- a/endpoints/__init__.py +++ b/endpoints/__init__.py @@ -6,4 +6,5 @@ EPQuestPostEdit, EPQuestPostIDCheck ) +from .root import EPRootTest from .user import EPUserLogin, EPUserLoginParam diff --git a/endpoints/root.py b/endpoints/root.py new file mode 100644 index 0000000..0a5c25d --- /dev/null +++ b/endpoints/root.py @@ -0,0 +1,13 @@ +"""Endpoints at the root. Serve as a status checking endpoint.""" +from responses import RootTestResponse, ResponseCodeCollection + +from .base import EndpointBase + +__all__ = ("EPRootTest",) + + +class EPRootTest(EndpointBase): + """Endpoint at the root path of the app.""" + + def get(self): # pylint: disable=no-self-use, missing-function-docstring + return RootTestResponse(ResponseCodeCollection.SUCCESS), 200 diff --git a/main.py b/main.py index 98cbac6..c8c6da7 100644 --- a/main.py +++ b/main.py @@ -37,4 +37,4 @@ class AppConfig: # pylint: enable=fixme if __name__ == "__main__": - app.run(debug=True) + app.run(threaded=True) diff --git a/requirements.txt b/requirements.txt index b6cef38..8676706 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ +# Web server +gunicorn + # Web framework flask flask-CORS diff --git a/responses/body/__init__.py b/responses/body/__init__.py index 7c6f21d..3e1c00d 100644 --- a/responses/body/__init__.py +++ b/responses/body/__init__.py @@ -8,4 +8,5 @@ QuestPostEditSuccessResponse, QuestPostEditFailedResponse, QuestPostIDCheckResponse ) +from .root import RootTestResponse from .user import UserLoginResponse diff --git a/responses/body/root.py b/responses/body/root.py new file mode 100644 index 0000000..7e9ea4d --- /dev/null +++ b/responses/body/root.py @@ -0,0 +1,8 @@ +"""Response body for the root endpoint.""" +from .basic import Response + +__all__ = ("RootTestResponse",) + + +class RootTestResponse(Response): + """Response body for the root endpoint.""" diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..f72c511 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.9.0 diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 9d2ab43..9dca44f 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -4,6 +4,17 @@ from responses import ResponseCodeCollection, QuestPostListResponseKey +def test_root(client): + r = client.get(url_for("misc.root")) + + assert r.status_code == 200 + + response = r.json + + assert response[QuestPostListResponseKey.CODE] == ResponseCodeCollection.SUCCESS.code + assert response[QuestPostListResponseKey.SUCCESS] + + def test_user_login(client): r = client.post( url_for("user.login"), @@ -17,7 +28,8 @@ def test_user_login(client): response = r.json - assert response[QuestPostListResponseKey.CODE] in (100, 101) + assert response[QuestPostListResponseKey.CODE] \ + in (ResponseCodeCollection.SUCCESS.code, ResponseCodeCollection.SUCCESS_NEW.code) assert response[QuestPostListResponseKey.SUCCESS]