-
Notifications
You must be signed in to change notification settings - Fork 66
/
test_celery.py
103 lines (81 loc) · 2.7 KB
/
test_celery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest
import mock
@pytest.mark.unit
def test_includeme_custom_config():
from pyramid_celery import includeme
from pyramid_celery import celery_app
from pyramid import testing
from pyramid.registry import Registry
config = testing.setUp()
config.registry = Registry()
config.registry.settings = {}
includeme(config)
config.configure_celery('tests/configs/dev.ini')
assert celery_app.conf['BROKER_URL'] == 'redis://localhost:1337/0'
@pytest.mark.unit
def test_includeme_default():
from pyramid_celery import includeme
from pyramid_celery import celery_app
from pyramid import testing
from pyramid.registry import Registry
config = testing.setUp()
config.registry = Registry()
config.registry.settings = {}
includeme(config)
assert celery_app.conf['BROKER_URL'] is None
@pytest.mark.unit
def test_includeme_use_celeryconfig():
from pyramid_celery import includeme
from pyramid_celery import celery_app
from pyramid import testing
from pyramid.registry import Registry
config = testing.setUp()
config.registry = Registry()
config.registry.settings = {}
includeme(config)
config.configure_celery('tests/configs/useceleryconfig.ini')
assert celery_app.conf['BROKER_URL'] == 'redis://localhost:1337/0'
@pytest.mark.unit
def test_preload_no_ini():
from pyramid_celery import on_preload_parsed
options = {
'ini': None,
'ini_var': None,
}
with pytest.raises(SystemExit):
on_preload_parsed(options)
@pytest.mark.unit
def test_preload_ini():
from pyramid_celery import on_preload_parsed
options = {
'ini': 'tests/configs/dev.ini',
'ini_var': None,
}
with mock.patch('pyramid_celery.bootstrap') as boot:
on_preload_parsed(options)
assert boot.called_with('dev.ini')
@pytest.mark.unit
def test_celery_imports():
from pyramid_celery import includeme, celery_app
from pyramid import testing
from pyramid.registry import Registry
config = testing.setUp()
config.registry = Registry()
config.registry.settings = {}
includeme(config)
config.configure_celery('tests/configs/imports.ini')
assert celery_app.conf['CELERY_IMPORTS'] == [
'myapp.tasks',
'otherapp.tasks'
]
@pytest.mark.unit
def test_preload_with_ini_vars():
from pyramid_celery import on_preload_parsed
options = {
'ini': 'tests/configs/dev.ini',
'ini_var': 'database=foo,password=bar',
}
with mock.patch('pyramid_celery.bootstrap') as boot:
on_preload_parsed(options)
expected_vars = {'database': 'foo', 'password': 'bar'}
assert boot.called_with('dev.ini', expected_vars)