Adding app factory and settings
continuous-integration/drone/push Build is passing Details

master
Drew Bednar 1 year ago
parent 4dd7672ba1
commit 4e27d3b407

1
.gitignore vendored

@ -60,3 +60,4 @@ target/
# Pycharm
.idea
.env

@ -13,3 +13,26 @@ inv --list
```
For a list of current utilities.
## Features
- [x] Application factory
- [x] View Blueprints
- [x] Configuration with Pydantic
- [ ] dotenv support for local dev
- [ ] Sqlalchemy integration
- [ ] Model migrations using Alembic
- [ ] User accounts
- [ ]
- [ ] Email integration
- [ ] Admin portal
- [ ] Hypermedia Application driven by HTMX under `/`
- [ ] JSON API under `/api` route
- [ ] Tilt local development environment
- [ ] Helm Chart Deployment
- [x] Continous Integration with Drone.io
- [x] Lint Checks
- [x] Unit Tests
- [ ] Integration Tests
- [ ] Continuous Delivery pipeline with Drone.io

@ -5,5 +5,6 @@ pip-tools
pre-commit
pytest
pytest-cov
python-dotenv
shellcheck-py==0.9.0.5
ruff

@ -57,6 +57,8 @@ pytest==7.4.2
# pytest-cov
pytest-cov==4.1.0
# via -r dev-requirements.in
python-dotenv==1.0.0
# via -r dev-requirements.in
pyyaml==6.0.1
# via pre-commit
ruff==0.0.290

@ -0,0 +1 @@
SECRET_KEY=6755ecb085f9c8d2b7da9f6fd3d9b3590758a1602f1a98724abbe204ff525153

@ -0,0 +1,15 @@
from flask import Flask
from .config import ContactSettings
def create_app(config: ContactSettings = None):
app = Flask("htmx_contact")
app.config.from_object(config if config else ContactSettings())
from . import main
app.register_blueprint(main.bp)
return app

@ -0,0 +1,5 @@
from pydantic_settings import BaseSettings
class ContactSettings(BaseSettings):
SECRET_KEY: bytes

@ -1,15 +1,15 @@
from flask import Flask
from flask import Blueprint
from flask import redirect
from flask import render_template
app = Flask("htmx_contact")
bp = Blueprint("main", __name__, url_prefix="/")
@app.route("/", methods=["GET"])
@bp.route("/", methods=["GET"])
def index():
return redirect("/contacts")
@app.route("/contacts", methods=["GET"])
@bp.route("/contacts", methods=["GET"])
def contacts():
return render_template("contacts.html", message="Hello HTMX")

@ -1,2 +1,4 @@
flask
pydantic
pydantic-settings
sqlalchemy

@ -4,6 +4,8 @@
#
# pip-compile requirements.in
#
annotated-types==0.5.0
# via pydantic
blinker==1.6.2
# via flask
click==8.1.7
@ -20,9 +22,22 @@ markupsafe==2.1.3
# via
# jinja2
# werkzeug
pydantic==2.3.0
# via
# -r requirements.in
# pydantic-settings
pydantic-core==2.6.3
# via pydantic
pydantic-settings==2.0.3
# via -r requirements.in
python-dotenv==1.0.0
# via pydantic-settings
sqlalchemy==2.0.20
# via -r requirements.in
typing-extensions==4.7.1
# via sqlalchemy
# via
# pydantic
# pydantic-core
# sqlalchemy
werkzeug==2.3.7
# via flask

@ -20,7 +20,7 @@ def serve_dev(c, debugger=True, reload=True, threads=True, port=8888, host="0.0.
@task
def test(c):
"""executes test suite"""
c.run("pytest -vvv tests/", pty=True)
c.run("pytest -vvv --cov tests/", pty=True)
@task

@ -1,10 +1,32 @@
import pytest
from htmx_contact.app import app
from htmx_contact import create_app
from htmx_contact.config import ContactSettings
@pytest.fixture()
def client():
def test_config():
return ContactSettings(SECRET_KEY=b"secrettestingvalue")
@pytest.fixture()
def app(test_config):
app = create_app(config=test_config)
app.config.update(
{
"TESTING": True,
}
)
# other setup can go here
yield app
# clean up / reset resources here
@pytest.fixture()
def client(app):
return app.test_client()

Loading…
Cancel
Save