1# -*- coding: utf-8 -*- 2# Copyright (C) 2017-2021 by the Free Software Foundation, Inc. 3# 4# This file is part of Postorius. 5# 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. 10# 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. 15# 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/>. 18# 19from unittest.mock import patch 20 21from django.contrib.auth.models import User 22from django.test import TestCase 23 24from mailmanclient import Client 25 26 27def server_error(requset): 28 raise Exception() 29 30 31class TestUtils(TestCase): 32 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)) 40 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)) 53 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) 61