Пример #1
0
 def test_passes_args_to_serializer_init(self):
     setup_encrypted_serializer(self.key)
     self.assertEqual(1, self.register_mock.call_count)
     self.encrypted_serializer_mock.assert_called_once_with(
         key=self.key,
         serializer='pickle',
     )
Пример #2
0
 def test_kombu_serializer_registration(self):
     setup_encrypted_serializer(key=self.key, serializer='pickle')
     self.register_mock.assert_called_once_with(
         'encrypted_pickle',
         self.encrypted_serializer_mock_instance.serialize,
         self.encrypted_serializer_mock_instance.deserialize,
         content_type='application/x-encrypted-pickle',
         content_encoding='utf-8',
     )
Пример #3
0
 def test_name_reflects_serializer_by_default(self):
     name = setup_encrypted_serializer(self.key, serializer='json')
     self.assertEqual(name, 'encrypted_json')
     self.register_mock.assert_called_once_with(
         'encrypted_json',
         self.encrypted_serializer_mock_instance.serialize,
         self.encrypted_serializer_mock_instance.deserialize,
         content_type='application/x-encrypted-json',
         content_encoding='utf-8',
     )
Пример #4
0
import os

from celery import Celery
from kombu_encrypted_serializer import setup_encrypted_serializer

TEST_KEY = 'WgFNqB8eokKER0aFxEmfnK7qyZmGhGmxxOqccW3oZoM='
os.environ['KOMBU_ENCRYPTED_SERIALIZER_KEY'] = TEST_KEY

serializer_name = setup_encrypted_serializer(serializer='pickle')

app = Celery('tasks', broker='redis://', backend='redis://')
app.conf.update(
    CELERY_TASK_SERIALIZER=serializer_name,
    CELERY_RESULT_SERIALIZER=serializer_name,
    CELERY_ACCEPT_CONTENT=[serializer_name],
)


@app.task
def add(x, y):
    return x + y


@app.task
def give_it_back(data):
    return data
Пример #5
0
 def test_calls_kombu_registry_register(self):
     setup_encrypted_serializer(self.key)
     self.assertEqual(1, self.register_mock.call_count)