Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
OpenBuildingMap
data-api-server
Commits
6fe7cee6
Commit
6fe7cee6
authored
Jul 14, 2021
by
Felix Delattre
Browse files
Introduced jsonrpc endpoint
parent
a63b7b6e
Pipeline
#25747
passed with stage
in 1 minute and 21 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
6fe7cee6
...
...
@@ -30,4 +30,6 @@ tests:
stage
:
test
interruptible
:
true
script
:
-
export FLASK_APP=obmdataapi
-
nohup flask run > log.txt 2>&1 &
-
pytest tests
obmdataapi/__init__.py
View file @
6fe7cee6
...
...
@@ -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
()
setup.py
View file @
6fe7cee6
...
...
@@ -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
,
...
...
tests/test_obmdataapi.py
View file @
6fe7cee6
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment