Skip to content

sandbox for: aiohttp, swagger, jinja2, class based views

Notifications You must be signed in to change notification settings

iliadmitriev/aiohttp-sandbox

Repository files navigation

CI unittests codecov

  1. Install python3 virtual environment
python3 -m venv venv
source venv/bin/activate
  1. create .env file
cat > .env << __ENV
JWT_SECRET_KEY=testsecretkey
ENGINE=postgres
POSTGRES_HOST=192.168.10.1
POSTGRES_PORT=5433
POSTGRES_DB=profile
POSTGRES_USER=profile
POSTGRES_PASSWORD=profilesecret
__ENV
  1. export variables from .env file
export $(cat .env | xargs)
  1. modules
pip install aiohttp aiohttp-jinja2 aiohttp-swagger \
    aiopg sqlalchemy marshmallow aiohttp_jwt \
    aiohttp_apispec pytest pytest-cov pytest-aiohttp
  1. run
python3 app.py
  1. tests
pytest -v --cov=. --cov-report=term-missing

Build and run docker

  1. install docker
  2. build image
docker build -f Dockerfile -t profile-test ./
  1. setup .env file (p.2)
  2. create docker instance of postgres
docker run -d -p 5433:5432 --name profile-postgres --env-file .env postgres:13.2-alpine
  1. run docker image as daemon
docker run --rm -d -p 8080:8080 --env-file .env --name profile-api profile-api
  1. attach to api container and create schema
docker exec -i profile-api python <<-__CODE__
from sqlalchemy import create_engine
from settings import dsn
from models import Base
engine = create_engine(dsn)
Base.metadata.create_all(engine)
__CODE__

useful links

* [API](http://localhost:8080/api/v1/doc)
* [API docs](http://localhost:8080/api/doc)