GÜDLFT is a (fictional - for education purposes) digital platform for coordinating strength competition in North America and Australia.
This is a proof of concept (POC) project to show a light-weight version of our competition booking platform. The goal of this project is to debug and build a test suite for a Flask application in Python, et proceed with developing more features with a Test-Driven Development approach.
- Debugging code in a Python application
- Test-Driven Development
- Unit Tests and Integration Tests with Pytest
- Functional Tests with Selenium
- Test Coverage with Coverage
- Performance Tests with Locust
- Manage errors and exceptions in Python
- Setup of a Python virtual environment
- Problem Solving
- Git and Github
- Flask
- Testing
This project uses the following technologies:
-
Python v3.x+
-
After cloning, change into the directory and type
virtualenv .. This will then set up a a virtual python environment within that directory. -
Next, type
source bin/activate. You should see that your command prompt has changed to the name of the folder. This means that you can install packages in here without affecting affecting files outside. To deactivate, typedeactivate -
Rather than hunting around for the packages you need, you can install in one step. Type
pip install -r requirements.txt. This will install all the packages listed in the respective file. If you install a package, make sure others know by updating the requirements.txt file. An easy way to do this ispip freeze > requirements.txt -
Flask requires that you set an environmental variable to the python file. However you do that, you'll want to set the file to be
server.py. Check here for more details -
You should now be ready to test the application. In the directory, type either
flask runorpython -m flask run. The app should respond with an address you should be able to go to using your browser.
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.
- booking.json - list of places booked by each club in each competition
- The Master branch should always have finished code running properly.
- A new branch must be created for any new feature or bug fix that would break the code
- Name new branches following the naming convention
<feature/bug/enhancement>/<descriptive_name>. - Before merging a branch to the Master branch, the code must be thoroughly tested, all the tests must pass.
Thoroughly testing a program is ensuring it works in any possible situation.
This program has been tested using various methods to guarantee its functioning.
The framework pytest as well at its extensions such as pytest-flask and pytest-mock have been used to create tests.
Unit tests check that simple units of code (functions, methods, class) work as expected,
act accordingly to the specification and return the right values.
They also check that the unit tested reacts appropriately given unexpected input values.
A unit test cannot be dependent on any functionality outside the unit being tested. For this reason, we have used mocked objects with the library pytest-mock to control the environment for these tests.
Integration tests check that units of code work well together to render the appropriate
result given a situation.
They also ensure that unexpected input will not cause the program to crash.
Functional tests check the user perspective in any situation and ensure the user is able to perform
the action they intend and get the appropriate response in case of wrong input.
In this program, the framework Selenium has been used to simulate the user activity on a browser.
You will need to download Chromedriver
and place it in the functional_test folder.
- Download Chromedriver and place it in the functional_test folder
- Run the flask application (restart if needed)
- Use the following command in the terminal:
pytest tests
Coverage reports to how well a program has been tested. The requirements indicate a minimum of 60% coverage being acceptable.
The library Coverage has been used to evaluate if this program has been properly tested.
- Run the flask application (restart if needed)
- Use the following command in the terminal:
pytest tests --cov=. --cov-branch --cov-report html- Open the file
htmlcov/index.htmlin the browser.
Here's a screenshot of the latest coverage report:

Performance tests assess the speed, responsiveness, and stability of an application when handling a particular workload.
In this program, the framework Locust has been used to test the performance of the application.
- Use the following command in the terminal:
locust -f tests/performance_test.py- Follow the link provided to start the test:
http://0.0.0.0:8089- Indicate the number of users and the spawn rate, as well as the host address:
http://127.0.0.1:5000

