diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-06-19 18:04:24 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-06-19 18:04:24 +0200 |
commit | 7ba7354f016bed3ff3b2afff5ecb1aa919a8ed26 (patch) | |
tree | 4c1f12b3629a42ac031edf90691f0c63fef1a8ee | |
parent | bf66286309fedc6f0a92d0cd9681d4c6484f30d9 (diff) |
Flask Hello World
-rwxr-xr-x | check | 3 | ||||
-rw-r--r-- | kerbana/__init__.py | 32 | ||||
-rw-r--r-- | kerbana/config.py | 12 | ||||
-rw-r--r-- | tests/test_app.py | 14 |
4 files changed, 61 insertions, 0 deletions
@@ -37,6 +37,9 @@ case $SUBCMD in "static") bandit --recursive --number=3 -lll -iii . ;; + "run") + flask --app kerbana --debug run + ;; *) echo "No such subcommand $SUBCMD" ;; diff --git a/kerbana/__init__.py b/kerbana/__init__.py new file mode 100644 index 0000000..920e730 --- /dev/null +++ b/kerbana/__init__.py @@ -0,0 +1,32 @@ +from typing import Optional + +import flask +import tomllib + +from . import config + + +def create_app(test_config: Optional[config.Config] = None): + app = flask.Flask(__name__, instance_relative_config=True) + + app.config.from_object(config.DefaultConfig) + + if test_config is None: + app.config.from_file( + "/etc/kerbana/kerbana.toml", + load=tomllib.load, + ) + app.config.from_file( + "kerbana.toml", + load=tomllib.load, + ) + app.config.from_envvar("KERBANA_CONFIG") + app.config.from_prefixed_env(prefix="KERBANA_") + else: + app.config.from_object(test_config) + + @app.route('/') + def root(): + return "Hello World!" + + return app diff --git a/kerbana/config.py b/kerbana/config.py new file mode 100644 index 0000000..2ccaabc --- /dev/null +++ b/kerbana/config.py @@ -0,0 +1,12 @@ +# Default configuration values + +class Config: + SECRET_KEY = "dev" + + +class DefaultConfig(Config): + pass + + +class TestConfig(Config): + TESTING = True diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..6d96fbb --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,14 @@ +import unittest + +from kerbana import config, create_app + + +class TestBase(unittest.TestCase): + def setUp(self): + test_config = config.TestConfig() + self.app = create_app(test_config) + self.client = self.app.test_client() + + def test_root(self): + res = self.client.get("/") + self.assertEqual("Hello World!", res.data.decode()) |