AxAks / P11_Gudlft

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

P11_Gudlift

Study project for testing

Chapters

  1. Presentation
  2. Prerequisites (for developers)
  3. Installation
  4. Execution
  5. Testing

1. Presentation

This project is a fork of the original Gudlift application available at : https://github.com/OpenClassrooms-Student-Center/Python_Testing

This is a proof of concept (POC) project to show a light-weight version of our competition booking platform. The aim is the keep things as light as possible, and use feedback from the users to iterate.


2. Prerequisites (for developers)

This project uses the following technologies:

  • Python v3.9+

  • Virtual environment This ensures you'll be able to install the correct packages without interfering with Python on your machine. Before you begin, please ensure you have this installed globally.

  • Flask


3. Installation

Download the project:
Via Git
$ git clone https://github.com/AxAks/P11_Gudlft.git

Via the Web

Linux / Mac
in the project directory in a shell:
create the virtual environment
$ python3.9 -m virtualenv 'venv_name'
activate the environment:
$ source 'venv_name'/bin/activate
install project requirements:
$ pip install -r requirements.txt

Windows
in the project directory in a shell:
create the virtual environment
$ virtualenv 'venv_name'
activate the environment:
$ C:\Users'Username''venv_name'\Scripts\activate.bat
install project requirements:
$ pip install -r requirements.txt


#4. Execution
activate the environment:
$ source 'venv_name'/bin/activate

launch the app:
(terminal)

  • At the Project root level:
    ('venv_name') $ export set FLASK_APP=server
    -> sets the environment variable
    ('venv_name') $ python -m flask run
    -> run the program: then reachable at http://localhost:5000

The app is powered by JSON files. This is to get around
having a DB until we actually need one. The main ones are:

  • the JSON DB file database.json

5. Testing

(virtual environment must be activated !)

Unit and integration Tests
The tests can be run with pytest
The main testing environment (code and sample data) is located in the folder "tests"
It contains:

  • The unit tests
  • The integration tests

A "test_launcher" file is available to launch both series of tests at once
using the following command:
-> python -m pytest -v tests/tests_launcher.py
or
-> python -m pytest -v [testfile1_path] [testfile2_path] [...]

or separately:
-> python -m pytest -v tests/integration_tests/integration_tests.py
-> python -m pytest -v tests/unit_tests/*
(unit test are separated in different modules sorted by route)
More info about pytest at :pytest

We also like to show how well we're testing, so the project contains a module called:
coverage
Basic tests run with coverage rate, use the following command:
coverage run -m pytest -v tests/tests_launcher.py (unit tests and integration tests at once)

You can also generate a HTML report using the command:
-> coverage html

Performance test are run under the module locust ( integrated in the project with locustfile.py as config file)
locust

Basic run of locust
-> locust -f locustfile.py

Basic run of locust from within the project with two threads
This enables to save CPU usage if needed.
Using two differents terminals:
-> locust -f locustfile.py --master (to set the master thread)
-> locust -f locustfile.py --worker (to set the workers)

The performance tests are then reachable at : http://localhost:8089/
(The app server must be launched)
You can set the user's peak and the spawn rate you wish
Enter the address of the app : http://localhost:5000
And Launch
-> the tests calls all routes and evaluates the performance.

About


Languages

Language:Python 90.2%Language:HTML 7.6%Language:CSS 2.1%