1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2018-2022 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
20 from django
.urls
import reverse
22 from postorius
.tests
.utils
import ViewTestCase
25 class AnonymousSubscribeTest(ViewTestCase
):
26 """Tests for anonymous subscribe page."""
30 self
.domain
= self
.mm_client
.create_domain('example.com')
31 self
.foo_list
= self
.domain
.create_list('foo')
33 def test_anonymous_subscribe(self
):
34 url
= reverse('list_anonymous_subscribe', args
=('foo.example.com',))
35 response
= self
.client
.post(url
, dict(email
='aperson@example.com'))
36 self
.assertEqual(response
.status_code
, 302)
37 self
.assertEqual(response
.url
,
38 reverse('list_summary', args
=('foo.example.com',)))
39 # 302 responses have no context, hence we can't check the actual
41 response
= self
.client
.post(url
,
42 dict(email
='bperson@example.com'),
44 success_msg
= list(response
.context
.get('messages'))[0]
45 self
.assertEqual(success_msg
.tags
, 'success')
46 self
.assertEqual(success_msg
.message
,
47 'Please check your inbox for further instructions')
48 # Make sure that there are two pending requests in Mailing List.
49 self
.assertEqual(len(self
.foo_list
.requests
), 2)
50 for req
in self
.foo_list
.requests
:
51 self
.assertEqual(req
['token_owner'], 'subscriber')
52 self
.assertEqual(req
['list_id'], 'foo.example.com')
54 def test_anonymous_subscribe_get(self
):
56 # Test that anonymous subscribe with a GET doesn't raise a 500 error.
57 url
= reverse('list_anonymous_subscribe', args
=('foo.example.com',))
58 response
= self
.client
.get(url
)
59 self
.assertEqual(response
.status_code
, 405)