Commit | Line | Data |
---|---|---|
ef30978a CAW |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011 Free Software Foundation, Inc | |
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 | ||
17 | import pkg_resources | |
18 | ||
19 | from mediagoblin import celery_setup | |
20 | ||
21 | ||
22 | def test_setup_celery_from_config(): | |
23 | def _wipe_testmodule_clean(module): | |
24 | vars_to_wipe = [ | |
25 | var for var in dir(module) | |
26 | if not var.startswith('__') and not var.endswith('__')] | |
27 | for var in vars_to_wipe: | |
28 | delattr(module, var) | |
29 | ||
ef30978a CAW |
30 | celery_setup.setup_celery_from_config( |
31 | {}, | |
32 | {'something': {'or': 'other'}, | |
33 | 'celery': {'some_variable': 'floop', | |
34 | 'mail_port': '2000', | |
35 | 'CELERYD_ETA_SCHEDULER_PRECISION': '1.3', | |
36 | 'celery_result_persistent': 'true', | |
37 | 'celery_imports': 'foo.bar.baz this.is.an.import'}}, | |
38 | 'mediagoblin.tests.fake_celery_module', set_environ=False) | |
39 | ||
40 | from mediagoblin.tests import fake_celery_module | |
41 | assert fake_celery_module.SOME_VARIABLE == 'floop' | |
42 | assert fake_celery_module.MAIL_PORT == 2000 | |
43 | assert isinstance(fake_celery_module.MAIL_PORT, int) | |
44 | assert fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION == 1.3 | |
45 | assert isinstance(fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION, float) | |
46 | assert fake_celery_module.CELERY_RESULT_PERSISTENT is True | |
47 | assert fake_celery_module.CELERY_IMPORTS == [ | |
88816492 | 48 | 'foo.bar.baz', 'this.is.an.import', 'mediagoblin.process_media'] |
ef30978a CAW |
49 | assert fake_celery_module.CELERY_MONGODB_BACKEND_SETTINGS == { |
50 | 'database': 'mediagoblin'} | |
51 | assert fake_celery_module.CELERY_RESULT_BACKEND == 'mongodb' | |
52 | assert fake_celery_module.BROKER_BACKEND == 'mongodb' | |
524c8f34 CAW |
53 | |
54 | _wipe_testmodule_clean(fake_celery_module) | |
55 | ||
56 | celery_setup.setup_celery_from_config( | |
57 | {'db_host': 'mongodb.example.org', | |
58 | 'db_port': '8080', | |
59 | 'db_name': 'captain_lollerskates', | |
60 | 'celery_section': 'vegetable'}, | |
61 | {'something': {'or': 'other'}, | |
62 | 'vegetable': {'some_variable': 'poolf', | |
63 | 'mail_port': '2020', | |
64 | 'CELERYD_ETA_SCHEDULER_PRECISION': '3.1', | |
65 | 'celery_result_persistent': 'false', | |
66 | 'celery_imports': 'baz.bar.foo import.is.a.this'}}, | |
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 == [ | |
88816492 | 77 | 'baz.bar.foo', 'import.is.a.this', 'mediagoblin.process_media'] |
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 |