1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012-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)
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
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
)
33 def _get(self
, *args
, **kwargs
):
34 return self
._storage
, True
36 def _store(self
, messages
, response
, *args
, **kwargs
):
38 self
._storage
= messages
44 class TestListView(TestCase
):
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
)
53 'email': ['.*@example.com'],
56 request
= self
.request_factory
.post(
57 '/postorius/lists/test_list.example.com/members/nonmember/',
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
)