chore: Bump copyright year
[mailman-postorious.git] / src / postorius / tests / mailman_api_tests / test_nav_helpers.py
blob3bde008427e7536b7cc574e55fb26438f657c0b2
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2019-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)
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 import time
22 from postorius.templatetags.nav_helpers import (
23 held_count,
24 pending_subscriptions,
26 from postorius.tests.utils import ViewTestCase
29 class TestNavigationHelpers(ViewTestCase):
30 def setUp(self):
31 super().setUp()
32 # Create a domain.
33 self.domain = self.mm_client.create_domain('example.com')
34 self.mlist = self.domain.create_list('test_list')
36 def tearDown(self):
37 self.domain.delete()
39 def test_subscription_request_count(self):
40 # Initially, the count of held messages is 0.
41 self.assertEqual(pending_subscriptions(self.mlist), 0)
42 self.mlist.settings['subscription_policy'] = 'moderate'
43 self.mlist.settings.save()
44 self.mlist.subscribe('needsmoderation@example.com', pre_verified=True)
45 self.assertEqual(pending_subscriptions(self.mlist), 1)
46 # Make sure the ones pending user approval don't show up.
47 self.mlist.settings['subscription_policy'] = 'confirm'
48 self.mlist.settings.save()
49 self.mlist.subscribe(
50 'needsconfirmation@example.com', pre_verified=True
52 self.assertEqual(pending_subscriptions(self.mlist), 1)
54 def test_held_message_count(self):
55 # Initially, the count of held messages is 0.
56 self.assertEqual(held_count(self.mlist), 0)
57 # Now, let's inject some message.
58 msg = """\
59 From: nonmember@example.com
60 To: test_list@example.com
61 Subject: What??
62 Message-ID: <moderated_01>
64 Hello.
65 """
66 inq = self.mm_client.queues['in']
67 inq.inject('test_list.example.com', msg)
68 # Wait for the message to be processed.
69 while True:
70 if len(inq.files) == 0:
71 break
72 time.sleep(0.1)
73 # Wait for message to show up in held queue.
74 while True:
75 all_held = self.mlist.held
76 if len(all_held) > 0:
77 break
78 time.sleep(0.1)
80 self.assertEqual(held_count(self.mlist), 1)