Code

make some more memorydb tests pass
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 5 Feb 2010 05:10:52 +0000 (05:10 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 5 Feb 2010 05:10:52 +0000 (05:10 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4451 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/backends/back_anydbm.py
roundup/backends/blobfiles.py
roundup/roundupdb.py
test/db_test_base.py
test/memorydb.py

index d0eb1a9545150f64d20e59ca4c30206995c543f6..2ce4c4fd7635176c81ec907408200c1a0e77b8d5 100644 (file)
@@ -784,6 +784,8 @@ class Class(hyperdb.Class):
         These operations trigger detectors and can be vetoed.  Attempts
         to modify the "creation" or "activity" properties cause a KeyError.
         """
+        if self.db.journaltag is None:
+            raise hyperdb.DatabaseError, _('Database open read-only')
         self.fireAuditors('create', None, propvalues)
         newid = self.create_inner(**propvalues)
         self.fireReactors('create', newid, None)
@@ -1045,6 +1047,9 @@ class Class(hyperdb.Class):
         These operations trigger detectors and can be vetoed.  Attempts
         to modify the "creation" or "activity" properties cause a KeyError.
         """
+        if self.db.journaltag is None:
+            raise hyperdb.DatabaseError, _('Database open read-only')
+
         self.fireAuditors('set', nodeid, propvalues)
         oldvalues = copy.deepcopy(self.db.getnode(self.classname, nodeid))
         for name,prop in self.getprops(protected=0).items():
@@ -1390,6 +1395,7 @@ class Class(hyperdb.Class):
         try:
             for nodeid in self.getnodeids(cldb):
                 node = self.db.getnode(self.classname, nodeid, cldb)
+                print (nodeid, node, node[self.key], keyvalue)
                 if node.has_key(self.db.RETIRED_FLAG):
                     continue
                 if not node.has_key(self.key):
index 68da227e6781400d17cd87168b3c33ef05a55ea5..0e4d9f08050ab48facea8bcef8808c38614d7fde 100644 (file)
@@ -304,6 +304,10 @@ class FileStorage:
         # file just ain't there
         raise IOError('content file for %s not found'%filename)
 
+    def filesize(self, classname, nodeid, property=None, create=0):
+        filename = self.filename(classname, nodeid, property, create)
+        return os.path.getsize(filename)
+
     def storefile(self, classname, nodeid, property, content):
         """Store the content of the file in the database. The property may be
            None, in which case the filename does not indicate which property
index 80f4ee108eea9a71cc814822ccb18862c8115e05..5ba6b4512e03952a1b458f36b03053a01392dafc 100644 (file)
@@ -361,8 +361,7 @@ class IssueClass:
         if msgid :
             for fileid in messages.get(msgid, 'files') :
                 # check the attachment size
-                filename = self.db.filename('file', fileid, None)
-                filesize = os.path.getsize(filename)
+                filesize = self.db.filesize('file', fileid, None)
                 if filesize <= self.db.config.NOSY_MAX_ATTACHMENT_SIZE:
                     message_files.append(fileid)
                 else:
index 356fb7e56ef19e248b19a7898188394570dbf2cb..b245ef2a6161c5a31174ea4baf3b85f4f23dbcae 100644 (file)
@@ -1855,14 +1855,14 @@ class DBTest(MyTestCase):
             db.issue.nosymessage(i, m, {})
             mail_msg = str(res["mail_msg"])
             self.assertEqual(res["mail_to"], ["fred@example.com"])
-            self.failUnless("From: admin" in mail_msg)
-            self.failUnless("Subject: [issue1] spam" in mail_msg)
-            self.failUnless("New submission from admin" in mail_msg)
-            self.failUnless("one two" in mail_msg)
-            self.failIf("File 'test1.txt' not attached" in mail_msg)
-            self.failUnless(base64.encodestring("xxx").rstrip() in mail_msg)
-            self.failUnless("File 'test2.txt' not attached" in mail_msg)
-            self.failIf(base64.encodestring("yyy").rstrip() in mail_msg)
+            self.assert_("From: admin" in mail_msg)
+            self.assert_("Subject: [issue1] spam" in mail_msg)
+            self.assert_("New submission from admin" in mail_msg)
+            self.assert_("one two" in mail_msg)
+            self.assert_("File 'test1.txt' not attached" not in mail_msg)
+            self.assert_(base64.encodestring("xxx").rstrip() in mail_msg)
+            self.assert_("File 'test2.txt' not attached" in mail_msg)
+            self.assert_(base64.encodestring("yyy").rstrip() not in mail_msg)
         finally :
             Mailer.smtp_send = backup
 
index ce10086ca7ea953b05bdc80879d0b72e7408d346..ea76be7dd458e5d735766245ec452615430591d5 100644 (file)
@@ -183,6 +183,9 @@ class Database(hyperdb.Database, roundupdb.Database):
         shutil.copyfile(__file__, __file__+'.dummy')
         return __file__+'.dummy'
 
+    def filesize(self, classname, nodeid, property=None, create=0):
+        return len(self.getnode(classname, nodeid)[property or 'content'])
+
     def post_init(self):
         pass
 
@@ -269,6 +272,8 @@ class Database(hyperdb.Database, roundupdb.Database):
     def newid(self, classname):
         self.ids[classname] += 1
         return str(self.ids[classname])
+    def setid(self, classname, id):
+        self.ids[classname] = id
 
     #
     # Nodes
@@ -282,7 +287,10 @@ class Database(hyperdb.Database, roundupdb.Database):
     def getnode(self, classname, nodeid, db=None):
         if db is not None:
             return db[nodeid]
-        return self.getclassdb(classname)[nodeid]
+        d = self.getclassdb(classname)
+        if nodeid not in d:
+            raise IndexError(nodeid)
+        return d[nodeid]
 
     def destroynode(self, classname, nodeid):
         del self.getclassdb(classname)[nodeid]
@@ -328,7 +336,10 @@ class Database(hyperdb.Database, roundupdb.Database):
 
 class Class(back_anydbm.Class):
     def getnodeids(self, db=None, retired=None):
-        return self.db.getclassdb(self.classname).keys()
+        d = self.db.getclassdb(self.classname)
+        if retired is None:
+            return d.keys()
+        return [k for k in d if d[k].get(self.db.RETIRED_FLAG, False) == retired]
 
 class FileClass(back_anydbm.Class):
     def __init__(self, db, classname, **properties):