Commit a63b7b6e authored by Felix Delattre's avatar Felix Delattre
Browse files

Added very basic flask

parent 75631026
Pipeline #25668 passed with stage
in 1 minute and 43 seconds
......@@ -16,6 +16,7 @@ Requirements
------------
* python >= 3.7
* Flask >= 2.0.1
Installation
------------
......@@ -30,7 +31,7 @@ Development and linting dependencies can be installed with:
pip3 install .[tests]
pip3 install .[linters]
We use `black` and `flake8` for consistent code style and `pylint` for general linting. Project linting comes pre-defined in `.pre-commit` to be used in `https://pre-commit.com/`_.
We use `black` and `flake8` for consistent code style and `pylint` for general linting. Project linting comes pre-defined in `.pre-commit` to be used in `pre-commit <https://pre-commit.com/>`_.
pre-commit install
......
......@@ -17,19 +17,46 @@
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
import os
import sys
from flask import Flask
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
app = Flask(__name__)
def main():
def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
logger.info("obmapidata has started")
sys.exit()
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
# a default secret that should be overridden by instance config
SECRET_KEY="dev"
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
else:
# 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>"
app.add_url_rule("/", endpoint="index")
if __name__ == "__main__":
main()
return app
#!/usr/bin/env python3
# Copyright (c) 2021
# Copyright (c) 2020-2021
#
# * Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
......@@ -20,6 +20,7 @@
from setuptools import setup, find_packages
tests_require = [
"Flask>=2.0.1",
"pytest",
]
......@@ -34,6 +35,7 @@ setup(
license="AGPLv3+",
keywords="API",
author="Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ",
install_requires=["Flask>=2.0.1"],
tests_require=tests_require,
extras_require={
"tests": tests_require,
......
#!/usr/bin/env python3
# Copyright (C) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import pytest
from obmdataapi import create_app
@pytest.fixture
def app():
# create the app with common test config
app = create_app({"TESTING": True})
yield app
@pytest.fixture
def client(app):
"""A test client for the app."""
return app.test_client()
......@@ -21,5 +21,7 @@ import logging
logger = logging.getLogger()
def test_func():
pass
def test_index(client):
response = client.get("/")
assert b"Hello" in response.data
assert b"World" in response.data
Supports Markdown
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