Skip to content

shakaran/django-cms-am

Repository files navigation

Django CMS Agile Monkeys Hiring Test

This repo covers a Agile Monkeys hiring recruiting test for a Django app

Maintenance contributions welcome Contributor Covenant Build Status License: AGPL v3 Conventional Commits Integration tests

πŸš€ Environment Setup

🐳 Needed tools

  • Python 3

πŸ› οΈ Environment configuration

Enable virtualenv enviroment for app repo:

python3 -m venv env
source env/bin/activate

πŸ‘©β€πŸ’» Project explanation

This repository contains a simple Django App with a Django REST API for customers.

πŸ”₯ Application execution

It is fully dockerized, with a .env.sample file where you can customize your credentials so run first time with:

docker-compose up --build

Or by steps:

docker-compose build
docker-compose up

After than run the migrations for first time with:

docker-compose exec web python manage.py migrate

Then create a "root" superuser with:

docker-compose exec web python manage.py createsuperuser

The static files could be collected with:

docker-compose exec web python manage.py collectstatic --noinput

To enter to Django container web app:

docker-compose exec -it web bash

Access the application at http://0.0.0.0/:8000 in your web browser.

Use the provided Django admin interface by visiting http://0.0.0.0:8000/admin and logging in with the superuser credentials.

βœ… Tests execution

You can run the test with:

docker-compose exec web python manage.py test

Create an application oauth at /admin/oauth2_provider/application/

Test with curl:

Authenticate a customer:

curl -X POST http://0.0.0.0:8000/auth/token/ \
-d "grant_type=password&username=test&password=test&client_id=your_client_id&client_secret=your_client_secret"
curl -X POST http://0.0.0.0:8000/auth/token/ \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=password&username=testuser&password=testpassword&client_id=your-client-id&client_secret=your-client-secret"

List all customers (GET /customers/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X GET http://0.0.0.0:8000/customers/

Get details about a specific customer (GET /customers/{id}/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X GET http://0.0.0.0:8000/customers/1/

Create a new customer (POST /customers/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X POST http://0.0.0.0:8000/customers/ \
     -F "name=John" \
     -F "surname=Doe" \
     -F "customer_id=12345" \
     -F "photo=@/path/to/photo.jpg"

Update an existant customer (PUT /customers/{id}/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X PUT http://0.0.0.0:8000/customers/1/ \
     -F "name=Jane" \
     -F "surname=Doe" \
     -F "customer_id=67890" \
     -F "photo=@/path/to/new_photo.jpg"

Delete a customer (DELETE /customers/{id}/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X DELETE http://0.0.0.0:8000/customers/1/

List all users (GET /users/)

This endpoint is only available for admin users.

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X GET http://0.0.0.0:8000/users/

Create a new user (POST /users/)

 curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X POST http://0.0.0.0:8000/users/ \
     -d "username=newuser&[email protected]&password=newpassword"

Update an existant user (POST /users/) (PUT /users/{id}/)

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X PUT http://0.0.0.0:8000/users/1/ \
     -d "username=updateduser&[email protected]"

Delete a user (DELETE /users/{id}/)

     curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -X DELETE http://0.0.0.0:8000/users/1/

Postman collection

There are a provided Postman collection for easy integration with all endpoints prefilled.

About

Django CMS Agile Monkeys Coding Hiring Test

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published