From 7ba7354f016bed3ff3b2afff5ecb1aa919a8ed26 Mon Sep 17 00:00:00 2001
From: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
Date: Mon, 19 Jun 2023 18:04:24 +0200
Subject: Flask Hello World

---
 check               |  3 +++
 kerbana/__init__.py | 32 ++++++++++++++++++++++++++++++++
 kerbana/config.py   | 12 ++++++++++++
 tests/test_app.py   | 14 ++++++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 kerbana/__init__.py
 create mode 100644 kerbana/config.py
 create mode 100644 tests/test_app.py

diff --git a/check b/check
index 331883f..45b03c8 100755
--- a/check
+++ b/check
@@ -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())
-- 
cgit v1.2.3