aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-05-28 23:54:34 -0700
committerGravatar MarkKoz <[email protected]>2019-05-29 02:50:41 -0700
commitfe00a9d72fd4c156db0a759e3cf7eac3fcf90d06 (patch)
tree2b1486dde2e8f72c04160bafab4861f28983302c
parentValidate request's input (diff)
Separate application instance from definition
This way, it is easier for tests to use the application because they can instead create their own instances after patching.
-rw-r--r--Pipfile2
-rw-r--r--snekbox/api/__init__.py3
-rw-r--r--snekbox/api/app.py7
-rw-r--r--snekbox/api/snekapi.py10
4 files changed, 16 insertions, 6 deletions
diff --git a/Pipfile b/Pipfile
index 6a0c5b4..72df21b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -30,7 +30,7 @@ lint = "flake8"
precommit = "pre-commit install"
test = "pytest tests --cov . --cov-report term-missing -v"
report = "pytest tests --cov . --cov-report=html"
-snekbox = "gunicorn -w 2 -b 0.0.0.0:8060 snekbox.api.app:api"
+snekbox = "gunicorn -w 2 -b 0.0.0.0:8060 snekbox.api.app"
buildbox = "docker build -t pythondiscord/snekbox:latest -f docker/Dockerfile ."
pushbox = "docker push pythondiscord/snekbox:latest"
buildboxbase = "docker build -t pythondiscord/snekbox-base:latest -f docker/base.Dockerfile ."
diff --git a/snekbox/api/__init__.py b/snekbox/api/__init__.py
index e69de29..d106f26 100644
--- a/snekbox/api/__init__.py
+++ b/snekbox/api/__init__.py
@@ -0,0 +1,3 @@
+from .snekapi import SnekAPI
+
+__all__ = ("SnekAPI",)
diff --git a/snekbox/api/app.py b/snekbox/api/app.py
index 25539af..c71e246 100644
--- a/snekbox/api/app.py
+++ b/snekbox/api/app.py
@@ -1,6 +1,3 @@
-import falcon
+from . import SnekAPI
-from .resources import EvalResource
-
-api = falcon.API()
-api.add_route("/eval", EvalResource())
+application = SnekAPI()
diff --git a/snekbox/api/snekapi.py b/snekbox/api/snekapi.py
new file mode 100644
index 0000000..d3afc91
--- /dev/null
+++ b/snekbox/api/snekapi.py
@@ -0,0 +1,10 @@
+import falcon
+
+from .resources import EvalResource
+
+
+class SnekAPI(falcon.API):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ self.add_route("/eval", EvalResource())