Code Monkey home page Code Monkey logo

django-and-djangorestframework-pytest-tutorial's Introduction

Welcome to Pytest Django and DRF Tutorial ๐Ÿฆ„

This tutorial series is dedicated to exploring the basics of inbuilt Django testing and introduces Pytest and its various plugins to help us write better code

Currently we cover the following:

  • Code coverage,
  • Generating fixtures using Mixer
  • Complex testing of edge-cases using Hypothesis
  • Testing Serializers
  • Testing DRF Views
  • DRF authentication testing
  • Github Actions

Additional Resources

Installation ๐Ÿ“ฅ

mkdir <my_project>

cd my_project

git clone https://github.com/geoffreynyaga/django-and-djangorestframework-pytest-tutorial.git .

Testing setup๐Ÿงช๐Ÿงช

The projects uses pytest and black as the formatting option. The tests also check for consistencies on code format.

To initiate tests follow the steps below:

  1. Its advised to create a virtual environment in the root folder

    virtualenv venv
  2. Activate the environent.

    a. For Linux/MacOS users use the command below

    source venv/bin/activate

    b. for windows users

    cd venv/Scripts
    
    activate.bat
  3. Install the requirements

    pip install -r requirements.txt
  4. Run the pytest command

    pytest

The testing results will be displayed and there will also be a htmlcov folder generated inside the project that will contain the code coverage details.

    .
    โ”œโ”€โ”€ accounts
    โ”‚   โ”œโ”€โ”€ api
    โ”‚   โ”‚   โ””โ”€โ”€ tests
    โ”‚   โ””โ”€โ”€ migrations
    โ”œโ”€โ”€ classroom
    โ”œโ”€โ”€ htmlcov
    โ””โ”€โ”€ venv

Open up the folder and open the index.html in your browser to see this information.

Project layout

    .
    โ”œโ”€โ”€ accounts
    โ”‚   โ”œโ”€โ”€ api
    โ”‚   โ”‚   โ””โ”€โ”€ tests
    โ”‚   โ””โ”€โ”€ migrations
    โ”œโ”€โ”€ classroom
    โ”œโ”€โ”€ htmlcov
    โ””โ”€โ”€ venv # after you create the virtualenv

django-and-djangorestframework-pytest-tutorial's People

Contributors

dependabot[bot] avatar geoffreynyaga avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.