Merge lp:~jskrzeszewska/systers/systers into lp:systers

Proposed by Joanna Skrzeszewska
Status: Needs review
Proposed branch: lp:~jskrzeszewska/systers/systers
Merge into: lp:systers
Diff against target: 813 lines (+694/-26)
10 files modified
Mailman/DlistUserDesc.py (+5/-22)
Mailman/DlistUtils.py (+20/-4)
tests/DlistTestBase.py (+39/-0)
tests/EmailBase.py (+75/-0)
tests/TestBase.py (+72/-0)
tests/dlist_testall.py (+35/-0)
tests/test_dlist_handlers.py (+185/-0)
tests/test_dlist_membership.py (+111/-0)
tests/test_dlist_userdesc.py (+62/-0)
tests/test_dlist_utils.py (+90/-0)
To merge this branch: bzr merge lp:~jskrzeszewska/systers/systers
Reviewer Review Type Date Requested Status
Nicki Hutchens Pending
Systers Pending
Review via email: mp+173301@code.launchpad.net

Description of the change

I added unit tests for some systers additions to mailman.
I created tests directory which contains:
1. DlistTestBase.py
2. EmailBase.py and TestBase.py (from tests directory for mailman 2.1)
3. dlist_testall.py
4. test_dlist_handlers.py for Mailman/Handlers/Dlists.py
5. test_dlist_membership.py for Mailman/DlistMemberships.py
6. test_dlist_userdesc.py for Mailman/DlistUserDesc.py
7. test_dlist_utils.py for class Subscriber from Mailman/DlistUtils.py

I also added small improvement for function repr from Mailman/DlisUserDesc.py.

To post a comment you must log in.

Unmerged revisions

76. By Joanna Skrzeszewska

Unit tests for systers additions to mailman

75. By Joanna Skrzeszewska

