/Cornershop_Backend_Test

In here I am presenting a solution for the Cornershop's Backend Test challenge, using Django + Celery + RabbitMQ + Docker.

Primary LanguagePythonMIT LicenseMIT

Cornershop's Backend Test solution

Hi there! In this repository you will find my implementation for the Cornershop's Backend Test, using the Django framework.

user_interfase

Resume

This project threats about a webpage to manage daily lunch menus for a comunity of Cornershop employees. Its implementation has been developed using the python Django framework for web developmet. In the next sections you will find the documentation, building instructions and another activities!

Video

You can find a full walkthrough video to see the project features:

Watch the video

Specifications

This project uses background tasks to operate Slack channels integration. In consecuence this development is a synergy of many microservices that help to create a final result:

  • Celery for async tasks setup.
  • RabbitMQ to connect Django and Celery's background tasks
  • Slack to notify reminders if today's menu is available according to Celery's scheduled workflow.
  • Django to develop the web project.
  • Docker to make the project's distribution easier.

Before you continue

About Docker use

This project uses Docker compose integration to build a time saving container. It is highl already have installed Docker and Docker compose services in your computer before keep reading this documentation. If not, you can get involved with a quick tutorial at:

Building instructions

Step 1: Cloning the repository

Start by cloning this repository to your computer by typing the next instruction in your command lines window:

$ git clone https://github.com/JeaustinSirias/Backend-Test-Sirias.git

Once this gets done move to the cloned repository path.

Step 2: Setting up your Slack enviroment

Slack service depends on the group of users where it is running and it requires authentication from the channel administrator, so to integrate this feature to your project you first need to set up your slack enviroment. You can read about how to install a Slack app here. In case you already have your Slack token (OAuth token) with all granted channel scope permissions, then all you have to do is edit the setup.py file inside the project's directory with your credentials:

'''Modifiable parameters of the project'''

# The Slack app token
OAUTH_TOKEN = '<your_token_here>' 

# The Slack channel name
SLACK_CHANNEL = '#<your_channel_name>'

# The hour limit for employees to request their menu
HOUR = 11 # AM CLT

You can also change the scheduled limit hour (HOUR parameter) for the employees request their today's menu option. Once you are done with this, then save changes and let's continue with the next steps!

Step 3: Running the project using Docker service

Make sure you are in the project's root directory and by using your terminal again type the following makefile instruction to build and run the web Cornershop's Backend test:

$ make docker

The image may take some minutes to get done as it downloads all its dependences. If everything went as expected you should be seeing now the HTTP direction of the devepment server as is usual in Django projects just the way the next image shows it:

bash_terminal

Then go to http://0.0.0.0:8000/ to start navigating in the web project.

Step 4: Administration credentials

So at this point the developmet server has you redirected to an authentication page. This is what Nora would actually see if she were the administrator. To login use the next superuser credentials:

  • username: nora
  • password: admin

As you get it done so you will be in front of the main administrative page for Nora just like the next image:

web

Now you can start discovering the webpage features such as creating a menu for today and sending the Slack reminder to the channel you specified in the Step 2. If the project is currenty running OK and the Slack background integration was successfully made, so you will be seeing something like this in your Slack channel as you set up the today's menu:

bash_terminal

At this point if you want to interact with the page as an employee (instead of Nora), so you can use the next common users (non admins) to request today's menu or something by entering to the generated link in the Slack reminder:

  • username: jose, password: jose12345
  • username: ana, password: ana12345

Step 5: Running unittests (optional)

The project counts with a list of unitary tests to make sure that its views, forms, models and celery tasks are running as expected. You can run unittests from the same docker container by typing the next instruction in your bash terminal:

$ make dockerUnittest

Just in case definitely you do not want to use Docker services

If you do not want (or can) use the Docker services, then you can also build a virtual enviroment venv (python 3.7+) as traditionally is made. Make sure you are in the cloned project root directory. In any case you will have to install the project's dependences by using the next command:

$ make requirements

And to run the Django project, as you usually know, from your local or virtual enviroment, type:

$ make run

If you also want to run unittests this way, then use:

$ make unittest

I hope you liked this walkthrough. See you the next time! :)