Skip to main content

asyncio unit tests with Django transactional support.

Project description

asyncio unit tests with Django transactional support.

It supports Django 1.8+ for Python versions 3.5+ and uses asynctest under the covers to provide support for easily mocking coroutines.

Build Status Code Health Code Coverage Documentation Status Latest Version Supported Python versions Downloads

Docs

Available at django-async-test.readthedocs.org

Installation

You can install django-async-test either via the Python Package Index (PyPI) or from github.

To install using pip;

$ pip install django-async-test

From github;

$ pip install git+https://github.com/alexhayes/django-async-test.git

Usage

asynctest.TestCase does a great job of mocking coroutines however if you’re writing tests that manipulate the database in Django you’ll most likely want to ensure that things are cleaned up after your test.

With django_async_test.TestCase you have the coroutine support of asynctest.TestCase but with the transaction support of Django’s django.test.TestCase.

import django_async_test

class MyTestCase(django_async_test.TestCase):

    @django_async_test.patch('myapp.my_coroutine')
    def test_foo(self, MockMyCoroutine):

        # Mock our coroutine.
        MockMyCoroutine.return_value = 'Hello World'

        # Create an instance of MyModel
        MyModel.objects.create(...)

        ...
        ...

In the above example, the test is run inside a transaction by Django’s TestCase, thus the creation of a MyModel will be rolled back, cleaning up the database.

Also, our co-routine will be patched correctly by asynctest.

License

This software is licensed under the MIT License. See the LICENSE file.

Author

Alex Hayes <alex@alution.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-async-test-0.2.2.tar.gz (873.7 kB view details)

Uploaded Source

File details

Details for the file django-async-test-0.2.2.tar.gz.

File metadata

File hashes

Hashes for django-async-test-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f5bab436d9beaab2d699e6cf81cf25a30da68cd56bc1fd459bf151262d24179d
MD5 2c999bdc9f7750e8b0328582e74275c2
BLAKE2b-256 38c4c277ce6f19313c6ab52de220bc618409a49a5a53f8185b667fbab2a25f2d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page