Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
ADD - Heroku Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
RaenonX committed Oct 27, 2020
1 parent c3c1bdb commit f75102e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn main:app
4 changes: 3 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
EPQuestPostEdit,
EPQuestPostIDCheck
)
from .root import EPRootTest
from .user import EPUserLogin, EPUserLoginParam
13 changes: 13 additions & 0 deletions endpoints/root.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ class AppConfig:
# pylint: enable=fixme

if __name__ == "__main__":
app.run(debug=True)
app.run(threaded=True)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Web server
gunicorn

# Web framework
flask
flask-CORS
Expand Down
1 change: 1 addition & 0 deletions responses/body/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
QuestPostEditSuccessResponse, QuestPostEditFailedResponse,
QuestPostIDCheckResponse
)
from .root import RootTestResponse
from .user import UserLoginResponse
8 changes: 8 additions & 0 deletions responses/body/root.py
Original file line number Diff line number Diff line change
@@ -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."""
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.0
14 changes: 13 additions & 1 deletion tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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]


Expand Down

0 comments on commit f75102e

Please sign in to comment.