Giter Club home page Giter Club logo

django-test-ci's Introduction

A demo CI/CD pipeline using Python Django and Pytest

Example Python Django application and CI/CD pipeline for integrating it with GitHub CI/CD. This application demonstrates CRUD operations using class based views in Django. It also includes UI for all CRUD views. And it's based on this tutorial: https://semaphoreci.com/blog/python-continuous-integration-continuous-delivery.

Local project setup

  1. Use virtualenv for setting up this project

  2. Install pip requirements

    pip install -r requirements.txt
    
  3. Create new psql database

    postgres=# create database pydjango;
    
  4. Setup your database credentials and SITE_URL in settings.py file available inside ### core folder

  5. Once you have setup your database, Open command prompt pointing to the Root of the project directory and run following command to create application default database

    (virtualenv / conda environment) > python manage.py migrate
    
    (virtualenv / conda environment) > python manage.py createsuperuser
    
  6. Once all of the above command run sucessfully, We are ready to go. Start server by executing command

    (virtualenv / conda environment) > python manage.py runserver
    

    and visit the web browser with 'http://127.0.0.1:8000'

Environment variables

The following environment variables can be set to override defaults:

  • SECRET_KEY: Django secret key.
  • DB_ENGINE: Django database backend.
  • DB_NAME: database name.
  • DB_HOST: database hostname.
  • DB_PORT: database port.
  • DB_USER: database user.
  • DB_PASSWORD: database password.

CI/CD GIthub

The example pipeline contains 3 blocks:

  • Install Dependencies
    • Installs pip requirements
  • Run Code Analysis
    • Run code analysis / code linting with Pylint
  • Run Unit Tests
    • Runs Unit Tests with pytest module for views and models file

Test with PyTest

To tell pytest witch Django settings that should be used for tests runs, we need to setup a pytest configuration file, called pytest.ini in our project root directory. The file contains:

[pytest]
DJANGO_SETTINGS_MODULE=core.test_settings
addopts = --nomigrations --cov=. --cov-report=html

To run the tests, we can invoke directly pytest command instead of manage.py test. The pytest-django is designed to run with the pytest command, but in case of you want to use manage.py test with pytest-django, you can create a simple test runner.

django-test-ci's People

Contributors

gabicavalcante avatar devyanb avatar

Watchers

James Cloos 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.