Dev environment:
- make a virtual environment (Python 3.9, use pyenv)
pip install pipenv
pipenv install --dev
(passing--dev
will include both the default and development)pre-commit install
docker-compose up --no-start && docker-compose start
(install Docker Desktop)export IS_LOCAL_DB=True
db_user=postgres db_app_user=app_user db_app_pass=postgress alembic upgrade head
python main.py seed --teryt-path=<path to teryt> --count=5 --db
(seekokon/commands/seed/README.md
)
Regarding branching:
- try to make sure you work on issues on seperate branches (e.g. feature/get-guests)
- always merge to dev
- merge to main only from dev
- we use it as requirements.txt alternative
- we still need
requirements.txt
for cloud functions - to generate
requirements.txt
:pipenv lock -r > requirements.txt
Migrations using alembic:
- upgrade:
alembic upgrade head
- downgrade:
alembic downgrade -1
- new migration:
alembic revision --autogenerate -m <migration_name>
(then edit generated migration if required) - after migration added - ensure in dev that downgrade works properly
IS_LOCAL_DB=True db_name=kokon_test db_user=postgres alembic upgrade head
pytest tests
If you need database filled with data - use db
fixture, just add db
argument to your test function.
You can take a look at a coverage report in htmlcov/index.html
file inside root directory.
You can run Google Cloud Function by running:
$ export IS_LOCAL_DB=True
$ functions-framework --target <function-name> --debug
Arguments (including request payload) should be passed as query params.
You'll need to add a header with the following value as well. Either pass it with -H
to curl,
or install a browser extension that allows customizing headers. For example header hacker for Chrome.
X-Endpoint-API-UserInfo: eyJnaXZlbl9uYW1lIjogIkpvaG4iLCAiZmFtaWx5X25hbWUiOiAiRG9lIiwgImVtYWlsIjogImpvaG4uZG9lQGV4YW1wbGUuY29tIiwgInN1YiI6ICIxMDc2OTE1MDM1MDAwNjE1MDcxNTExMzA4MjM2NyIsICJwaWN0dXJlIjogImh0dHBzOi8vZ29vZ2xlLmNvbS8xMjMifQ==
For more info see: https://cloud.google.com/endpoints/docs/openapi/migrate-to-esp-v2#receiving_auth_results_in_your_api
You can debug functions using tests, see tests/functions
for examples.
For example for the Host
model:
print(CreateTable(Host.__table__).compile(global_pool))
Passing a working postgres connection pool is important, otherwise some features (like native enums) are not used.
- The OpenAPI spec now lives in the iac repo
- When adding/removing functions add/remove them from the cloudbuild setup as well at: https://github.com/KoalicjaOtwartyKrakow/iac/blob/dev/modules/codebuild/backend/main.tf#L6