FastAPI: Jinja2 base layout + database models
This MR brings in basic Jinja2 template rendering with l10n integration, as well as basic SQLAlchemy models (starting with User, AccountType).
Coverage Note: With this MR, we're at 86% total coverage across the base. Our goal is 100%, but with this MR, testing coverage was focused primarily on files being added (all new files should be at 100%) and some where we could easily get it. That being said; we expect that all new Python code added for FastAPI should have 100% coverage.
View Changes
First, follow INSTALL for relevant configuration and database setup.
Then, run the FastAPI server in straight up development mode:
$ hypercorn aurweb.asgi:app
With hypercorn
running, you can browse to http://localhost:8000. You will be presented with the index page, which uses the entirety of ./templates/
to render through FastAPI. This page has the base layout of the website, without user authentication taken into account, including the set_lang
language form located at the top right underneath the main navigation bar.
Additions
-
aurweb.models.user
, an SQLAlchemy ORM Users table mapping. -
aurweb.models.account_type
, an SQLAlchemy ORM AccountTypes table mapping. -
aurweb.routers.html
, a router used to render our HTML layout. -
aurweb.templates
, a jinja2-based template module. -
aurweb.testing
, a test utility module. - the
templates
directory. - aurweb.config [options] aurwebdir, useful to store the absolute root of aurweb in the config so we can just grab its location without introspecting scripts and other workarounds.
- modern pytest suites; see
test/*.py
.
Modifications
-
aurweb.l10n
: Make a global Translator object,aurweb.l10n.translator
; also added some more utility functions used in different higher level areas. -
test
: Addedcoverage run --append
to all Python script executions inside of our shell tests, added pytest suites. This is provided bytest/scripts/cover
within sharness tests and specified for pytest inside oftest/Makefile
. -
test/Makefile
: Addpytest
target, move the check target tosh
, usecheck
to cover bothpytest
andsh
. -
.gitlab-ci.yml
: Add pytest dependencies, install aurweb, setup a test config and run initdb, then print out coverage report after runningmake -C test
.
For a complete set of modifications, see git log origin/pu..fork/pu_fastapi_base
.