Sample full stack question - Setting up a Django server and making HTTP calls to validate

Overview

Setting up Django Web Server and validating HTTP calls. The candidate is provided a sample Django application. The folder structure for the project will already be set up with some tasks left in a few files. We will mention those details in the problem statement so the candidate can understand it. Candidates will be evaluated based on completing the configuration and settings for the application such that the server is able to respond to the HTTP requests. Test cases are mentioned in such a way to evaluate if the application is installed in the Django project if the server is able to host application URLs, and if the HTTP requests are returning the correct response.

To learn more about how to create a custom full stack question, read this article.

Sample problem

1. Create a new folder for the project and open it in a code editor.
2. Navigate to Terminal and start a Django project: django-admin startproject myapp   
3. This creates a folder structure similar to the following image:
Screenshot from 2023-05-29 14-39-51 
4. Create a sample app in this project: python manage.py startapp sample
5. Create a view in sample/views.py file by adding the code below. This will be used for candidate evaluation.
class HomeView(APIView):

def get(self, request):
content = {'message': 'Welcome to Django!'}
return Response(content)

6. Now the candidate should be able to write the setting and configuration for ‘sample’ app so that the request to ‘/home’ returns a valid response. Detailed tasks for the candidate to complete are given further in the article.

Tasks for a candidate to complete

  1. Open the settings.py file located in the myapp directory.
  2. Add 'myapp' to the INSTALLED_APPS list to register the app with the Django project.
  3. Make sure backend URLs are included in ROOT_URLCONF constant.
  4. In the project's urls.py file, import the include function from django.urls module.
  5. Add a new URL pattern that includes the sample.urls module. This will map the root URL to the URLs defined in the myapp app.
  6. Add a new URL pattern in sample/urls.py  that includes the URL pattern for ‘home’ view. 

Here is the GitHub link for the project.

Test cases

The following test cases can be added for candidate evaluation:

  1. Check if the candidate was able to successfully configure the settings.py file.
    1. The test case will check if the INSTALLED_APPS in settings.py file includes the ‘sample’ app configuration.
  2. Check if the candidate was able to set up the URLs in ‘sample’ app.
    1. The test case will check whether the ‘/home’ URL is responding to the request.
    2. Test case only gets passed if the response has status code 200.

Technical specifications

  1. Project source: backend
  2. Build commands
      1. pip install -r requirements.txt
      2. python manage.py migrate
  3. Deploy commands: python manage.py run server 0.0.0.0:8000
  4. Sample Evaluation commands: python manage.py test sample_tests
  5. Evaluation commands: python manage.py test tests
  6. Evaluation report path: Xunittest.xml