Author: barry.warsaw
Date: Sun Mar 20 19:57:12 2005
New Revision: 40

Added:
   trunk/mailman/src/mailman/database/tests/base.py
Modified:
   trunk/mailman/src/mailman/database/schema.py
   trunk/mailman/src/mailman/database/tests/test_roster.py
Log:
Move the Roster test to a proper unit test.


Modified: trunk/mailman/src/mailman/database/schema.py
==============================================================================
--- trunk/mailman/src/mailman/database/schema.py        (original)
+++ trunk/mailman/src/mailman/database/schema.py        Sun Mar 20 19:57:12 2005
@@ -233,35 +233,3 @@
 # XXX For performance reasons, because these tables are so normalized, we
 # could generate a lookup table which will only change when an attribute has
 # changed.
-
-
-
-if __name__ == '__main__':
-    from sqlobject.sqlite import builder
-    conn = builder()(sys.argv[1], debug=True)
-    for table in (MailingList, Domain, RosterEntry, EmailAddress, Roster,
-                  RosterReference):
-        table.setConnection(conn)
-        table.createTable(ifNotExists=True)
-    # Test code
-    roster1 = Roster()
-    roster2 = Roster()
-    addr1 = EmailAddress(address='[EMAIL PROTECTED]', realname='Adam Ant',
-                         member_of=roster1)
-    addr2 = EmailAddress(address='[EMAIL PROTECTED]', realname='Betty Boop',
-                         member_of=roster1)
-    addr3 = EmailAddress(address='[EMAIL PROTECTED]', realname='Charlie 
Chaplin',
-                         member_of=roster2)
-    rref = RosterReference(roster=roster2, member_of=roster1)
-
-    def dumproster(roster):
-        for entry in roster.entries:
-            if isinstance(entry, RosterReference):
-                dumproster(entry.roster)
-            else:
-                print entry.address
-
-    print 'Roster 1'
-    dumproster(roster1)
-    print 'Roster 2'
-    dumproster(roster2)

Added: trunk/mailman/src/mailman/database/tests/base.py
==============================================================================
--- (empty file)
+++ trunk/mailman/src/mailman/database/tests/base.py    Sun Mar 20 19:57:12 2005
@@ -0,0 +1,36 @@
+# Copyright (C) 2005 Barry A. Warsaw
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place - Suite 330, Boston, MA 02111-1307, USA.
+
+"""Base class for SQLObject database tests."""
+
+import os
+import tempfile
+import unittest
+
+from mailman.database import Database
+
+
+
+class DatabaseTest(unittest.TestCase):
+    def setUp(self):
+        fd, self._dbfile = tempfile.mkstemp('.db', text=False)
+        filename = os.path.abspath(self._dbfile)
+        self._db = Database()
+        self._db.open('sqlite://' + filename)
+
+    def tearDown(self):
+        self._db.close()
+        os.remove(self._dbfile)

Modified: trunk/mailman/src/mailman/database/tests/test_roster.py
==============================================================================
--- trunk/mailman/src/mailman/database/tests/test_roster.py     (original)
+++ trunk/mailman/src/mailman/database/tests/test_roster.py     Sun Mar 20 
19:57:12 2005
@@ -16,26 +16,14 @@
 
 """Roster tests."""
 
-import os
-import tempfile
 import unittest
 
-from mailman.database import Database
 from mailman.database import schema
+from mailman.database.tests.base import DatabaseTest
 
 
 
-class TestRoster(unittest.TestCase):
-    def setUp(self):
-        fd, self._dbfile = tempfile.mkstemp('.db', text=False)
-        filename = os.path.abspath(self._dbfile)
-        self._db = Database()
-        self._db.open('sqlite://' + filename)
-
-    def tearDown(self):
-        self._db.close()
-        os.remove(self._dbfile)
-
+class TestRoster(DatabaseTest):
     def test_simple_roster(self):
         eq = self.assertEqual
         roster = schema.Roster()
@@ -47,6 +35,37 @@
             schema.EmailAddress.q.address == '[EMAIL PROTECTED]'))
         eq(len(entries), 1)
         eq(entries[0].address, '[EMAIL PROTECTED]')
+
+    def test_roster_refs(self):
+        eq = self.assertEqual
+        roster1 = schema.Roster()
+        roster2 = schema.Roster()
+        addr1 = schema.EmailAddress(address='[EMAIL PROTECTED]',
+                                    realname='Adam Ant',
+                                    member_of=roster1)
+        addr2 = schema.EmailAddress(address='[EMAIL PROTECTED]',
+                                    realname='Betty Boop',
+                                    member_of=roster1)
+        addr3 = schema.EmailAddress(address='[EMAIL PROTECTED]',
+                                    realname='Charlie Chaplin',
+                                    member_of=roster2)
+        rref = schema.RosterReference(roster=roster2, member_of=roster1)
+        addrs = []
+        def flatten(roster):
+            for entry in roster.entries:
+                if isinstance(entry, schema.RosterReference):
+                    flatten(entry.roster)
+                else:
+                    addrs.append(entry.address)
+        flatten(roster1)
+        eq(len(addrs), 3)
+        addrs.sort()
+        eq(addrs, ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]', '[EMAIL 
PROTECTED]'])
+        del addrs[:]
+        flatten(roster2)
+        eq(len(addrs), 1)
+        eq(addrs, ['[EMAIL PROTECTED]'])
+
 
 
 def test_suite():
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to