~barry/mailman/templatecache

« back to all changes in this revision

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

  • Committer: Barry Warsaw
  • Date: 2012-10-31 16:37:22 UTC
  • mfrom: (7178.1.1 work2)
  • Revision ID: barry@list.org-20121031163722-3lszhsiv9ai0akfp
 * Python 2.7 is not required.  Python 2.6 is no longer officially supported.
   The code base is now also `python2.7 -3` clean, although there are still
   some warnings in 3rd party dependencies.  LP: #1073506

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
    def test_try_to_join_missing_list(self):
52
52
        # A user tries to join a non-existent list.
53
 
        try:
54
 
            # For Python 2.6.
 
53
        with self.assertRaises(HTTPError) as cm:
55
54
            call_api('http://localhost:9001/3.0/members', {
56
55
                'list_id': 'missing.example.com',
57
56
                'subscriber': 'nobody@example.com',
58
57
                })
59
 
        except HTTPError as exc:
60
 
            self.assertEqual(exc.code, 400)
61
 
            self.assertEqual(exc.msg, 'No such list')
62
 
        else:
63
 
            raise AssertionError('Expected HTTPError')
 
58
        self.assertEqual(cm.exception.code, 400)
 
59
        self.assertEqual(cm.exception.msg, 'No such list')
64
60
 
65
61
    def test_try_to_leave_missing_list(self):
66
62
        # A user tries to leave a non-existent list.
67
 
        try:
68
 
            # For Python 2.6.
 
63
        with self.assertRaises(HTTPError) as cm:
69
64
            call_api('http://localhost:9001/3.0/lists/missing@example.com'
70
65
                     '/member/nobody@example.com',
71
66
                     method='DELETE')
72
 
        except HTTPError as exc:
73
 
            self.assertEqual(exc.code, 404)
74
 
            self.assertEqual(exc.msg, '404 Not Found')
75
 
        else:
76
 
            raise AssertionError('Expected HTTPError')
 
67
        self.assertEqual(cm.exception.code, 404)
 
68
        self.assertEqual(cm.exception.msg, '404 Not Found')
77
69
 
78
70
    def test_try_to_leave_list_with_bogus_address(self):
79
71
        # Try to leave a mailing list using an invalid membership address.
80
 
        try:
81
 
            # For Python 2.6.
 
72
        with self.assertRaises(HTTPError) as cm:
82
73
            call_api('http://localhost:9001/3.0/members/1', method='DELETE')
83
 
        except HTTPError as exc:
84
 
            self.assertEqual(exc.code, 404)
85
 
            self.assertEqual(exc.msg, '404 Not Found')
86
 
        else:
87
 
            raise AssertionError('Expected HTTPError')
 
74
        self.assertEqual(cm.exception.code, 404)
 
75
        self.assertEqual(cm.exception.msg, '404 Not Found')
88
76
 
89
77
    def test_try_to_leave_a_list_twice(self):
90
78
        with transaction():
96
84
        # content.
97
85
        self.assertEqual(content, None)
98
86
        self.assertEqual(response.status, 204)
99
 
        try:
100
 
            # For Python 2.6.
 
87
        with self.assertRaises(HTTPError) as cm:
101
88
            call_api(url, method='DELETE')
102
 
        except HTTPError as exc:
103
 
            self.assertEqual(exc.code, 404)
104
 
            self.assertEqual(exc.msg, '404 Not Found')
105
 
        else:
106
 
            raise AssertionError('Expected HTTPError')
 
89
        self.assertEqual(cm.exception.code, 404)
 
90
        self.assertEqual(cm.exception.msg, '404 Not Found')
107
91
 
108
92
    def test_try_to_join_a_list_twice(self):
109
93
        with transaction():
110
94
            anne = self._usermanager.create_address('anne@example.com')
111
95
            self._mlist.subscribe(anne)
112
 
        try:
113
 
            # For Python 2.6.
 
96
        with self.assertRaises(HTTPError) as cm:
114
97
            call_api('http://localhost:9001/3.0/members', {
115
98
                'list_id': 'test.example.com',
116
99
                'subscriber': 'anne@example.com',
117
100
                })
