~sayan-chowdhury2012/postorius/postorius

« back to all changes in this revision

Viewing changes to src/postorius/tests/mailman_api_tests/test_subscriptions.py

  • Committer: Florian Fuchs
  • Date: 2015-04-17 21:20:47 UTC
  • mfrom: (225.2.24 postorius)
  • Revision ID: flo.fuchs@gmail.com-20150417212047-087j9a6o5smh1oe0
* Added subscription moderation.
* Subscription attempts now show proper messages (subscribed/held for approval).
* Style changes on most forms.
* Removed some cruft from the forms module.
* Style changes on the summary page.
* Added list owner address to summary page.
* Added a note for moderators about non-advertised lists to the list index to avoid confusion. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright (C) 2012-2015 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
# Postorius is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# Postorius.  If not, see <http://www.gnu.org/licenses/>.
 
17
import logging
 
18
 
 
19
from django.contrib.auth.models import User
 
20
from django.core.urlresolvers import reverse
 
21
from django.test import Client, TestCase
 
22
from django.test.utils import override_settings
 
23
from urllib2 import HTTPError
 
24
 
 
25
from postorius.tests import MM_VCR
 
26
from postorius.utils import get_client
 
27
 
 
28
 
 
29
logger = logging.getLogger(__name__)
 
30
vcr_log = logging.getLogger('vcr')
 
31
vcr_log.setLevel(logging.WARNING)
 
32
 
 
33
 
 
34
API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001',
 
35
                   'MAILMAN_USER': 'restadmin',
 
36
                   'MAILMAN_PASS': 'restpass'}
 
37
 
 
38
 
 
39
@override_settings(**API_CREDENTIALS)
 
40
class TestSubscriptionPolicyOpen(TestCase):
 
41
    """Tests for the list members page.
 
42
 
 
43
    Tests permissions and creation of list owners and moderators.
 
44
    """
 
45
 
 
46
    @MM_VCR.use_cassette('test_list_subscription.yaml')
 
47
    def setUp(self):
 
48
        self.client = Client()
 
49
        try:
 
50
            self.domain = get_client().create_domain('example.com')
 
51
        except HTTPError:
 
52
            self.domain = get_client().get_domain('example.com')
 
53
        try:
 
54
            self.test_list = self.domain.create_list('open_list')
 
55
        except HTTPError:
 
56
            self.test_list = get_client().get_list('open_list.example.com')
 
57
        # Set subscription policy to open
 
58
        settings = self.test_list.settings
 
59
        settings['subscription_policy'] = 'open'
 
60
        settings.save()
 
61
        self.user = User.objects.create_user(
 
62
            'testuser', 'test@example.com', 'pwd')
 
63
 
 
64
    @MM_VCR.use_cassette('test_list_subscription.yaml')
 
65
    def tearDown(self):
 
66
        self.test_list.delete()
 
67
        self.user.delete()
 
68
 
 
69
    @MM_VCR.use_cassette('test_list_subscription.yaml')
 
70
    def test_subscribing_adds_member(self):
 
71
        # The subscription goes straight through.
 
72
        self.client.login(username='testuser', password='pwd')
 
73
        response = self.client.post(
 
74
            reverse('list_subscribe', args=('open_list.example.com', )),
 
75
            {'email': 'fritz@example.org'})
 
76
        self.assertEqual(len(self.test_list.members), 1)
 
77
        self.assertEqual(len(self.test_list.requests), 0)
 
78
 
 
79
 
 
80
@override_settings(**API_CREDENTIALS)
 
81
class TestSubscriptionPolicyModerate(TestCase):
 
82
    """Tests for the list members page.
 
83
 
 
84
    Tests permissions and creation of list owners and moderators.
 
85
    """
 
86
 
 
87
    @MM_VCR.use_cassette('test_list_subscription_moderate.yaml')
 
88
    def setUp(self):
 
89
        self.client = Client()
 
90
        try:
 
91
            self.domain = get_client().create_domain('example.com')
 
92
        except HTTPError:
 
93
            self.domain = get_client().get_domain('example.com')
 
94
        try:
 
95
            self.test_list = self.domain.create_list('moderate_subs')
 
96
        except HTTPError:
 
97
            self.test_list = get_client().get_list('moderate_subs.example.com')
 
98
        # Set subscription policy to open
 
99
        settings = self.test_list.settings
 
100
        settings['subscription_policy'] = 'moderate'
 
101
        settings.save()
 
102
        # Create django user.
 
103
        self.user = User.objects.create_user(
 
104
            'testuser', 'test@example.com', 'pwd')
 
105
 
 
106
    @MM_VCR.use_cassette('test_list_subscription_moderate.yaml')
 
107
    def tearDown(self):
 
108
        self.test_list.delete()
 
109
        self.user.delete()
 
110
 
 
111
    @MM_VCR.use_cassette('test_list_subscription_moderate.yaml')
 
112
    def test_subscribing_adds_member(self):
 
113
        # The subscription is held for approval.
 
114
        self.client.login(username='testuser', password='pwd')
 
115
        response = self.client.post(
 
116
            reverse('list_subscribe', args=('moderate_subs.example.com', )),
 
117
            {'email': 'fritz@example.org'})
 
118
        self.assertEqual(len(self.test_list.members), 0)
 
119
        self.assertEqual(len(self.test_list.requests), 1)