1 # Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
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)
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
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/>.
18 """REST root object tests."""
20 from __future__
import absolute_import
, unicode_literals
31 from urllib2
import HTTPError
33 from mailman
.config
import config
34 from mailman
.testing
.helpers
import call_api
35 from mailman
.testing
.layers
import RESTLayer
39 class TestSystem(unittest
.TestCase
):
42 def test_system_url_too_long(self
):
43 # /system/foo/bar is not allowed.
44 with self
.assertRaises(HTTPError
) as cm
:
45 call_api('http://localhost:9001/3.0/system/foo/bar')
46 self
.assertEqual(cm
.exception
.code
, 400)
48 def test_system_url_not_preferences(self
):
49 # /system/foo where `foo` is not `preferences`.
50 with self
.assertRaises(HTTPError
) as cm
:
51 call_api('http://localhost:9001/3.0/system/foo')
52 self
.assertEqual(cm
.exception
.code
, 400)
54 def test_system_preferences_are_read_only(self
):
55 # /system/preferences are read-only.
56 with self
.assertRaises(HTTPError
) as cm
:
57 call_api('http://localhost:9001/3.0/system/preferences', {
58 'acknowledge_posts': True,
60 self
.assertEqual(cm
.exception
.code
, 405)
61 # /system/preferences are read-only.
62 with self
.assertRaises(HTTPError
) as cm
:
63 call_api('http://localhost:9001/3.0/system/preferences', {
64 'acknowledge_posts': False,
65 'delivery_mode': 'regular',
66 'delivery_status': 'enabled',
68 'preferred_language': 'en',
69 'receive_list_copy': True,
70 'receive_own_postings': True,
72 self
.assertEqual(cm
.exception
.code
, 405)
74 def test_queue_directory(self
):
75 # The REST runner is not queue runner, so it should not have a
76 # directory in var/queue.
77 queue_directory
= os
.path
.join(config
.QUEUE_DIR
, 'rest')
78 self
.assertFalse(os
.path
.isdir(queue_directory
))