Git Product home page Git Product logo

ut_flask_base's Introduction

U1 unit test homework

Installation and Config

Require

  • OS: Linux
  • Python: python3 (python 3.8 is recommended)
  • Mysql: mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) (if needed)
  • Redis: Redis server v=5.0.3
  • Nginx: nginx version: nginx/1.13.12
  • Docker: Docker version 18.09.0
  • Docker-compose: docker-compose version 1.23.1
  • Supervisord: v3.3.1

Setup environment for development and unittest

  • Install virtualenv
pip install virtualenv
  • Create virtual environment:
virtualenv -p python3 venv
  • Active and install dependencies:
source ./venv/bin/activate
cd project_folder && make deps

Configuration

cd project_folder     # if needed
make init # to copy secret files
  • Create database and re-config settings, env file. Example:
# project_folder/settings/development.py

from settings.common import *

# SQLAlchemy override
SQLALCHEMY_DATABASE_URI = 'mysql://test:123456@localhost:3306/database_test'

# Redis override
REDIS_DB = 0
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_TTL = 60
# project_folder/.env

DYNACONF_SETTINGS=settings.development
  • Make migrations and migrate. Example:
cd project_folder     # if needed
export APP_ENV=development
make migrate          # if needed

Fix if error migrate: https://stackoverflow.com/questions/32311366/alembic-util-command-error-cant-find-identifier

  • Add host if environment is development

Run server

Run server dev local

cd project_folder     # if needed
python manager.py

Build with docker

cd project_folder     # if needed
docker-compose up -d --build

Style Guide for Python Code

  • Auto format code with black and isort
make auto-lint

Unittest

Configuration

Copy settings file and edit the value according to the unittest environment:

cd project_folder     # if needed
cp settings/unittest.py.orig settings/unittest.py
  • Re-config settings, env file. Example:
# microservices/settings/unittest.py

from settings.common import *

# SQLAlchemy override
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'

# Redis settings
REDIS_HOST = 'redis'
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_TTL = 60
# microservices/.env

DYNACONF_SETTINGS=settings.unittest

Command line

Run all test case

make test

Check style with flake8:

make lint

Coverage all test suites:

make coverage

Coverage with html view

coverage html

ut_flask_base's People

Contributors

hocndh-1784 avatar

Watchers

 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.