From 91572f9f8497c37fc44e41437cec124de875e240 Mon Sep 17 00:00:00 2001 From: Amit Tripathi Date: Sat, 25 May 2019 12:13:51 +0200 Subject: [PATCH] Requirements upgrade, python3.7 tests in travis, coverage report (#35) --- .gitignore | 1 + .travis.yml | 8 +++++--- README.md | 37 +++++++++++++++++++++---------------- requirements.txt | 12 ++++++------ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index d19bafb..843a753 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ bootstrap.min.css *.egg-info/ env env3 +venv .idea .vscode dist diff --git a/.travis.yml b/.travis.yml index 3d49867..44d4764 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,17 @@ sudo: false -language: - - python +dist: xenial +language: python python: - "3.5" + - "3.6" + - "3.7" install: - pip install -r requirements.txt - pip install coveralls script: - - coverage run --source pygmy -m py.test + - coverage run --omit="*/templates*,*/venv*,*/tests*,*/python*" -m py.test after_success: - coveralls \ No newline at end of file diff --git a/README.md b/README.md index 181404f..0ba774d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ # Pygmy [![Build Status](https://travis-ci.org/amitt001/pygmy.svg?branch=master)](https://travis-ci.org/amitt001/pygmy) +[![Coverage Status](https://img.shields.io/coveralls/github/amitt001/pygmy.svg?color=yellowgreen)](https://coveralls.io/github/amitt001/pygmy?branch=master) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Django.svg) [![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/) ![Docker Pulls](https://img.shields.io/docker/pulls/amit19/pygmy.svg) @@ -12,7 +13,8 @@ Live version of this project @ [https://pygy.co](https://pygy.co) Check link stats by adding **+** to the URL. Example [pygy.co/pygmy+](https://pygy.co/pygmy+) -*Note that pygy.co is a demo website for this project and should be used as such. While the website is going to be up for the foreseeable future, its future depends on the sponsorship and hosting that I get. Currently, the project is hosted on Digitalocean, as they were kind enough to offer me one year of sponsorship. I would like to keep the project website up and maintain the project but I do not make any money out of this project or website. +*Note that pygy.co is a demo website for this project and should be used as such. While the website is going to be up for the foreseeable future, its future depends on the sponsorship and hosting that I get. Currently, the project is hosted on Digitalocean, as they were kind enough to offer me one year of sponsorship. I would like to keep the project website up and maintain the project but I do not make any financial gains out of this project or website. Website is +free to use and is completely ad-free. If you would like to support the project, Please use the donate link in [Donations](#donations) section.* # Table of Contents @@ -29,7 +31,7 @@ If you would like to support the project, Please use the donate link in [Donatio - [Use SQLite](#use-sqlite) - [Docker](#docker-1) - [Using Pygmy API](#using-pygmy-api) - - [## Create User:](#create-user) + - [Create User:](#create-user) - [Shell Usage](#shell-usage) - [How Link Stats Are Generated?](#how-link-stats-are-generated) - [How Pygmy Auth Token Works?](#how-pygmy-auth-token-works) @@ -94,19 +96,19 @@ Note: - The project has two config files: - pygmy.cfg: `pygmy/config/pygmy.cfg` rest API and pygmy core settings file - settings.py: `pygmyui/pygmyui/settings.py` Django settings file - - SQLite is default db, if you are using PostgreSQL or MySQL with this project, make sure they are installed into the system. - - You can run pygmy shell present in the root directory to run the program on the terminal. `python shell` - - By default in `pygmyui/pygmyui/settings.py` DEBUG is set to True, set it to False in production + - SQLite is default DB, if you are using PostgreSQL or MySQL with this project, make sure they are installed into the system. + - You can run pygmy shell also. Present in the root directory. To run the program on the terminal: `python shell` + - By default, DEBUG is set to True in `pygmyui/pygmyui/settings.py` file, set it to False in production. ## DB Setup: -By default Pygmy uses SQLite but any of the SQLite, MySQL or PostgreSQL DB can be used. Configs are present in `pygmy/config/pygmy.cfg` directory. +By default, Pygmy uses SQLite but any of the DB, SQLite, MySQL or PostgreSQL, can be used. Configs is present at `pygmy/config/pygmy.cfg`. -Use db specific instruction below. Make sure to check and modify values in pygmy.cfg file according to your DB setup. +Use DB specific instruction below. Make sure to check and modify values in pygmy.cfg file according to your DB setup. ### Use MySQL -First install `pymysql`: +First, install `pymysql`: `pip install pymysql` @@ -131,7 +133,7 @@ Enter MySQL URL `CREATE DATABASE pygmy;` -Note: It's better to use Mysql with version > `5.6.5` to use default value of `CURRENT_TIMESTAMP` for `DATETIME`. +Note: It's better to use Mysql with version > `5.6.5` to use the default value of `CURRENT_TIMESTAMP` for `DATETIME`. ### Use Postgresql @@ -167,14 +169,13 @@ Docker image name: amit19/pygmy Docker image can be built by: `docker build -t amit19/pygmy .` -Both Dockerfile and docker-compose file are present at the root of the project. +Both the Dockerfile and docker-compose file are present at the root of the project. To use docker-compose you need to pass DB credentials in the docker-compose file ## Using Pygmy API -## Create User: ------------- +### Create User: curl -XPOST http://127.0.0.1:9119/api/user/1 -H 'Content-Type: application/json' -d '{ "email": "amit@gmail.com", @@ -249,7 +250,7 @@ Out[4]: 'time_stats': 0, 'total_hits': 0} -In [5]: # check available context of the shell +In [5]: # check the available context of the shell In [6]: pygmy_context In [7]: # Create custom short URL @@ -274,7 +275,7 @@ For getting geo location stats from IP maxminds' [GeoLite2-Country.mmd](http://p ###### How Pygmy Auth Token Works? -It uses JWT. When user logs in using username and password two tokens are generated, refresh token and auth token. Auth token is used for authentication with the Pygmy API. Refresh token can only be used to generate new auth token. Auth token has a very short TTL but refresh token has a longer TTL. After 30 minutes. When a request comes with the old auth token and a new token is generated from the refresh token API. User passwords are encrypted by [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) hash algorithm. +It uses JWT. When user logs in using username and password two tokens are generated, refresh token and auth token. Auth token is used for authentication with the Pygmy API. The refresh token can only be used to generate a new auth token. Auth token has a very short TTL but refresh token has a longer TTL. After 30 minutes. When a request comes with the old auth token and a new token is generated from the refresh token API. User passwords are encrypted by [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) hash algorithm. ## Development @@ -287,9 +288,13 @@ To contribute to the project: 3. Test the changer by running: `docker run -it -p 8000:8000 pygmy` 4. The website will be available at http://127.0.0.1:8000/ -Run tests and generate a coverage report: +Run tests: -`coverage run --source pygmy -m py.test` +In root directory run this command: `py.test` + +Or with coverage report(`pip install coverage`): + +`coverage run --omit="*/templates*,*/venv*,*/tests*" -m py.test` See coverage report(Coverage is bad because the coverage for integration tests is not generated yet): diff --git a/requirements.txt b/requirements.txt index 7062b3e..4e7cd15 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ attrs==17.4.0 -bcrypt==3.1.4 +bcrypt==3.1.6 certifi==2018.1.18 cffi==1.11.4 chardet==3.0.4 click==6.7 -Django==2.1.3 +Django==2.2.1 Flask==1.0.2 Flask-Cors==3.0.3 Flask-JWT-Extended==3.6.0 @@ -12,7 +12,7 @@ geoip2==2.7.0 gunicorn==19.7.1 idna==2.6 itsdangerous==0.24 -Jinja2==2.10 +Jinja2==2.10.1 MarkupSafe==1.0 marshmallow==2.16.3 maxminddb==1.3.0 @@ -24,8 +24,8 @@ pycparser==2.18 PyJWT==1.5.3 pytest==3.4.0 pytz==2017.3 -requests==2.20.1 +requests==2.22.0 six==1.11.0 -SQLAlchemy==1.2.2 -urllib3==1.24.1 +SQLAlchemy==1.3.3 +urllib3==1.25.3 Werkzeug==0.14.1 \ No newline at end of file