Improvements for repr function in DlistUserDesc.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Mailman/DlistUserDesc.py'
2--- Mailman/DlistUserDesc.py 2009-04-06 19:45:21 +0000
3+++ Mailman/DlistUserDesc.py 2013-07-06 08:38:35 +0000
4@@ -34,25 +34,8 @@
5
6 ## I didn't inherit, I duplicated the work here, as I couldn't figure out how to concatenate the two strings correctly
7 def __repr__(self):
8- address = getattr(self, 'address', 'n/a')
9- fullname = getattr(self, 'fullname', 'n/a')
10- password = getattr(self, 'password', 'n/a')
11- digest = getattr(self, 'digest', 'n/a')
12- if digest == 0:
13- digest = 'no'
14- elif digest == 1:
15- digest = 'yes'
16- language = getattr(self, 'language', 'n/a')
17- essay = getattr(self, 'essay', 'n/a')
18- # Make sure fullname, password and essay are encoded if they're strings
19- if isinstance(fullname, UnicodeType):
20- fullname = fullname.encode('ascii', 'replace')
21- if isinstance(password, UnicodeType):
22- password = password.encode('ascii', 'replace')
23- if isinstance(essay, UnicodeType):
24- essay = essay.encode('ascii', 'replace')
25- return '<UserDesc %s (%s) [%s] [digest? %s] [%s] [%s] >' % (
26- address, fullname, password, digest, language, essay)
27-
28-
29-
30+ essay = getattr(self, 'essay', 'n/a')
31+ # Make sure essay is encoded if it's string
32+ if isinstance(essay, UnicodeType):
33+ essay = essay.encode('ascii', 'replace')
34+ return UserDesc.__repr__(self)[:-1] + ' [%s]>' % (essay)
35
36=== modified file 'Mailman/DlistUtils.py'
37--- Mailman/DlistUtils.py 2010-05-27 18:01:32 +0000
38+++ Mailman/DlistUtils.py 2013-07-06 08:38:35 +0000
39@@ -125,7 +125,15 @@
40 syslog('info', 'subscriber_id = %d\n', subscriber_id)
41 msgdata['subscriber_id'] = subscriber_id
42 return subscriber_id
43-
44+
45+ @decfunc
46+ def is_subscriber_deleted(self, subscriber_id):
47+ return self.store.find(Subscriber,And(Subscriber.subscriber_id == subscriber_id, Subscriber.deleted == True)).count()
48+ @decfunc
49+ def is_subscribed_to_thread(self, thread_id, subscriber_id):
50+ return self.store.find(Override,And(Override.subscriber_id == subscriber_id, Override.thread_id == thread_id, Override.preference == 1)).count()
51+
52+
53 @decfunc
54 def get_format(self, subscriber_id):
55 command = "return int(self.store.get(Subscriber,subscriber_id).format)\n"
56@@ -160,6 +168,11 @@
57 self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval)
58
59 @decfunc
60+ def is_subscriber_disabled(self, subscriber_id):
61+ return self.store.find(Subscriber,And(Subscriber.subscriber_id == subscriber_id,
62+ Or(Subscriber.suppress == 0, Subscriber.suppress == 2))).count()
63+
64+ @decfunc
65 def setDigest(self, member, flag):
66 """Disable/enable delivery based on user digest status"""
67
68@@ -185,6 +198,10 @@
69 syslog('info', 'DlistUtils(setDigest):Executing query:\n%s', command)
70 self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval)
71
72+ @decfunc
73+ def is_digest_disabled(self, subscriber_id):
74+ return self.store.find(Subscriber,And(Subscriber.subscriber_id == subscriber_id,
75+ Or(Subscriber.suppress == 0, Subscriber.suppress == 1))).count()
76 @decfunc
77 def changePreference(self, member, preference):
78 """Change a user's default preference for new threads."""
79@@ -475,14 +492,14 @@
80 def threadIDandName(self, threadReference):
81 """Given thread_id or thread_name, determine the other, returning (thread_id, thread_name)"""
82 try:
83- thread_id = int(thread_reference)
84+ thread_id = int(threadReference)
85 try:
86 command = "result = self.store.find(Thread,Thread.thread_id == thread_id)\nthread_name = [(thread.thread_name) for thread in result]\nthread_name = thread_name.encode('utf-8')\n"
87 if DEBUG_MODE:
88 syslog('info', 'DlistUtils(threadIDandName)Executing query:\n%s', command)
89 result = self.store.find(Thread,Thread.thread_id == thread_id)
90 thread_name = [(thread.thread_name) for thread in result]
91- thread_name = thread_name.encode('utf-8')
92+ thread_name = thread_name.encode('utf-8')
93 except:
94 raise NonexistentThreadRequest("Your message could not be sent because you specified a nonexistent conversation (%d). Perhaps you meant to start a new conversation, which you can do by addressing your message to %s+new@%s" % (thread_id, self.mlist.real_name, self.mlist.host_name))
95 except:
96@@ -502,7 +519,6 @@
97 thread_id = thread_id[0]
98 if DEBUG_MODE:
99 syslog('info', 'thread_id: %s\n', thread_id)
100-
101 return (thread_id, thread_name)
102
103 def getThreadAddress(msgdata):
104
105=== added directory 'tests'
106=== added file 'tests/DlistTestBase.py'
107--- tests/DlistTestBase.py 1970-01-01 00:00:00 +0000
108+++ tests/DlistTestBase.py 2013-07-06 08:38:35 +0000
109@@ -0,0 +1,39 @@
110+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
111+#
112+# This program is free software; you can redistribute it and/or
113+# modify it under the terms of the GNU General Public License
114+# as published by the Free Software Foundation; either version 2
115+# of the License, or (at your option) any later version.
116+#
117+# This program is distributed in the hope that it will be useful,
118+# but WITHOUT ANY WARRANTY; without even the implied warranty of
119+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120+# GNU General Public License for more details.
121+#
122+# You should have received a copy of the GNU General Public License
123+# along with this program; if not, write to the Free Software
124+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
125+
126+"""Test base class which handles creating and deleting a test dlist.
127+"""
128+
129+import os
130+import shutil
131+import difflib
132+from Mailman import DlistUtils
133+from TestBase import TestBase
134+import unittest
135+
136+class DlistTestBase(TestBase):
137+
138+ def setUp(self):
139+ TestBase.setUp(self)
140+ try:
141+ DlistUtils.remove_dlist('_xtest')
142+ except:
143+ pass # If there is no _xtest list do nothing
144+ DlistUtils.create_dlist(self._mlist)
145+
146+ def tearDown(self):
147+ DlistUtils.remove_dlist('_xtest')
148+ TestBase.tearDown(self)
149
150=== added file 'tests/EmailBase.py'
151--- tests/EmailBase.py 1970-01-01 00:00:00 +0000
152+++ tests/EmailBase.py 2013-07-06 08:38:35 +0000
153@@ -0,0 +1,75 @@
154+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
155+#
156+# This program is free software; you can redistribute it and/or
157+# modify it under the terms of the GNU General Public License
158+# as published by the Free Software Foundation; either version 2
159+# of the License, or (at your option) any later version.
160+#
161+# This program is distributed in the hope that it will be useful,
162+# but WITHOUT ANY WARRANTY; without even the implied warranty of
163+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
164+# GNU General Public License for more details.
165+#
166+# You should have received a copy of the GNU General Public License
167+# along with this program; if not, write to the Free Software
168+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
169+
170+"""Base class for tests that email things.
171+"""
172+
173+import socket
174+import asyncore
175+import smtpd
176+
177+from Mailman import mm_cfg
178+
179+from TestBase import TestBase
180+
181+
182+
183
184+MSGTEXT = None
185+
186+class OneShotChannel(smtpd.SMTPChannel):
187+ def smtp_QUIT(self, arg):
188+ smtpd.SMTPChannel.smtp_QUIT(self, arg)
189+ raise asyncore.ExitNow
190+
191+
192+class SinkServer(smtpd.SMTPServer):
193+ def handle_accept(self):
194+ conn, addr = self.accept()
195+ channel = OneShotChannel(self, conn, addr)
196+
197+ def process_message(self, peer, mailfrom, rcpttos, data):
198+ global MSGTEXT
199+ MSGTEXT = data
200+
201+
202+
203
204+class EmailBase(TestBase):
205+ def setUp(self):
206+ TestBase.setUp(self)
207+ # Second argument tuple is ignored.
208+ self._server = SinkServer(('localhost', mm_cfg.SMTPPORT),
209+ ('localhost', 25))
210+
211+ def tearDown(self):
212+ self._server.close()
213+ TestBase.tearDown(self)
214+
215+ def _readmsg(self):
216+ global MSGTEXT
217+ # Save and unlock the list so that the qrunner process can open it and
218+ # lock it if necessary. We'll re-lock the list in our finally clause
219+ # since that if an invariant of the test harness.
220+ self._mlist.Unlock()
221+ try:
222+ try:
223+ # timeout is in milliseconds, see asyncore.py poll3()
224+ asyncore.loop(timeout=30.0)
225+ MSGTEXT = None
226+ except asyncore.ExitNow:
227+ pass
228+ return MSGTEXT
229+ finally:
230+ self._mlist.Lock()
231
232=== added file 'tests/TestBase.py'
233--- tests/TestBase.py 1970-01-01 00:00:00 +0000
234+++ tests/TestBase.py 2013-07-06 08:38:35 +0000
235@@ -0,0 +1,72 @@
236+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
237+#
238+# This program is free software; you can redistribute it and/or
239+# modify it under the terms of the GNU General Public License
240+# as published by the Free Software Foundation; either version 2
241+# of the License, or (at your option) any later version.
242+#
243+# This program is distributed in the hope that it will be useful,
244+# but WITHOUT ANY WARRANTY; without even the implied warranty of
245+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
246+# GNU General Public License for more details.
247+#
248+# You should have received a copy of the GNU General Public License
249+# along with this program; if not, write to the Free Software
250+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
251+
252+"""Test base class which handles creating and deleting a test list.
253+"""
254+
255+import os
256+import shutil
257+import difflib
258+import unittest
259+from cStringIO import StringIO
260+
261+from Mailman import MailList
262+from Mailman import Utils
263+from Mailman import mm_cfg
264+
265+NL = '\n'
266+
267+
268+
269
270+class TestBase(unittest.TestCase):
271+ if hasattr(difflib, 'ndiff'):
272+ # Python 2.2 and beyond
273+ def ndiffAssertEqual(self, first, second):
274+ """Like failUnlessEqual except use ndiff for readable output."""
275+ if first <> second:
276+ sfirst = str(first)
277+ ssecond = str(second)
278+ diff = difflib.ndiff(sfirst.splitlines(), ssecond.splitlines())
279+ fp = StringIO()
280+ print >> fp, NL, NL.join(diff)
281+ raise self.failureException, fp.getvalue()
282+ else:
283+ # Python 2.1
284+ ndiffAssertEqual = unittest.TestCase.assertEqual
285+
286+ def setUp(self):
287+ mlist = MailList.MailList()
288+ mlist.Create('_xtest', 'test@dom.ain', 'xxxxx')
289+ mlist.host_name = 'dom.ain'
290+ mlist.web_page_url = 'http://www.dom.ain/mailman/'
291+ mlist.Save()
292+ # This leaves the list in a locked state
293+ self._mlist = mlist
294+
295+ def tearDown(self):
296+ self._mlist.Unlock()
297+ listname = self._mlist.internal_name()
298+ for dirtmpl in ['lists/%s',
299+ 'archives/private/%s',
300+ 'archives/private/%s.mbox',
301+ 'archives/public/%s',
302+ 'archives/public/%s.mbox',
303+ ]:
304+ dir = os.path.join(mm_cfg.VAR_PREFIX, dirtmpl % listname)
305+ if os.path.islink(dir):
306+ os.unlink(dir)
307+ elif os.path.isdir(dir):
308+ shutil.rmtree(dir)
309
310=== added file 'tests/dlist_testall.py'
311--- tests/dlist_testall.py 1970-01-01 00:00:00 +0000
312+++ tests/dlist_testall.py 2013-07-06 08:38:35 +0000
313@@ -0,0 +1,35 @@
314+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
315+#
316+# This program is free software; you can redistribute it and/or
317+# modify it under the terms of the GNU General Public License
318+# as published by the Free Software Foundation; either version 2
319+# of the License, or (at your option) any later version.
320+#
321+# This program is distributed in the hope that it will be useful,
322+# but WITHOUT ANY WARRANTY; without even the implied warranty of
323+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
324+# GNU General Public License for more details.
325+#
326+# You should have received a copy of the GNU General Public License
327+# along with this program; if not, write to the Free Software
328+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
329+
330+"""PyUnit-based test harness for Systers Mailman."""
331+
332+import unittest
333+
334+MODULES = ('dlist_handlers', 'dlist_membership', 'dlist_userdesc', 'dlist_utils')
335+
336+
337+
338
339+def suite():
340+ alltests = unittest.TestSuite()
341+ for modname in MODULES:
342+ mod = __import__('test_'+modname)
343+ alltests.addTest(mod.suite())
344+ return alltests
345+
346+
347+
348
349+if __name__ == '__main__':
350+ unittest.main(defaultTest='suite')
351
352=== added file 'tests/test_dlist_handlers.py'
353--- tests/test_dlist_handlers.py 1970-01-01 00:00:00 +0000
354+++ tests/test_dlist_handlers.py 2013-07-06 08:38:35 +0000
355@@ -0,0 +1,185 @@
356+import unittest
357+import email
358+
359+from Mailman import Message
360+from Mailman import Version
361+from Mailman import Errors
362+from Mailman import ErrorsDlist
363+from Mailman import DlistUtils
364+
365+from EmailBase import EmailBase
366+from Mailman.DlistMemberships import DlistMemberships
367+from Mailman.Handlers.Dlists import process
368+from DlistTestBase import DlistTestBase
369+from Mailman.Handlers.Dlists import get_malformed_msg_txt
370+
371+class TestSentMessage(DlistTestBase):
372+ def setUp(self):
373+ DlistTestBase.setUp(self)
374+ def test_new_thread_message(self):
375+ eq = self.assertEqual
376+ msg = email.message_from_string("""\
377+To: _xtest+new@dom.ain
378+X-Original-To: _xtest+new@dom.ain
379+From: nobody@dom.ain
380+Subject: and another thing
381+
382+yadda yadda yadda
383+""", Message.Message)
384+ mdata = {}
385+ process(self._mlist, msg, mdata)
386+ thread = DlistUtils.Thread(self._mlist)
387+ eq(thread.threadIDandName(mdata['thread_name'])[0], mdata['thread_id'])
388+
389+ def test_new_thread_with_name_message(self):
390+ eq = self.assertEqual
391+ msg = email.message_from_string("""\
392+To: _xtest+new+name@dom.ain
393+X-Original-To: _xtest+new+name@dom.ain
394+From: nobody@dom.ain
395+Subject: and another thing
396+
397+yadda yadda yadda
398+""", Message.Message)
399+ mdata = {}
400+ process(self._mlist, msg, mdata)
401+ thread = DlistUtils.Thread(self._mlist)
402+ eq(thread.threadIDandName(mdata['thread_name'])[0], mdata['thread_id'])
403+ eq(mdata['thread_name'], 'name')
404+
405+ def test_continue_thread(self):
406+ eq = self.assertEqual
407+ msgNewThread = email.message_from_string("""\
408+To: _xtest+new+name@dom.ain
409+X-Original-To: _xtest+new+name@dom.ain
410+From: nobody@dom.ain
411+Subject: and another thing
412+
413+yadda yadda yadda
414+""", Message.Message)
415+ mdataNewThread = {}
416+ process(self._mlist, msgNewThread, mdataNewThread)
417+ self._mlist.addNewMember('person@dom.ain')
418+ msgContinueThread = email.message_from_string("""\
419+To: _xtest+name@dom.ain
420+X-Original-To: _xtest+name@dom.ain
421+From: nobody@dom.ain
422+Subject: and another thing
423+
424+yadda yadda yadda
425+""", Message.Message)
426+ mdataContinueThread = {}
427+ process(self._mlist, msgContinueThread, mdataContinueThread)
428+ eq(mdataNewThread['thread_id'], mdataContinueThread['thread_id'])
429+ eq(mdataNewThread['thread_name'], mdataContinueThread['thread_name'])
430+
431+ def test_subscribe_to_thread(self):
432+ msgNewThread = email.message_from_string("""\
433+To: _xtest+new+name@dom.ain
434+X-Original-To: _xtest+new+name@dom.ain
435+From: nobody@dom.ain
436+Subject: and another thing
437+
438+yadda yadda yadda
439+""", Message.Message)
440+ mdataNewThread = {}
441+ process(self._mlist, msgNewThread, mdataNewThread)
442+ self._mlist.addNewMember('person@dom.ain')
443+ msg = email.message_from_string("""\
444+To: _xtest+name+subscribe@dom.ain
445+X-Original-To: _xtest+name+subscribe@dom.ain
446+From: person@dom.ain
447+Subject: and another thing
448+
449+yadda yadda yadda
450+""", Message.Message)
451+ mdata = {}
452+ try:
453+ process(self._mlist, msg, mdata)
454+ except:
455+ subscriber = DlistUtils.Subscriber(self._mlist)
456+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
457+ self.assertEqual(subscriber.is_subscribed_to_thread(mdata['thread_id'], subscriber_id), True)
458+
459+ def test_unsubscribe_from_thread(self):
460+ msgNewThread = email.message_from_string("""\
461+To: _xtest+new+name@dom.ain
462+X-Original-To: _xtest+new+name@dom.ain
463+From: nobody@dom.ain
464+Subject: and another thing
465+
466+yadda yadda yadda
467+""", Message.Message)
468+ mdataNewThread = {}
469+ process(self._mlist, msgNewThread, mdataNewThread)
470+ self._mlist.addNewMember('person@dom.ain')
471+ msg = email.message_from_string("""\
472+To: _xtest+name+unsubscribe@dom.ain
473+X-Original-To: _xtest+name+unsubscribe@dom.ain
474+From: person@dom.ain
475+Subject: and another thing
476+
477+yadda yadda yadda
478+""", Message.Message)
479+ mdata = {}
480+ try:
481+ process(self._mlist, msg, mdata)
482+ except:
483+ subscriber = DlistUtils.Subscriber(self._mlist)
484+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
485+ self.assertEqual(subscriber.is_subscribed_to_thread(mdata['thread_id'],subscriber_id), False)
486+
487+ def test_wrong_number_of_commands(self):
488+ msgNewThread = email.message_from_string("""\
489+To: _xtest+new+name@dom.ain
490+X-Original-To: _xtest+new+name@dom.ain
491+From: nobody@dom.ain
492+Subject: and another thing
493+
494+yadda yadda yadda
495+""", Message.Message)
496+ mdataNewThread = {}
497+ process(self._mlist, msgNewThread, mdataNewThread)
498+ msg = email.message_from_string("""\
499+To: _xtest+name+subscribe+new@dom.ain
500+X-Original-To: _xtest+name+subscribe+new@dom.ain
501+From: nobody@dom.ain
502+Subject: and another thing
503+
504+yadda yadda yadda
505+""", Message.Message)
506+ mdata = {}
507+ self.assertRaises(ErrorsDlist.MalformedRequest, process, self._mlist, msg, mdata)
508+
509+ def test_wrong_address(self):
510+ #tutaj nie dziala a chcialabym zeby dzialalo
511+ msg = email.message_from_string("""\
512+To:
513+X-Original-To:
514+From: nobody@dom.ain
515+Subject: and another thing
516+
517+yadda yadda yadda
518+""", Message.Message)
519+ mdata = {}
520+ self.assertRaises(ErrorsDlist.MalformedRequest, process, self._mlist, msg, mdata)
521+
522+ def test_no_command(self):
523+ msg = email.message_from_string("""\
524+To: _xtest@dom.ain
525+X-Original-To: _xtest@dom.ain
526+From: nobody@dom.ain
527+Subject: and another thing
528+
529+yadda yadda yadda
530+""", Message.Message)
531+ mdata = {}
532+ self.assertRaises(ErrorsDlist.MalformedRequest, process, self._mlist, msg, mdata)
533+
534+def suite():
535+ suite = unittest.TestSuite()
536+ suite.addTest(unittest.makeSuite(TestSentMessage))
537+ return suite
538+
539+if __name__ == '__main__':
540+ unittest.main(defaultTest='suite')
541
542=== added file 'tests/test_dlist_membership.py'
543--- tests/test_dlist_membership.py 1970-01-01 00:00:00 +0000
544+++ tests/test_dlist_membership.py 2013-07-06 08:38:35 +0000
545@@ -0,0 +1,111 @@
546+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
547+#
548+# This program is free software; you can redistribute it and/or
549+# modify it under the terms of the GNU General Public License
550+# as published by the Free Software Foundation; either version 2
551+# of the License, or (at your option) any later version.
552+#
553+# This program is distributed in the hope that it will be useful,
554+# but WITHOUT ANY WARRANTY; without even the implied warranty of
555+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
556+# GNU General Public License for more details.
557+#
558+# You should have received a copy of the GNU General Public License
559+# along with this program; if not, write to the Free Software
560+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
561+
562+"""Unit tests for DlistMemberships.
563+"""
564+
565+import os
566+import time
567+import unittest
568+
569+from Mailman import mm_cfg
570+from Mailman import Utils
571+from Mailman import MailList
572+from Mailman.DlistMemberships import DlistMemberships
573+from Mailman import DlistUtils
574+from Mailman.Errors import NotAMemberError
575+
576+from DlistTestBase import DlistTestBase
577+
578+class TestMembers(DlistTestBase):
579+ def setUp(self):
580+ DlistTestBase.setUp(self)
581+
582+ def test_get_cp_member_strict(self):
583+ self._mlist.addNewMember('person@dom.ain')
584+ mlist = self._mlist
585+ member, type = mlist._DlistMemberships__get_cp_member('person@dom.ain')
586+ self.assertEqual(member, 'person@dom.ain')
587+
588+ def test_get_cp_member_loose(self):
589+ self._mlist.addNewMember('person@dom.ain')
590+ mlist = self._mlist
591+ member, type = mlist._DlistMemberships__get_cp_member('person@my.dom.ain')
592+ self.assertEqual(member, 'person@dom.ain')
593+
594+ def test_add_member_affect_dlist_database(self):
595+ self._mlist.addNewMember('person@dom.ain',
596+ affect_dlist_database = True)
597+ mlist = self._mlist
598+ subscriber = DlistUtils.Subscriber(mlist)
599+ self.assertEqual(subscriber.getSubscriber_id_raw('person@dom.ain'), not None)
600+
601+ def test_add_member_not_affect_dlist_database(self):
602+ self._mlist.addNewMember('person@dom.ain',
603+ affect_dlist_database = False)
604+ mlist = self._mlist
605+ subscriber = DlistUtils.Subscriber(self._mlist)
606+ self.assertEqual(subscriber.getSubscriber_id_raw('person@dom.ain'), None)
607+
608+ def test_remove_member(self):
609+ self._mlist.addNewMember('person@dom.ain')
610+ self._mlist.removeMember('person@dom.ain')
611+ subscriber = DlistUtils.Subscriber(self._mlist)
612+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
613+ self.assertEqual(subscriber.is_subscriber_deleted(subscriber_id), True)
614+
615+ def test_authentication(self):
616+ self._mlist.addNewMember('person@dom.ain',
617+ password='xxXXxx')
618+ mlist = self._mlist
619+ self.failIf(mlist.authenticateMember('person@dom.ain', 'xxx'))
620+ self.assertEqual(mlist.authenticateMember('person@dom.ain', 'xxXXxx'),
621+ 'xxXXxx')
622+
623+ def test_change_member_address(self):
624+ self._mlist.addNewMember('person@dom.ain')
625+ self._mlist.changeMemberAddress('person@dom.ain', 'newperson@dom.ain')
626+ subscriber = DlistUtils.Subscriber(self._mlist)
627+ self.assertEqual(subscriber.getSubscriber_id_raw('person@dom.ain'), None)
628+ self.assertEqual(subscriber.getSubscriber_id_raw('newperson@dom.ain'), True)
629+
630+ def test_set_delivery_status(self):
631+ self._mlist.addNewMember('person@dom.ain')
632+ subscriber = DlistUtils.Subscriber(self._mlist)
633+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
634+ self._mlist.setDeliveryStatus('person@dom.ain', False)
635+ self.assertEqual(subscriber.is_subscriber_disabled(subscriber_id), True)
636+ self._mlist.setDeliveryStatus('person@dom.ain', True)
637+ self.assertEqual(subscriber.is_subscriber_disabled(subscriber_id), False)
638+
639+ def test_set_member_option(self):
640+ self._mlist.addNewMember('person@dom.ain')
641+ subscriber = DlistUtils.Subscriber(self._mlist)
642+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
643+ self._mlist.setMemberOption('person@dom.ain', mm_cfg.Digests , 1)
644+ subscriber = DlistUtils.Subscriber(self._mlist)
645+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
646+ self.assertEqual(subscriber.is_digest_disabled(subscriber_id), False)
647+ self._mlist.setMemberOption('person@dom.ain', mm_cfg.Digests, 0)
648+ self.assertEqual(subscriber.is_digest_disabled(subscriber_id), True)
649+
650+def suite():
651+ suite = unittest.TestSuite()
652+ suite.addTest(unittest.makeSuite(TestMembers))
653+ return suite
654+
655+if __name__ == '__main__':
656+ unittest.main(defaultTest='suite')
657
658=== added file 'tests/test_dlist_userdesc.py'
659--- tests/test_dlist_userdesc.py 1970-01-01 00:00:00 +0000
660+++ tests/test_dlist_userdesc.py 2013-07-06 08:38:35 +0000
661@@ -0,0 +1,62 @@
662+# Copyright (C) 2001-2008 by the Free Software Foundation, Inc.
663+#
664+# This program is free software; you can redistribute it and/or
665+# modify it under the terms of the GNU General Public License
666+# as published by the Free Software Foundation; either version 2
667+# of the License, or (at your option) any later version.
668+#
669+# This program is distributed in the hope that it will be useful,
670+# but WITHOUT ANY WARRANTY; without even the implied warranty of
671+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
672+# GNU General Public License for more details.
673+#
674+# You should have received a copy of the GNU General Public License
675+# along with this program; if not, write to the Free Software
676+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
677+# USA.
678+
679+"""Unit tests for Mailman/SecurityManager.py
680+"""
681+
682+import os
683+import unittest
684+import errno
685+import Cookie
686+try:
687+ import crypt
688+except ImportError:
689+ crypt = None
690+# Don't use cStringIO because we're going to inherit
691+from StringIO import StringIO
692+from Mailman.DlistUserDesc import DlistUserDesc
693+from Mailman import mm_cfg
694+from Mailman import Utils
695+from Mailman import Errors
696+from Mailman.Utils import md5_new, sha_new
697+
698+from TestBase import TestBase
699+
700+
701+class TestDlistUserDesc(TestBase):
702+ def setUp(self):
703+ TestBase.setUp(self)
704+
705+ def tearDown(self):
706+ TestBase.tearDown(self)
707+
708+ def test_empty_repr(self):
709+ emptydUD = DlistUserDesc()
710+ self.assertEqual(emptydUD.__repr__(), '<UserDesc n/a (n/a) [n/a] [digest? n/a] [n/a] [n/a]>')
711+
712+ def test_repr(self):
713+ dUD = DlistUserDesc('xxx', 'xxx', 'xxx', 1, 'xxx', 'xxx')
714+ self.assertEqual(dUD.__repr__(), '<UserDesc xxx (xxx) [xxx] [digest? yes] [xxx] [xxx]>')
715+
716+def suite():
717+ suite = unittest.TestSuite()
718+ suite.addTest(unittest.makeSuite(TestDlistUserDesc))
719+ return suite
720+
721+
722+if __name__ == '__main__':
723+ unittest.main(defaultTest='suite')
724
725=== added file 'tests/test_dlist_utils.py'
726--- tests/test_dlist_utils.py 1970-01-01 00:00:00 +0000
727+++ tests/test_dlist_utils.py 2013-07-06 08:38:35 +0000
728@@ -0,0 +1,90 @@
729+# Copyright (C) 2001-2003 by the Free Software Foundation, Inc.
730+#
731+# This program is free software; you can redistribute it and/or
732+# modify it under the terms of the GNU General Public License
733+# as published by the Free Software Foundation; either version 2
734+# of the License, or (at your option) any later version.
735+#
736+# This program is distributed in the hope that it will be useful,
737+# but WITHOUT ANY WARRANTY; without even the implied warranty of
738+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
739+# GNU General Public License for more details.
740+#
741+# You should have received a copy of the GNU General Public License
742+# along with this program; if not, write to the Free Software
743+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
744+
745+import unittest
746+import email
747+from Mailman import Message
748+
749+from Mailman import DlistUtils
750+from Mailman import ErrorsDlist
751+from DlistTestBase import DlistTestBase
752+from Mailman.Handlers.Dlists import process
753+
754+
755+class TestSubscriber(DlistTestBase):
756+ def setUp(self):
757+ DlistTestBase.setUp(self)
758+
759+ def test_get_subscriber_id_raw(self):
760+ self._mlist.addNewMember('person@dom.ain')
761+ subscriber = DlistUtils.Subscriber(self._mlist)
762+ self.assertEqual(subscriber.getSubscriber_id_raw('person@dom.ain'), 1)
763+ self.assertEqual(subscriber.getSubscriber_id_raw(None), None)
764+
765+ def test_subscriber_id_taw_or_die(self):
766+ self._mlist.addNewMember('person@dom.ain')
767+ subscriber = DlistUtils.Subscriber(self._mlist)
768+ self.assertEqual(subscriber.getSubscriber_id_raw_or_die('person@dom.ain'), 1)
769+ self.assertRaises(ErrorsDlist.InternalError,
770+ subscriber.getSubscriber_id_raw_or_die, None)
771+
772+ def test_set_disable(self):
773+ self._mlist.addNewMember('person@dom.ain')
774+ subscriber = DlistUtils.Subscriber(self._mlist)
775+ subscriber.setDisable('person@dom.ain', False)
776+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
777+ self.assertEqual(subscriber.is_subscriber_disabled(subscriber_id), True)
778+ subscriber.setDisable('person@dom.ain', True)
779+ self.assertEqual(subscriber.is_subscriber_disabled(subscriber_id), False)
780+
781+ def test_set_digest(self):
782+ self._mlist.addNewMember('person@dom.ain')
783+ subscriber = DlistUtils.Subscriber(self._mlist)
784+ subscriber.setDigest('person@dom.ain', False)
785+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
786+ self.assertEqual(subscriber.is_digest_disabled(subscriber_id), True)
787+ subscriber.setDigest('person@dom.ain', True)
788+ self.assertEqual(subscriber.is_digest_disabled(subscriber_id), False)
789+
790+ def test_change_address(self):
791+ self._mlist.addNewMember('person@dom.ain')
792+ subscriber = DlistUtils.Subscriber(self._mlist)
793+ subscriber.changeAddress('person@dom.ain', 'newperson@dom.ain')
794+ self.assertEqual(subscriber.getSubscriber_id_raw('person@dom.ain'), None)
795+ self.assertEqual(subscriber.getSubscriber_id_raw('newperson@dom.ain'), not None)
796+
797+ def test_unsubscribe_from_list(self):
798+ self._mlist.addNewMember('person@dom.ain')
799+ subscriber = DlistUtils.Subscriber(self._mlist)
800+ subscriber.unsubscribeFromList('person@dom.ain')
801+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
802+ self.assertEqual(subscriber.is_subscriber_deleted(subscriber_id), True)
803+
804+ def test_subscribe_to_list(self):
805+ self._mlist.addNewMember('person@dom.ain')
806+ subscriber = DlistUtils.Subscriber(self._mlist)
807+ subscriber.unsubscribeFromList('person@dom.ain')
808+ subscriber.subscribeToList('person@dom.ain')
809+ subscriber_id = subscriber.getSubscriber_id_raw('person@dom.ain')
810+ self.assertEqual(subscriber.is_subscriber_deleted(subscriber_id), False)
811+
812+def suite():
813+ suite = unittest.TestSuite()
814+ suite.addTest(unittest.makeSuite(TestSubscriber))
815+ return suite
816+
817+if __name__ == '__main__':
818+ unittest.main(defaultTest='suite')

Subscribers

People subscribed via source and target branches

to status/vote changes: