1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2023 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/>.
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
):
31 class TestUtils(TestCase
):
32 def test_404_page(self
):
33 response
= self
.client
.get('/postorius/not-here', follow
=True)
34 self
.assertEqual(response
.status_code
, 404)
35 self
.assertTrue('<h1>Page not found</h1>' in str(response
.content
))
37 '<div class="alert alert-danger">' in str(response
.content
)
40 @patch.object(Client
, 'get_list')
41 def test_403_page(self
, mock_get_list
):
42 user
= User
.objects
.create_user(
43 '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
49 self
.assertEqual(response
.status_code
, 403)
50 self
.assertTrue('<h1>Forbidden</h1>' in str(response
.content
))
52 '<div class="alert alert-danger">' in str(response
.content
)
55 def test_500_page(self
):
56 su
= User
.objects
.create_superuser(
57 'su', 'test@example.com', 'testpass'
59 self
.client
.force_login(su
)
60 response
= self
.client
.get('/500', follow
=True)
61 self
.assertEqual(response
.status_code
, 500)
62 self
.assertTrue(b
'<h1>Server error</h1>' in response
.content
)