A small test for Python API development
Nork-Town is a weird place. Crows cawk the misty morning while old men squint. It’s a small town, so the mayor had a bright idea to limit the number of cars a person may possess. One person may have up to 3 vehicles. The vehicle, registered to a person, may have one color, ‘yellow’, ‘blue’ or ‘gray’. And one of three models, ‘hatch’, ‘sedan’ or ‘convertible’. Carford car shop want a system where they can add car owners and cars. Car owners may not have cars yet, they need to be marked as a sale opportunity. Cars cannot exist in the system without owners.
Requirements
● Setup the dev environment with docker
○ Using docker-compose with as many volumes as it takes
● Use Python’s Flask framework and any other library
● Use any SQL database
● Secure routes
● Write tests
What things you need to install the software and how to install them.
Python 3.10+
Python 3.6+ (Not Tested)
A step by step series of examples that tell you how to get a development env running.
- Get this project
git clone https://github.com/Vrrl/Nork-Town-Cars.git
cd Nork-Town-Cars
- Installing the dependences (virtualenv recommended)
pip install -r requirements.txt
- Configure env file
cp .env.example .env
# fill .env variables
- Run the server API
python server.py
- Check if it is running with curl request
curl http://127.0.0.1:5000/hello-world
# Hello World! The API is Running!
- building the container
docker build -t nork-town-cars .
- running the container
docker run -p 3567:3567 -d --hostname=supertokens --network=host registry.supertokens.io/supertokens/supertokens-postgresql
docker run -e DATABASE_CONNECTION_STRING=sqlite:///./test.db -e SUPERTOKENS_CONNECTION_URI=http://supertokens:3567 --network=host -p 80:5000 nork-town-cars
- build & run
docker-compose up -d
To run the Unit Tests with PyTest after installation run in the project folder
pytest -v
Test the code quality according to the pylint config file
pylint src
Load the Insomnia Collection file "insomnia_routes_collection" and make requests.
- Flask - Web Framework
- Sqlalchemy - Database ORM
- SuperTokens - Auth Provider
- PyTest - Test Tools
Things that will make the project better in my opnion, but it's not necessary
- Segregate supertokens from flask by applying directly in usecases
- System diagrams
- Car Owner & Car edit/delete usecases
- Flask Framework tests (idk if Flask has an test SDK as FastAPI has)