3
# Copyright (C) 2010-2014 by the Free Software Foundation, Inc.
5
# This file is part of mailman.client.
7
# mailman.client is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU Lesser General Public License as published by the
9
# Free Software Foundation, version 3 of the License.
11
# mailman.client is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
# License for more details.
16
# You should have received a copy of the GNU Lesser General Public License
17
# along with mailman.client. If not, see <http://www.gnu.org/licenses/>.
23
from core.users import Users, UserException
25
sys.path = [os.path.abspath(os.path.dirname(__file__)) +
26
'/../../cli/'] + sys.path
27
from core.users import Users, UserException
28
from lib.mailman_utils import MailmanUtils
31
class TestCreateUser(unittest.TestCase):
33
utils = MailmanUtils()
37
self.client = self.utils.connect()
38
self.users = Users(self.client)
39
self.test_user = 'a@' + self.utils.get_random_string(5) + '.org'
40
self.new_users.append(self.test_user)
41
self.client.create_user(email=self.test_user,
44
self.test_list = self.client.lists[0]
45
self.test_list.subscribe(self.test_user)
47
# Test if user created else setup fails.
48
self.client.get_user(self.test_user)
50
def test_normal_create(self):
52
new_user = 'a@' + self.utils.get_random_string(5) + '.org'
53
self.new_users.append(new_user)
54
args['email'] = new_user
55
args['password'] = 'abc'
57
self.users.create(args)
58
self.assertRaises(UserException, self.users.create, args)
60
def test_create_existent_user(self):
62
args['email'] = self.test_user
63
args['password'] = 'abc'
65
self.assertRaises(UserException, self.users.create, args)
68
for user in self.new_users:
70
u = self.client.get_user(user)
72
except Exception as e:
76
class TestSubscription(unittest.TestCase):
78
utils = MailmanUtils()
83
self.client = self.utils.connect()
84
self.users = Users(self.client)
86
self.test_domain = self.utils.get_new_domain_name()
87
self.domain_list.append(self.test_domain)
88
self.client.create_domain(self.test_domain)
90
self.test_user = self.utils.get_random_string(8) + '@domain.org'
91
self.new_users.append(self.test_user)
92
self.client.create_user(email=self.test_user,
95
self.client.get_user(self.test_user)
96
domain = self.client.get_domain(self.test_domain)
97
self.test_list = (self.utils.get_random_string(8) +
98
'@' + self.test_domain)
99
domain.create_list(self.test_list.split('@')[0])
101
# Test if user created else setup fails.
102
self.client.get_user(self.test_user)
104
def test_subscribe_to_list(self):
106
_list = self.client.get_list(self.test_list)
107
nmembers = len(_list.members)
109
args['users'] = ['a@b.com', 'b@c.com', 'd@e.com']
110
self.new_users.extend(args['users'])
111
args['list_name'] = self.test_list
112
args['quiet'] = False
113
self.users.subscribe(args)
114
self.assertEqual(nmembers + 3, len(_list.members))
117
for i in self.new_users:
119
user = self.client.get_user(i)
123
for i in self.domain_list:
125
self.client.delete_domain(i)