b13adae6147cbbcce2fcdb05fbd5637b005633ca
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
19 from mediagoblin
.init
import config
22 CARROT_CONF_GOOD
= pkg_resources
.resource_filename(
23 'mediagoblin.tests', 'fake_carrot_conf_good.ini')
24 CARROT_CONF_EMPTY
= pkg_resources
.resource_filename(
25 'mediagoblin.tests', 'fake_carrot_conf_empty.ini')
26 CARROT_CONF_BAD
= pkg_resources
.resource_filename(
27 'mediagoblin.tests', 'fake_carrot_conf_bad.ini')
28 FAKE_CONFIG_SPEC
= pkg_resources
.resource_filename(
29 'mediagoblin.tests', 'fake_config_spec.ini')
32 def test_read_mediagoblin_config():
34 this_conf
, validation_results
= config
.read_mediagoblin_config(
35 CARROT_CONF_EMPTY
, FAKE_CONFIG_SPEC
)
37 assert this_conf
['carrotapp']['carrotcake'] == False
38 assert this_conf
['carrotapp']['num_carrots'] == 1
39 assert 'encouragement_phrase' not in this_conf
['carrotapp']
40 assert this_conf
['celery']['EAT_CELERY_WITH_CARROTS'] == True
43 this_conf
, validation_results
= config
.read_mediagoblin_config(
44 CARROT_CONF_GOOD
, FAKE_CONFIG_SPEC
)
46 assert this_conf
['carrotapp']['carrotcake'] == True
47 assert this_conf
['carrotapp']['num_carrots'] == 88
48 assert this_conf
['carrotapp']['encouragement_phrase'] == \
49 "I'd love it if you eat your carrots!"
50 assert this_conf
['carrotapp']['blah_blah'] == "blah!"
51 assert this_conf
['celery']['EAT_CELERY_WITH_CARROTS'] == False
54 this_conf
, validation_results
= config
.read_mediagoblin_config(
55 CARROT_CONF_BAD
, FAKE_CONFIG_SPEC
)
57 # These should still open but will have errors that we'll test for
58 # in test_generate_validation_report()
59 assert this_conf
['carrotapp']['carrotcake'] == 'slobber'
60 assert this_conf
['carrotapp']['num_carrots'] == 'GROSS'
61 assert this_conf
['carrotapp']['encouragement_phrase'] == \
63 assert this_conf
['carrotapp']['blah_blah'] == "blah!"
64 assert this_conf
['celery']['EAT_CELERY_WITH_CARROTS'] == "pants"
67 def test_generate_validation_report():
69 this_conf
, validation_results
= config
.read_mediagoblin_config(
70 CARROT_CONF_EMPTY
, FAKE_CONFIG_SPEC
)
71 report
= config
.generate_validation_report(this_conf
, validation_results
)
75 this_conf
, validation_results
= config
.read_mediagoblin_config(
76 CARROT_CONF_GOOD
, FAKE_CONFIG_SPEC
)
77 report
= config
.generate_validation_report(this_conf
, validation_results
)
81 this_conf
, validation_results
= config
.read_mediagoblin_config(
82 CARROT_CONF_BAD
, FAKE_CONFIG_SPEC
)
83 report
= config
.generate_validation_report(this_conf
, validation_results
)
85 assert report
.startswith("""\
86 There were validation problems loading this config file:
87 --------------------------------------------------------""")
90 'carrotapp:carrotcake = the value "slobber" is of the wrong type.',
91 'carrotapp:num_carrots = the value "GROSS" is of the wrong type.',
92 'celery:EAT_CELERY_WITH_CARROTS = the value "pants" is of the wrong type.']
93 warnings
= report
.splitlines()[2:]
95 assert len(warnings
) == 3
96 for warning
in expected_warnings
:
97 assert warning
in warnings