KalleHahl / Wolt2024

Backend code challenge for Wolt Internship

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pre-assignment for Wolt Summer 2024 Engineering Internship, Backend (Python)

Description:

HTTP API for calculating an order's delivery fee

I took this pre-assignment as an opportunity to challenge myself, and tried to create as clean, readable, typed, and well-tested code as possible. Even though the assigned project was small in scale, I decided to go for a directory structure, and divided different functionalities, such as pydantic models and the class where the delivery fee calculation happens, into separate folders.

Technologies:

  • Poetry for dependency management
  • The API is built using FastAPI and Uvicorn
  • Pydantic is used in validating the request and response
  • Unit tests are run with Pytest using Pythons unittest module
  • FastAPIs TestClient is used in testing the endpoint
  • Coverage is used for checking test coverage
  • Mypy for static type checking (inspired by this video from Wolt Tech Talks youtube channel)
  • Code is formatted using Black
  • Necessary commands use invokes

Installing / Getting started

NOTE: If you don't have poetry installed on you system, follow the instructions provided at python-poetry.org/docs

Run these commands in the projects root directory

Install dependencies

poetry install

Enter poetrys virtual environment

poetry shell

Start the server

invoke start

Connection can be checked by visiting 127.0.0.1:8000

Make the POST requests to http://127.0.0.1:8000/api/calculate_delivery_fee

Successfull requests are responded to with code 200 and a json e.g {"delivery_fee": 710}

If the request body or its fields are invalid, the request is responded to with error code 422 with a response body with further details

Tests etc:

Enter poetrys virtual environment with poetry shell before running these

Tests are run with

invoke test

Coverage report

invoke coverage-report

Check for formatting errors

invoke black-check

Type check

invoke mypy

About

Backend code challenge for Wolt Internship


Languages

Language:Python 100.0%