Bump version to 1.3.6 and update NEWS.rst for 1.3.5
[mailman-postorious.git] / src / postorius / tests / mailman_api_tests / test_middleware.py
blob58f4c5948804749664f99003776af4f14ff7585d
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-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.
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
14 # more details.
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.test import RequestFactory, TestCase
21 # from django.urls import reverse
23 # import mock
24 # from mailmanclient import MailmanConnectionError
26 # from postorius.models import MailmanApiError
29 # class TestMiddleware(TestCase):
31 # def setUp(self):
32 # self.factory = RequestFactory()
34 # @mock.patch('requests.request')
35 # @mock.patch('postorius.views.list.list_index')
36 # def test_middleware_request(self, mock_request, mock_list_index):
37 # # Mock the view function to raise MailmanApiError and verify
38 # # the behavior of the middleware function.
39 # mock_list_index.side_effect = MailmanApiError
40 # response = self.client.get(reverse('list_index'))
41 # # Check that correct error page is rendered.
42 # self.assertEqual('Mailman REST API not available. Please start Mailman core.', # noqa
43 # response.context['error'])
44 # mock_list_index.reset_mock()
45 # # Check similar semantics with MailmanConnectionError from
46 # # mailmanclient.
47 # mock_list_index.side_effect = MailmanConnectionError
48 # response = self.client.get(reverse('list_index'))
49 # self.assertEqual('Mailman REST API not available. Please start Mailman core.', # noqa
50 # response.context['error'])