1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2012-2015 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)
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
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/>.
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
25
from postorius.tests import MM_VCR
26
from postorius.utils import get_client
29
logger = logging.getLogger(__name__)
30
vcr_log = logging.getLogger('vcr')
31
vcr_log.setLevel(logging.WARNING)
34
API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001',
35
'MAILMAN_USER': 'restadmin',
36
'MAILMAN_PASS': 'restpass'}
39
@override_settings(**API_CREDENTIALS)
40
class TestSubscriptionPolicyOpen(TestCase):
41
"""Tests for the list members page.
43
Tests permissions and creation of list owners and moderators.
46
@MM_VCR.use_cassette('test_list_subscription.yaml')
48
self.client = Client()
50
self.domain = get_client().create_domain('example.com')
52
self.domain = get_client().get_domain('example.com')
54
self.test_list = self.domain.create_list('open_list')
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'
61
self.user = User.objects.create_user(
62
'testuser', 'test@example.com', 'pwd')
64
@MM_VCR.use_cassette('test_list_subscription.yaml')
66
self.test_list.delete()
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)
80
@override_settings(**API_CREDENTIALS)
81
class TestSubscriptionPolicyModerate(TestCase):
82
"""Tests for the list members page.
84
Tests permissions and creation of list owners and moderators.
87
@MM_VCR.use_cassette('test_list_subscription_moderate.yaml')
89
self.client = Client()
91
self.domain = get_client().create_domain('example.com')
93
self.domain = get_client().get_domain('example.com')
95
self.test_list = self.domain.create_list('moderate_subs')
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'
102
# Create django user.
103
self.user = User.objects.create_user(
104
'testuser', 'test@example.com', 'pwd')
106
@MM_VCR.use_cassette('test_list_subscription_moderate.yaml')
108
self.test_list.delete()
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)