Skip to content

api to manage users and posts (FastAPI + SQLAlchemy + AUTH (JWT) + PyTest)

Notifications You must be signed in to change notification settings

Slavian2015/FastAPIPostAuth

Repository files navigation

Backend API build and configuration

API source code. Written on python using FastAPI, SQLITE, SQLAlchemy, Alembic, PyTest, JWT

Requirements

  1. Python 3.10
  2. Python PIP (https://pip.pypa.io/en/stable/installation/)
  3. Python venv module (https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)

Installation

  1. Clone code from the repository to the local machine
$ git clone [email protected]:Slavian2015/FastAPIPostAuth.git path_on_locahost
  1. CD into the project folder
  2. Create python virtual environment
$ python3 -m venv ./venv
  1. Activate virtual environment
$ source ./venv/bin/activate
  1. Install application dependencies
$ pip install -r requirements.txt

Configuration

  1. Copy .env.dist file to the .env file
$ cp .env.dist .env
  1. Configure .env file
  • AUTH_SECRET - Random string that will be used as a key for the hashing
  • NUMBER_OF_USERS - Random integer that will be used in test db users creation
  • MAX_POSTS_PER_USER - Random integer that will be used in test db post creation
  • MAX_LIKES_PER_USER - Random integer that will be used in test db likes creation

Database migration

  1. Copy .env.dist file to the .env file
$ alembic upgrade head

Testing

  1. Unit test suite
$ python3 -m pytest tests/unit
  1. Functional test suite
$ python3 -m pytest tests/functional

All tests should pass successfully to consider setup is finished and works

Running local server

  1. Start uvicorn service
$ uvicorn src.api.application:api --host=localhost --port=8080

Create DB test data

  1. Run python bot
$ python3 demo_db/bot.py

About

api to manage users and posts (FastAPI + SQLAlchemy + AUTH (JWT) + PyTest)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published