Skip to content

FastAPI: Jinja2 + SQLAlchemy ORM models + Tests

Kevin Morris requested to merge kevr/aurweb:pu_fastapi into pu

This MR brings in basic Jinja2 template rendering with l10n integration, as well as basic SQLAlchemy models (starting with User, AccountType).

It additionally brings in a Dockerfile which can be used to run tests and subsequently start up the development server in a docker instance: docker build --network=host .

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.


  • 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 static directory.
  • 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.


  • aurweb.l10n: Make a global Translator object, aurweb.l10n.translator; also added some more utility functions used in different higher level areas.
  • test: Added coverage run --append to all Python script executions inside of our shell tests, added pytest suites. This is provided by test/scripts/cover within sharness tests and specified for pytest inside of test/Makefile.
  • test/Makefile: Add pytest target, move the check target to sh, use check to cover both pytest and sh.
  • .gitlab-ci.yml: Add pytest dependencies, install aurweb, setup a test config and run initdb, then print out coverage report after running make -C test.

For a complete set of modifications, see git log origin/pu..fork/pu_fastapi.


  • Updated, test/ to include deps and more testing details.
  • Updated INSTALL, to include updated deps.
  • Updated, to include some new contribution guidelines.

This MR covers the current state of the board at Other branches will be based off of this MR from branch for further items on the board (as of writing); that is: user authentication, complete porting over of Home page route, and so on.

Edited by Kevin Morris

Merge request reports