~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/rest/tests/test_systemconf.py

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2014 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Test system configuration read-only access."""
 
19
 
 
20
__all__ = [
 
21
    'TestSystemConfiguration',
 
22
    ]
 
23
 
 
24
 
 
25
import unittest
 
26
 
 
27
from mailman.testing.helpers import call_api
 
28
from mailman.testing.layers import RESTLayer
 
29
from six.moves.urllib_error import HTTPError
 
30
 
 
31
 
 
32
 
 
33
class TestSystemConfiguration(unittest.TestCase):
 
34
    layer = RESTLayer
 
35
    maxDiff = None
 
36
 
 
37
    def test_basic_system_configuration(self):
 
38
        # Read some basic system configuration value, just to prove that the
 
39
        # infrastructure works.
 
40
        url = 'http://localhost:9001/3.0/system/configuration/mailman'
 
41
        json, response = call_api(url)
 
42
        # There must be an `http_etag` key, but we don't care about its value.
 
43
        self.assertIn('http_etag', json)
 
44
        del json['http_etag']
 
45
        self.assertEqual(json, dict(
 
46
            site_owner='noreply@example.com',
 
47
            noreply_address='noreply',
 
48
            default_language='en',
 
49
            sender_headers='from from_ reply-to sender',
 
50
            email_commands_max_lines='10',
 
51
            pending_request_life='3d',
 
52
            pre_hook='',
 
53
            post_hook='',
 
54
            layout='testing',
 
55
            filtered_messages_are_preservable='no',
 
56
            ))
 
57
 
 
58
    def test_dotted_section(self):
 
59
        # A dotted section works too.
 
60
        url = 'http://localhost:9001/3.0/system/configuration/language.fr'
 
61
        json, response = call_api(url)
 
62
        # There must be an `http_etag` key, but we don't care about its value.
 
63
        self.assertIn('http_etag', json)
 
64
        del json['http_etag']
 
65
        self.assertEqual(json, dict(
 
66
            description='French',
 
67
            charset='iso-8859-1',
 
68
            enabled='yes',
 
69
            ))
 
70
 
 
71
    def test_multiline(self):
 
72
        # Some values contain multiple lines.  It is up to the client to split
 
73
        # on whitespace.
 
74
        url = 'http://localhost:9001/3.0/system/configuration/nntp'
 
75
        json, response = call_api(url)
 
76
        value = json['remove_headers']
 
77
        self.assertEqual(sorted(value.split()), [
 
78
            'date-received',
 
79
            'nntp-posting-date',
 
80
            'nntp-posting-host',
 
81
            'posted',
 
82
            'posting-version',
 
83
            'received',
 
84
            'relay-version',
 
85
            'x-complaints-to',
 
86
            'x-trace',
 
87
            'xref',
 
88
            ])
 
89
 
 
90
 
 
91
    def test_all_sections(self):
 
92
        # Getting the top level configuration object returns a list of all
 
93
        # existing sections.
 
94
        url = 'http://localhost:9001/3.0/system/configuration'
 
95
        json, response = call_api(url)
 
96
        self.assertIn('http_etag', json)
 
97
        self.assertEqual(sorted(json['sections']), [
 
98
            'antispam',
 
99
            'archiver.mail_archive',
 
100
            'archiver.master',
 
101
            'archiver.mhonarc',
 
102
            'archiver.prototype',
 
103
            'bounces',
 
104
            'database',
 
105
            'devmode',
 
106
            'digests',
 
107
            'language.en',
 
108
            'language.fr',
 
109
            'language.ja',
 
110
            'logging.archiver',
 
111
            'logging.bounce',
 
112
            'logging.config',
 
113
            'logging.database',
 
114
            'logging.debug',
 
115
            'logging.error',
 
116
            'logging.fromusenet',
 
117
            'logging.http',
 
118
            'logging.locks',
 
119
            'logging.mischief',
 
120
            'logging.root',
 
121
            'logging.runner',
 
122
            'logging.smtp',
 
123
            'logging.subscribe',
 
124
            'logging.vette',
 
125
            'mailman',
 
126
            'mta',
 
127
            'nntp',
 
128
            'passwords',
 
129
            'paths.dev',
 
130
            'paths.fhs',
 
131
            'paths.here',
 
132
            'paths.local',
 
133
            'paths.testing',
 
134
            'runner.archive',
 
135
            'runner.bad',
 
136
            'runner.bounces',
 
137
            'runner.command',
 
138
            'runner.digest',
 
139
            'runner.in',
 
140
            'runner.lmtp',
 
141
            'runner.nntp',
 
142
            'runner.out',
 
143
            'runner.pipeline',
 
144
            'runner.rest',
 
145
            'runner.retry',
 
146
            'runner.shunt',
 
147
            'runner.virgin',
 
148
            'shell',
 
149
            'styles',
 
150
            'webservice',
 
151
            ])
 
152
 
 
153
    def test_no_such_section(self):
 
154
        # A bogus section returns a 404.
 
155
        url = 'http://localhost:9001/3.0/system/configuration/nosuchsection'
 
156
        with self.assertRaises(HTTPError) as cm:
 
157
            call_api(url)
 
158
        self.assertEqual(cm.exception.code, 404)
 
159
 
 
160
    def test_too_many_path_components(self):
 
161
        # More than two path components is an error, even if they name a valid
 
162
        # configuration variable.
 
163
        url = 'http://localhost:9001/3.0/system/configuration/mailman/layout'
 
164
        with self.assertRaises(HTTPError) as cm:
 
165
            call_api(url)
 
166
        self.assertEqual(cm.exception.code, 400)
 
167
 
 
168
    def test_read_only(self):
 
169
        # The entire configuration is read-only.
 
170
        url = 'http://localhost:9001/3.0/system/configuration'
 
171
        with self.assertRaises(HTTPError) as cm:
 
172
            call_api(url, {'foo': 'bar'})
 
173
        # 405 is Method Not Allowed.
 
174
        self.assertEqual(cm.exception.code, 405)
 
175
 
 
176
    def test_section_read_only(self):
 
177
        # Sections are also read-only.
 
178
        url = 'http://localhost:9001/3.0/system/configuration/mailman'
 
179
        with self.assertRaises(HTTPError) as cm:
 
180
            call_api(url, {'foo': 'bar'})
 
181
        # 405 is Method Not Allowed.
 
182
        self.assertEqual(cm.exception.code, 405)