118
 
        except HTTPError as exc:
119
 
            self.assertEqual(exc.code, 409)
120
 
            self.assertEqual(exc.msg, 'Member already subscribed')
121
 
        else:
122
 
            raise AssertionError('Expected HTTPError')
 
101
        self.assertEqual(cm.exception.code, 409)
 
102
        self.assertEqual(cm.exception.msg, 'Member already subscribed')
123
103
 
124
104
    def test_join_with_invalid_delivery_mode(self):
125
 
        try:
 
105
        with self.assertRaises(HTTPError) as cm:
126
106
            call_api('http://localhost:9001/3.0/members', {
127
107
                'list_id': 'test.example.com',
128
108
                'subscriber': 'anne@example.com',
129
109
                'display_name': 'Anne Person',
130
110
                'delivery_mode': 'invalid-mode',
131
111
                })
132
 
        except HTTPError as exc:
133
 
            self.assertEqual(exc.code, 400)
134
 
            self.assertEqual(exc.msg,
135
 
                             'Cannot convert parameters: delivery_mode')
136
 
        else:
137
 
            raise AssertionError('Expected HTTPError')
 
112
        self.assertEqual(cm.exception.code, 400)
 
113
        self.assertEqual(cm.exception.msg,
 
114
                         'Cannot convert parameters: delivery_mode')
138
115
 
139
116
    def test_join_email_contains_slash(self):
140
117
        content, response = call_api('http://localhost:9001/3.0/members', {
196
173
 
197
174
    def test_get_nonexistent_member(self):
198
175
        # /members/<bogus> returns 404
199
 
        try:
200
 
            # For Python 2.6
 
176
        with self.assertRaises(HTTPError) as cm:
201
177
            call_api('http://localhost:9001/3.0/members/bogus')
202
 
        except HTTPError as exc:
203
 
            self.assertEqual(exc.code, 404)
204
 
        else:
205
 
            raise AssertionError('Expected HTTPError')
 
178
        self.assertEqual(cm.exception.code, 404)
206
179
 
207
180
    def test_patch_nonexistent_member(self):
208
181
        # /members/<missing> PATCH returns 404
209
 
        try:
210
 
            # For Python 2.6
 
182
        with self.assertRaises(HTTPError) as cm:
211
183
            call_api('http://localhost:9001/3.0/members/801', method='PATCH')
212
 
        except HTTPError as exc:
213
 
            self.assertEqual(exc.code, 404)
214
 
        else:
215
 
            raise AssertionError('Expected HTTPError')
 
184
        self.assertEqual(cm.exception.code, 404)
216
185
 
217
186
    def test_patch_member_bogus_attribute(self):
218
187
        # /members/<id> PATCH 'bogus' returns 400
219
188
        with transaction():
220
189
            anne = self._usermanager.create_address('anne@example.com')
221
190
            self._mlist.subscribe(anne)
222
 
        try:
223
 
            # For Python 2.6
 
191
        with self.assertRaises(HTTPError) as cm:
224
192
            call_api('http://localhost:9001/3.0/members/1', {
225
193
                     'powers': 'super',
226
194
                     }, method='PATCH')
227
 
        except HTTPError as exc:
228
 
            self.assertEqual(exc.code, 400)
229
 
            self.assertEqual(exc.msg, 'Unexpected parameters: powers')
230
 
        else:
231
 
            raise AssertionError('Expected HTTPError')
 
195
        self.assertEqual(cm.exception.code, 400)
 
196
        self.assertEqual(cm.exception.msg, 'Unexpected parameters: powers')
232
197
 
233
198
    def test_member_all_without_preferences(self):
234
199
        # /members/<id>/all should return a 404 when it isn't trailed by
235
200
        # `preferences`
236
 
        try:
237
 
            # For Python 2.6
 
201
        with self.assertRaises(HTTPError) as cm:
238
202
            call_api('http://localhost:9001/3.0/members/1/all')
239
 
        except HTTPError as exc:
240
 
            self.assertEqual(exc.code, 404)
241
 
        else:
242
 
            raise AssertionError('Expected HTTPError')
 
203
        self.assertEqual(cm.exception.code, 404)