A backend API for a personal blog/notebook implemented, using Aiohttp & Postgresql.
Deployment repo contains a set of Ansible playbooks for deploying this repo and frontend.
The following must be done before app can be run:
- Creating a virtual env & installing dependencies from
requirements.txt; - Adding a development app config at
backend_main/config.json(backend_main/config.json.samplecan be used as a template); - Ensuring a Postgresql 14+ instance exists and is running with the settings specified in the config file (location, default database & superuser).
- creating a dev database:
python -m backend_main.db
python -m backend_mainpython -m backend_main.db --forcepython -m backend_main.db --revision --message "<Migration message>"
# or
cd backend_main/db
alembic revision --autogenerate -m "<revision message>"python -m backend_main.db --migrate
# or
cd backend_main/db
alembic upgrade head # `alembic` must be invoked from the `db` dir
cd backend_main/db
# Apply migrations to the database up to <revision hash>
alembic upgrade <revision hash>
# Downgrade database to <revision hash
alembic downgrade <revision hash>Before tests can be run, a separate app configuration must be put at <project_root>/tests/test_config.json. Differences from dev configuration should include setting all logging modes to off and debug to True. use_forwarded can be set to True, as well.
tests module handles fixture cleanup and invokes pytest with additional plugins.
source venv/bin/activate
python -m tests [<additional pytest args>]# Runs all tests
python -m testsAny CLI args given to tests module will be passed to the invoked pytest command.
Tests from specific files & dirs can be performed by passing their paths relative to <project_root>/tests/tests directory:
# Run a single file `test_config.py`
python -m tests modules/test_config.py
# Run all tests in the `routes/objects` dir
python -m tests routes/objects
# Run tests from several files/dirs
python -m tests modules/test_config.py routes/objectsEach test file can be executed directly in order to run all its tests.