Code Monkey home page Code Monkey logo

mamba-django's Introduction

mamba-django

PyPI pyversions

A Django test runner for mamba.

How to install

pip install mamba-django

How to use

Go to your Django test settings and add this line

TEST_RUNNER = 'mamba_django.MambaRunner'

and then execute the Django tests

./manage.py test --settings=project.settings.test --keepdb

or you can execute the tests passing it as parameter

./manage.py test --testrunner mamba_django.MambaRunner --settings=project.settings.test --keepdb

Also, you can pass all the mamba parameters to the Django test command.

For example:

./manage.py test --settings=project.settings.test --keepdb -f documentation -s 1

How to execute mamba tests with Django database transactions

from expects import (
    equal,
    expect
)

from mamba_django import (
    start_django_transactions,
    rollback_django_transactions
)

from myapp.models import Animal


with description("Mamba with Django") as self:

    with before.each:
        self.transactions = start_django_transactions()

    with context("Running atomic tests"):

        with it("creates an animal"):
            Animal.objects.create(name="lion", sound="roar")
            expect(Animal.objects.all().count()).to(equal(1))

        with it("creates another animal"):
            Animal.objects.create(name="lion", sound="roar")
            expect(Animal.objects.all().count()).to(equal(1))

    with after.each:
        rollback_django_transactions(self.transactions)

How to load Django fixtures

You can use the method load_fixtures to load Django fixtures.

from expects import (
    equal,
    expect
)

from mamba_django import (
    load_fixtures,
    start_django_transactions,
    rollback_django_transactions
)

from django.contrib.auth.models import Group


with description("Mamba with Django") as self:

    with before.each:
        self.transactions = start_django_transactions()
        load_fixtures(['group.json'])

    with context("Fixtures"):

        with it("can retrieve loaded fixtures"):
            expect(Group.objects.all().count()).to(equal(1))

    with after.each:
        rollback_django_transactions(self.transactions)

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.