Bump version to 1.3.6 and update NEWS.rst for 1.3.5
[mailman-postorious.git] / src / postorius / tests / test_list_view.py
blobd34ac1a2930a1f0c7a07d9975089ac97fd6ebb5e
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012-2021 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)
9 # any later version.
10 # Postorius 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 # Postorius. If not, see <http://www.gnu.org/licenses/>.
19 from django.contrib.messages.storage.base import BaseStorage, Message
20 from django.test import TestCase
21 from django.test.client import RequestFactory
23 from mailmanclient import MailingList
25 from postorius.views.list import ListMembersViews
28 class LocalStorage(BaseStorage):
29 def __init__(self, *args, **kwargs):
30 super().__init__(*args, **kwargs)
31 self._storage = []
33 def _get(self, *args, **kwargs):
34 return self._storage, True
36 def _store(self, messages, response, *args, **kwargs):
37 if messages:
38 self._storage = messages
39 else:
40 self._storage = []
41 return []
44 class TestListView(TestCase):
45 def setUp(self):
46 self.request_factory = RequestFactory()
48 def test_error_message(self):
49 mailing_list_data = {'list_id': 'test_list.example.com'}
50 mailing_list = MailingList(None, None, data=mailing_list_data)
51 view = ListMembersViews(mailing_list=mailing_list)
52 request_data = {
53 'email': ['.*@example.com'],
54 'display_name': ['']
56 request = self.request_factory.post(
57 '/postorius/lists/test_list.example.com/members/nonmember/',
58 data=request_data
60 request._messages = LocalStorage(request)
61 view.post(request, 'test_list.example.com', role='nonmember')
62 self.assertTrue(len(request._messages))
63 self.assertIsInstance(list(request._messages)[0], Message)