Code Monkey home page Code Monkey logo

django-mongodb-testing's Introduction

django-mongodb-testing

Testing app created for the purpose of writing tests in django framework without the hassle of integration and connection with database. It seamlessly integrates the mongodb related process in the django framework and make testing similiar to that of SQL database.

Using the app and integrating in the project

In the settings.py file in django project -

TEST_RUNNER = 'testing.runner.MongodbBaseDiscoverRunner'

MONGO_DATABASE = {
    'default': {
        'NAME': 'database_1',
        'DB_ALIAS': 'database_1',
        'HOST': '0.0.0.0',
        'PORT': '27017',
        'USERNAME': 'user',
        'PASSWORD': 'pass',
        'AUTH': 'admin',
        'TEST': {
            'NAME': 'test_database_1',
            'DB_ALIAS': 'test_database_1'
        }
    }
}

In case of testing database name and alias not specified in MONGO_DATABASE, it will create test database with test_ appended in the development database name and alias

Writing Tests

BaseTestCase is the base class to inherit from to build class based tests. (BaseTest, SimpleTest in python and django). Also need to specify 2 class variables -

  • DOCUMENT_CLASS A tuple containing all the document classes which will get affected from the test. Basically will change the database for these documents to test database.

  • DATA_OBJECT A tuple containing the data as a list of dict objects. These will be stored in database in the begining of the test run.

DATA_OBJECT should contain the data elements list corresponding to the class in DOCUMENT_CLASS. In case of no initial data for a particular document, provide a empty list []

Running Tests

Run the tests using the command ./manage.py test as one would do in django and can also specify app or specific test class which needs to run. This is exact similiar to django flow

Things to remember

This app is configured in a manner that all the database connections and data updates happens in the begining of all the test. This is when collection of all the specified tests happens in django.

Also, only in the end it disconnects from database and drop it

django-mongodb-testing's People

Contributors

kushalmitruka avatar

Stargazers

Masih avatar

Watchers

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