Bump copyright year
[mailman-postorious.git] / src / postorius / tests / test_error_pages.py
blob22f4852ca3312700d36b02ff7ffba39332a73450
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-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)
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/>.
19 from unittest.mock import patch
21 from django.contrib.auth.models import User
22 from django.test import TestCase
24 from mailmanclient import Client
27 def server_error(requset):
28 raise Exception()
31 class TestUtils(TestCase):
33 def test_404_page(self):
34 response = self.client.get('/postorius/not-here', follow=True)
35 self.assertEqual(response.status_code, 404)
36 self.assertTrue(
37 '<h1>Page not found</h1>' in str(response.content))
38 self.assertTrue(
39 '<div class="alert alert-danger">' in str(response.content))
41 @patch.object(Client, 'get_list')
42 def test_403_page(self, mock_get_list):
43 user = User.objects.create_user(
44 'testuser', 'test@example.com', 'testpass')
45 self.client.force_login(user)
46 response = self.client.get(
47 '/postorius/lists/foolist.example.org/settings/', follow=True)
48 self.assertEqual(response.status_code, 403)
49 self.assertTrue(
50 '<h1>Forbidden</h1>' in str(response.content))
51 self.assertTrue(
52 '<div class="alert alert-danger">' in str(response.content))
54 def test_500_page(self):
55 su = User.objects.create_superuser(
56 'su', 'test@example.com', 'testpass')
57 self.client.force_login(su)
58 response = self.client.get('/500', follow=True)
59 self.assertEqual(response.status_code, 500)
60 self.assertTrue(b'<h1>Server error</h1>' in response.content)