Skip to main content

celery-mock allows you to mock celery task and run them when you want

Project description

https://img.shields.io/pypi/v/celery-mock.svg https://img.shields.io/travis/ulamlabs/celery-mock.svg https://codecov.io/gh/ulamlabs/celery-mock/branch/master/graph/badge.svg

celery-mock allows you to mock celery task and then run them when you want

Rationale

Sometimes a celery task retries itself to wait for some event or model to change. This is hard to test because celery tasks run (and retry) inline in tests. Now you can choose when to run your tasks.

Supported versions

  • Python 3 support

  • Celery 3.1.x and 4.0.x support

How to install

pip install celery-mock

How to use

from celery_mock import task_mock
from django.test import TestCase, Client

from myapp import dummyview

class UsersTestCase(TestCase):

    def test_create_user(self):
        client = Client()
        client.post('/api/users/', data={'username': 'konrad')  # runs tasks inline

        with task_mock():
            client.post('/api/users/', data={'username': 'konrad')
            # no tasks started yet
        # all tasks ran here

        with task_mock('myapp.post_user_create_task'):
            client.post('/api/users/', data={'username': 'konrad')
            # all tasks started execept myapp.post_user_create_task
        # myapp.post_user_create_task started here

        # you can use task_mock manually:

        tmock = task_mock().start()
        client.post('/api/users/', data={'username': 'konrad')
        # no tasks started yet
        tomock.stop()  # all tasks ran here

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

celery-mock-1.1.6.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

celery_mock-1.1.6-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file celery-mock-1.1.6.tar.gz.

File metadata

  • Download URL: celery-mock-1.1.6.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.8.5 Darwin/19.6.0

File hashes

Hashes for celery-mock-1.1.6.tar.gz
Algorithm Hash digest
SHA256 62fc56008463b827d982c10c887ece047e1acef145e968b78798c3c11f6a301d
MD5 96a4894f9ba50d4db55bd69cb02250b5
BLAKE2b-256 46f519b1ad0c84d9260ab46e52bed360f069ab2c75b6496c02aa883a63629dde

See more details on using hashes here.

File details

Details for the file celery_mock-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: celery_mock-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.8.5 Darwin/19.6.0

File hashes

Hashes for celery_mock-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 91a5578478d01ec11ad6612fa328805159cf7d4f28c69e9d3a7d3b327bd9fc68
MD5 eb66c2d2a1c7e5b9d202b48807f65c93
BLAKE2b-256 111e830d0fa38c99763b9c2d54cf7bc51877661989a7fdba11df9bd0b51d046c

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