It's 2012 all up in here
[mediagoblin.git] / mediagoblin / tests / test_celery_setup.py
CommitLineData
ef30978a 1# GNU MediaGoblin -- federated, autonomous media hosting
cf29e8a8 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
ef30978a
CAW
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
78e1c5f1
CAW
17import pkg_resources
18
073b61fe 19from mediagoblin.init import celery as celery_setup
421129b6 20from mediagoblin.init.config import read_mediagoblin_config
8abeaf2f
CAW
21
22
23TEST_CELERY_CONF_NOSPECIALDB = pkg_resources.resource_filename(
24 'mediagoblin.tests', 'fake_celery_conf.ini')
25TEST_CELERY_CONF_MGSPECIALDB = pkg_resources.resource_filename(
26 'mediagoblin.tests', 'fake_celery_conf_mgdb.ini')
ef30978a
CAW
27
28
29def test_setup_celery_from_config():
30 def _wipe_testmodule_clean(module):
31 vars_to_wipe = [
32 var for var in dir(module)
33 if not var.startswith('__') and not var.endswith('__')]
34 for var in vars_to_wipe:
35 delattr(module, var)
36
8abeaf2f
CAW
37 global_config, validation_result = read_mediagoblin_config(
38 TEST_CELERY_CONF_NOSPECIALDB)
39 app_config = global_config['mediagoblin']
40
ef30978a 41 celery_setup.setup_celery_from_config(
8abeaf2f 42 app_config, global_config,
ef30978a
CAW
43 'mediagoblin.tests.fake_celery_module', set_environ=False)
44
45 from mediagoblin.tests import fake_celery_module
46 assert fake_celery_module.SOME_VARIABLE == 'floop'
47 assert fake_celery_module.MAIL_PORT == 2000
48 assert isinstance(fake_celery_module.MAIL_PORT, int)
49 assert fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION == 1.3
50 assert isinstance(fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION, float)
51 assert fake_celery_module.CELERY_RESULT_PERSISTENT is True
52 assert fake_celery_module.CELERY_IMPORTS == [
0bce749b 53 'foo.bar.baz', 'this.is.an.import', 'mediagoblin.processing']
ef30978a
CAW
54 assert fake_celery_module.CELERY_MONGODB_BACKEND_SETTINGS == {
55 'database': 'mediagoblin'}
56 assert fake_celery_module.CELERY_RESULT_BACKEND == 'mongodb'
57 assert fake_celery_module.BROKER_BACKEND == 'mongodb'
524c8f34
CAW
58
59 _wipe_testmodule_clean(fake_celery_module)
60
8abeaf2f
CAW
61 global_config, validation_result = read_mediagoblin_config(
62 TEST_CELERY_CONF_MGSPECIALDB)
63 app_config = global_config['mediagoblin']
64
524c8f34 65 celery_setup.setup_celery_from_config(
8abeaf2f 66 app_config, global_config,
524c8f34
CAW
67 'mediagoblin.tests.fake_celery_module', set_environ=False)
68
69 from mediagoblin.tests import fake_celery_module
70 assert fake_celery_module.SOME_VARIABLE == 'poolf'
71 assert fake_celery_module.MAIL_PORT == 2020
72 assert isinstance(fake_celery_module.MAIL_PORT, int)
73 assert fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION == 3.1
74 assert isinstance(fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION, float)
75 assert fake_celery_module.CELERY_RESULT_PERSISTENT is False
76 assert fake_celery_module.CELERY_IMPORTS == [
0bce749b 77 'baz.bar.foo', 'import.is.a.this', 'mediagoblin.processing']
524c8f34
CAW
78 assert fake_celery_module.CELERY_MONGODB_BACKEND_SETTINGS == {
79 'database': 'captain_lollerskates',
80 'host': 'mongodb.example.org',
81 'port': 8080}
82 assert fake_celery_module.CELERY_RESULT_BACKEND == 'mongodb'
83 assert fake_celery_module.BROKER_BACKEND == 'mongodb'
84 assert fake_celery_module.BROKER_HOST == 'mongodb.example.org'
85 assert fake_celery_module.BROKER_PORT == 8080