Code

don't have mailgw tests close the db - they're not testing persistence
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 8 Feb 2010 08:30:37 +0000 (08:30 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 8 Feb 2010 08:30:37 +0000 (08:30 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4454 57a73879-2fb5-44c3-a270-3262357dd7e2

test/db_test_base.py
test/memorydb.py
test/test_mailgw.py

index 7fd26638fb74eee5182e8925b87b7cdcf8c25166..bb4272ab75a4c0ad6b3593d024d716b93d54bfc7 100644 (file)
@@ -1863,6 +1863,9 @@ class SchemaTest(MyTestCase):
             shutil.rmtree(config.DATABASE)
         os.makedirs(config.DATABASE + '/files')
 
+    def open_database(self):
+        self.db = self.module.Database(config, 'admin')
+
     def test_reservedProperties(self):
         self.open_database()
         self.assertRaises(ValueError, self.module.Class, self.db, "a",
index 9565050bef68405d3c0eebf54969369261a0b0e3..17c8330f7c3029c86363a3603a04f1a84111e97c 100644 (file)
@@ -184,7 +184,6 @@ class Database(back_anydbm.Database):
         self.sessions = Sessions()
         self.otks = OneTimeKeys()
         self.indexer = Indexer(self)
-        self.sessions = Sessions()
 
         # anydbm bits
         self.cache = {}         # cache of nodes loaded or created
@@ -193,7 +192,6 @@ class Database(back_anydbm.Database):
         self.destroyednodes = {}# keep track of the destroyed nodes by class
         self.transactions = []
 
-
     def filename(self, classname, nodeid, property=None, create=0):
         shutil.copyfile(__file__, __file__+'.dummy')
         return __file__+'.dummy'
index ca3419f90510d7bc361dc0fd6d2a000b0a181e21..b1e4db93c82a29b5254e5eedb8efe4360b55e937 100644 (file)
@@ -143,8 +143,16 @@ class MailgwTestCase(unittest.TestCase, DiffHelper):
             os.remove(SENDMAILDEBUG)
         self.db.close()
 
+    def _create_mailgw(self, message):
+        class MailGW(self.instance.MailGW):
+            def handle_message(self, message):
+                return self._handle_message(message)
+        handler = MailGW(self.instance)
+        handler.db = self.db
+        return handler
+
     def _handle_mail(self, message):
-        handler = self.instance.MailGW(self.instance)
+        handler = self._create_mailgw(message)
         handler.trapExceptions = 0
         return handler.main(StringIO(message))
 
@@ -582,7 +590,7 @@ _______________________________________________________________________
         # reconstruct old behaviour: This would reuse the
         # database-handle from the doNewIssue above which has committed
         # as user "Chef". So we close and reopen the db as that user.
-        self.db.close()
+        #self.db.close() actually don't close 'cos this empties memorydb
         self.db = self.instance.open('Chef')
         self.db.issue.set('1', assignedto=self.chef_id)
         self.db.commit()
@@ -1032,6 +1040,7 @@ Subject: [issue1] Testing... [nosy=-richard]
         assert not os.path.exists(SENDMAILDEBUG)
 
     def testNewUserAuthor(self):
+        self.db.commit()
         l = self.db.user.list()
         l.sort()
         message = '''Content-Type: text/plain;
@@ -1133,8 +1142,7 @@ Subject: [issue] Testing nonexisting user...
 
 This is a test submission of a new issue.
 '''
-        self.db.close()
-        handler = self.instance.MailGW(self.instance)
+        handler = self._create_mailgw(message)
         # we want a bounce message:
         handler.trapExceptions = 1
         ret = handler.main(StringIO(message))