Skip to content

jourdanrodrigues-tests/test_10

Repository files navigation

HelloFresh Test

Style guides used

Notes

I never needed/wanted to build a bare Python server before this task. Is quite interesting to see what the Frameworks that I often use do underneath.

That said, I want to be completely honest regarding my approaches (that you can check in commits messages/code) and knowledge sources.

Some of what's implemented in the request handler came from here.

Instructions

Running the server

Note: Whenever you run this command, the script for database schema creation is run for your convenience (of course, it wouldn't work like this in production).

docker-compose up

If you don't want to bind the process to the current terminal, run the following:

docker-compose up -d

Running the tests

docker-compose run --rm server pytest

Creating database schema

docker-compose run --rm server python scripts/create_schema.py

Loading mock data

docker-compose run --rm server python scripts/load_mock_data.py

Useful cURL commands for API testing

Note: These cURL commands work after loading the mock data

curl -X GET http://localhost:8080/recipes/ # Retrieve recipe list

curl -X GET http://localhost:8080/recipes/1/ # Retrieve a recipe for the specified ID

curl -X POST \
  http://localhost:8080/recipes/ \
  -H 'Authorization: 1' \
  -H 'Content-Type: application/json' \
  -d '{"name": "A cool recipe", "difficulty": 1, "vegetarian": false, "preparation_time": 15}' # Create a recipe

curl -X PUT \
  http://localhost:8080/recipes/1/ \
  -H 'Authorization: 1' \
  -H 'Content-Type: application/json' \
  -d '{"name": "One fine recipe", "difficulty": 2, "vegetarian": true, "preparation_time": 14}' # Update a recipe with PUT

curl -X PATCH \
  http://localhost:8080/recipes/1/ \
  -H 'Authorization: 1' \
  -H 'Content-Type: application/json' \
  -d '{"name": "One fine recipe", "difficulty": 2, "vegetarian": false, "preparation_time": 13}' # Update a recipe with PATCH

curl -X DELETE http://localhost:8080/recipes/1/ -H 'Authorization: 1' # Delete a recipe

curl -X POST http://localhost:8080/recipes/1/rating/ -H 'Content-Type: application/json' -d '{"value": 2}' # Create a rating for a recipe

About

Bare Python API (HelloFresh)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages