Commit 6fe7cee6 authored by Felix Delattre's avatar Felix Delattre
Browse files

Introduced jsonrpc endpoint

parent a63b7b6e
Pipeline #25747 passed with stage
in 1 minute and 21 seconds
......@@ -30,4 +30,6 @@ tests:
stage: test
interruptible: true
script:
- export FLASK_APP=obmdataapi
- nohup flask run > log.txt 2>&1 &
- pytest tests
......@@ -17,17 +17,16 @@
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
import os
import sys
from flask import Flask
from flask import Flask, request, Response
from jsonrpcserver import method, dispatch
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
app = Flask(__name__)
def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
......@@ -47,16 +46,18 @@ def create_app(test_config=None):
# load the test config if passed in
app.config.update(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
@method
def ping():
return "pong"
app.add_url_rule("/", endpoint="index")
@app.route("/", methods=["POST"])
def index():
req = request.get_data().decode()
response = dispatch(req)
return Response(str(response), response.http_status, mimetype="application/json")
return app
if __name__ == "__main__":
create_app().run()
......@@ -21,6 +21,7 @@ from setuptools import setup, find_packages
tests_require = [
"Flask>=2.0.1",
"jsonrpcclient[requests]",
"pytest",
]
......@@ -35,7 +36,7 @@ setup(
license="AGPLv3+",
keywords="API",
author="Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ",
install_requires=["Flask>=2.0.1"],
install_requires=["Flask>=2.0.1", "jsonrpcserver"],
tests_require=tests_require,
extras_require={
"tests": tests_require,
......
......@@ -18,10 +18,11 @@
import logging
from jsonrpcclient import request
logger = logging.getLogger()
def test_index(client):
response = client.get("/")
assert b"Hello" in response.data
assert b"World" in response.data
def test_ping(client):
response = request("http://127.0.0.1:5000/", "ping").data.result
assert "pong" in response
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment