Bump copyright years.
[mailman.git] / src / mailman / rest / tests / test_root.py
blob96a41edf754db2d67f50dd4488266b3c009a32c9
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)
8 # any later version.
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.
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
22 __metaclass__ = type
23 __all__ = [
24 'TestSystem',
28 import unittest
29 import os
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):
40 layer = RESTLayer
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,
59 }, method='PATCH')
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',
67 'hide_address': True,
68 'preferred_language': 'en',
69 'receive_list_copy': True,
70 'receive_own_postings': True,
71 }, method='PUT')
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))