feat: List the count of files in queues under System Administration tab.
[mailman-postorious.git] / src / postorius / tests / mailman_api_tests / test_system.py
blob32df50296766cdf456a2355235ae11b0e9b14583
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2018-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/>.
20 from django.contrib.auth.models import User
21 from django.urls import reverse
23 from allauth.account.models import EmailAddress
25 from postorius.tests.utils import ViewTestCase
28 class TestSystemInformationPage(ViewTestCase):
30 def setUp(self):
31 super().setUp()
32 self.superuser = User.objects.create_superuser(
33 'testsu', 'su@example.com', 'testpass')
34 EmailAddress.objects.create(
35 user=self.superuser, email='su@example.com', verified=True)
37 def test_system_info(self):
38 response = self.client.get(reverse('system_information'))
39 # Logged-out users shouldn't be able to get this information.
40 self.assertEqual(response.status_code, 302)
41 # Superuser should have access to this information.
42 self.assertTrue(self.client.login(
43 username='testsu', password='testpass'))
44 response = self.client.get(reverse('system_information'))
45 self.assertEqual(response.status_code, 200)
46 self.assertIn(b'Mailman Core API Version', response.content)
47 self.assertIn(b'Mailman Core Version', response.content)
49 def test_list_queue_info(self):
50 # Test the values inthe queue.
51 self.client.force_login(self.superuser)
52 response = self.client.get(reverse('system_information'))
53 self.assertEqual(response.status_code, 200)
54 self.assertIn('queues', response.context)
55 self.mm_client.create_domain(
56 'example.com').create_list('somelist')
57 badq = self.mm_client.queues.get('bad')
58 badq.inject(
59 'somelist.example.com',
60 'From: abhilash@example.com\nTo:somelist@example.com\n\n Hello')
61 response = self.client.get(reverse('system_information'))
62 self.assertEqual(response.status_code, 200)
63 self.assertIn('queues', response.context)
64 queues = response.context.get('queues')
65 self.assertEqual(queues['bad'], 1)