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)
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.test import RequestFactory, TestCase
21 # from django.urls import reverse
24 # from mailmanclient import MailmanConnectionError
26 # from postorius.models import MailmanApiError
29 # class TestMiddleware(TestCase):
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
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'])