<commit_before># -*- coding: utf-8 -*-

import mock
from raven.utils.testutils import TestCase
from celery.tests.utils import with_eager_tasks
from raven.contrib.celery import CeleryClient


class ClientTest(TestCase):
    def setUp(self):
        self.client = CeleryClient(servers=['http://example.com'])

    @mock.patch('raven.contrib.celery.CeleryClient.send_raw')
    def test_send_encoded(self, send_raw):
        self.client.send_encoded('foo')

        send_raw.delay.assert_called_once_with('foo')

    @mock.patch('raven.contrib.celery.CeleryClient.send_raw')
    def test_without_eager(self, send_raw):
        """
        Integration test to ensure it propagates all the way down
        and calls delay on the task.
        """
        self.client.captureMessage(message='test')

        self.assertEquals(send_raw.delay.call_count, 1)

    @with_eager_tasks
    @mock.patch('raven.base.Client.send_encoded')
    def test_with_eager(self, send_encoded):
        """
        Integration test to ensure it propagates all the way down
        and calls the parent client's send_encoded method.
        """
        self.client.captureMessage(message='test')

        self.assertEquals(send_encoded.call_count, 1)<commit_msg>Make celery mixin tests work with celery 3.1<commit_after># -*- coding: utf-8 -*-

import mock

from celery.app import app_or_default

from raven.utils.testutils import TestCase
from raven.contrib.celery import CeleryClient


class ClientTest(TestCase):
    def setUp(self):
        self.client = CeleryClient(servers=['http://example.com'])

    @mock.patch('raven.contrib.celery.CeleryClient.send_raw')
    def test_send_encoded(self, send_raw):
        self.client.send_encoded('foo')

        send_raw.delay.assert_called_once_with('foo')

    @mock.patch('raven.contrib.celery.CeleryClient.send_raw')
    def test_without_eager(self, send_raw):
        """
        Integration test to ensure it propagates all the way down
        and calls delay on the task.
        """
        self.client.captureMessage(message='test')

        self.assertEquals(send_raw.delay.call_count, 1)

    @mock.patch('raven.base.Client.send_encoded')
    def test_with_eager(self, send_encoded):
        """
        Integration test to ensure it propagates all the way down
        and calls the parent client's send_encoded method.
        """
        celery_app = app_or_default()
        celery_app.conf.CELERY_ALWAYS_EAGER = True

        self.client.captureMessage(message='test')

        self.assertEquals(send_encoded.call_count, 1)

        celery_app.conf.CELERY_ALWAYS_EAGER = False
{'fraction_non_alphanumeric': 0.10336906584992343, 'fraction_numerical': 0.0030627871362940277, 'mean_word_length': 3.214516129032258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109668', 'n_tokens_mistral': 821, 'n_tokens_neox': 792, 'n_words': 165}