Coder Social home page Coder Social logo

r3-backend's Introduction

Backend for KOK

Before you start

Dev environment:

  1. make a virtual environment (Python 3.9, use pyenv)
  2. pip install pipenv
  3. pipenv install --dev (passing --dev will include both the default and development)
  4. pre-commit install
  5. docker-compose up --no-start && docker-compose start (install Docker Desktop)
  6. export IS_LOCAL_DB=True
  7. db_user=postgres db_app_user=app_user db_app_pass=postgress alembic upgrade head
  8. python main.py seed --teryt-path=<path to teryt> --count=5 --db (see kokon/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

Pipenv:

  • 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

Testing

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.

Coverage report

You can take a look at a coverage report in htmlcov/index.html file inside root directory.

Debugging

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.

Generating SQL from orm

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.

Relationship with the infrastructure as code repo

r3-backend's People

Contributors

nanvel avatar wsrtka avatar unjello avatar mlazowik avatar wniedzwiedz avatar fpudelko avatar zhylkaaa avatar quercusilvam avatar ttm56p avatar g-maak avatar supsub avatar kkomkov avatar majronman avatar pawelkraw avatar bancerowski avatar jakw0j avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.