Table of Contents
- Analyze application performance with Locust.
- Implement a Python test suite.
- Handle errors and exceptions in Python.
- Debug the code of a Python application.
I work for Güdlft, a company that created a digital platform to coordinate strength competitions (deadlifting 🏋🏻♂️, strongman) exclusively for branded fitness apparel companies.
Now, Güdlft has created a team called Regional Outreach to create a lighter (and less expensive) version of their current platform for regional organizers.
The team drew up a list of functional specifications for a prototype, broken down into several phases.
Sam, the main developer took care of phase 1, but he's getting sick, so I'm in charge of fixing the bugs in phase 1 and adding the feature expected in phase 2.
The goal of the application is to streamline the management of competitions between clubs (hosting, registration, fees and administration).
This is a proof of concept (POC) project, The aim is the keep things as light as possible, and use feedback from the users to iterate.
The app is powered by JSON files. This is to get around having a DB until we actually need one. The main ones are:
- competitions.json - list of competitions
- clubs.json - list of clubs with relevant information. You can look here to see what email addresses the app will accept for login.
With the forked project, correct the error, bugs and add the feature of this issues section here.
Create tests and performance report.
See complete report with request, response time statistics and beautiful charts here.
Unit tests for server.py and utils.py
Before you begin, please ensure you have this installed globally.
- Install Python ;
- Clone the project in desired directory ;
git clone https://github.com/KDerec/Python_Testing.git
- Change directory to project folder ;
cd path/to/Python_Testing
- Create a virtual environnement ;
virtualenv .
- Activate the virtual environment ;
- For Windows :
Scripts\activate
- For Linux :
source bin/activate
- For Windows :
- Install package of requirements.txt ;
pip install -r requirements.txt
-
Install Python. If you are using Linux or macOS, it should be available on your system already. If you are a Windows user, you can get an installer from the Python homepage and follow the instructions to install it:
- Go to python.org
- Under the Download section, click the link for Python "3.xxx".
- At the bottom of the page, click the Windows Installer link to download the installer file.
- When it has downloaded, run it.
- On the first installer page, make sure you check the "Add Python 3.xxx to PATH" checkbox.
- Click Install, then click Close when the installation has finished.
-
Open your command prompt (Windows) / terminal (macOS/ Linux). To check if Python is installed, enter the following command (this should return a version number.):
python -V # If the above fails, try: python3 -V # Or, if the "py" command is available, try: py -V
-
Change directory to flaskr folder ;
cd path/to/Python_Testing/flaskr
-
Run the server ;
python server.py
-
Go to http://127.0.0.1:5000/, login with an email accounts of clubs.json, for example, [email protected] and enjoy.
- To run tests and coverage test, go to ;
cd path/to/Python_Testing/tests
- Enter the two commands below ;
coverage run -m pytest coverage report -m
- Run server (see above) ;
- Go to ;
cd path/to/Python_Testing/tests/performance_tests
- Enter ;
locust
- Go to http://localhost:8089/, enter a number of users, spawn rate and host (http://127.0.0.1:5000/ by default) and click on "Start swarming".
Kévin Dérécusson 👇🏻
Email : [email protected]
LinkedIn : https://www.linkedin.com/in/kevin-derecusson/
This student project is the #8 of my training.
You can follow the previous here and next one here.