/features-webapp

Web app that lets a user create client requests of new features

Primary LanguagePythonMIT LicenseMIT

Python Requirements Status Build Status Coverage

features-webapp

This a demo app based on this requirements built with Python, Flask and KnockoutJs. This demo consists in a Knockout.js single page application and a Python Restful API.

A live demo can be found in here.

This app can be started using docker or running the stand-alone service.

Getting the project

  • Clone the repository in any directory you want with:
git clone git@github.com:netor27/features-webapp.git
  • Change directory with:
cd features-webapp/

Start the service with docker-compose (Recommended)

sudo docker-compose build
sudo docker-compose up -d

This will initialize the containers (one with a postgreSQL database and another with the flask app).

That's it!, you can now login to the site with the previous credentials here http://localhost:80.

Also, the API docs are located in here http://localhost:80/apidocs/.

  • To stop the containers:
sudo docker-compose down

Running the tests inside a docker container

  • Execute the following commands to build the test images and run the tests.
sudo docker-compose -f docker-compose.tests.yml -p ci build
sudo docker-compose -f docker-compose.tests.yml -p ci run web-tests python -m pytest --cov=web/ tests --configfile=configtestdocker
  • That will print out the tests results and a code coverage report.
  • To stop the test images, run the following command.
sudo docker-compose down

Start the standalone service

Setup a PostgreSQL database

  • Create a database in PostgreSQL, login as the default user (set "features" to your desired new db name).
sudo -u postgres createdb features
sudo -u postgres -i
  • Run the psql client and create a new user with a role to manage the new db. (set 'apiuser' to your user, 'password' to your password and 'features' to your database name).
psql

CREATE ROLE apiuser WITH LOGIN PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE features TO apiuser; 
ALTER USER apiuser CREATEDB;
  • If you change any value, update the configuration in the config.py file with the values for your database name, user, password, host and port.

  • The app will initialize the schema by itself the first time it runs.

Running the service

  • To install the requirements and run the app, execute the following commands:
pip install -r requirements.txt
python app.py

That's it!, you can now login to the site with the previous credentials here http://localhost:80.

Also, the API docs are located in here http://localhost:80/apidocs/.

Running tests with the standalone service

  • First you need to setup a local database and update the config file with the values for your db name, user name, password and db hostname.

Setting up the test database

  • Create a database in PostgreSQL, login as the default user (set 'test_mesages' to your desired new db name).
sudo -u postgres createdb 'test_features'
sudo -u postgres -i
  • Run the psql client and set the privileges to our previously created user to manage the new db.
psql

GRANT ALL PRIVILEGES ON DATABASE test_features TO apiuser;
  • Update the contents of configtest.py with the values for your database name, database user, database host.

Running tests

pip install pytest pytest-cov pytest-flask
pytest --cov=web/ tests
  • That will print out the tests results and a code coverage report.