From 1d9927830e9257a5f6515a2838390ea8c9348454 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 5 Feb 2010 05:10:52 +0000 Subject: [PATCH] make some more memorydb tests pass git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4451 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/back_anydbm.py | 6 ++++++ roundup/backends/blobfiles.py | 4 ++++ roundup/roundupdb.py | 3 +-- test/db_test_base.py | 16 ++++++++-------- test/memorydb.py | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index d0eb1a9..2ce4c4f 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -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): diff --git a/roundup/backends/blobfiles.py b/roundup/backends/blobfiles.py index 68da227..0e4d9f0 100644 --- a/roundup/backends/blobfiles.py +++ b/roundup/backends/blobfiles.py @@ -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 diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index 80f4ee1..5ba6b45 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -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: diff --git a/test/db_test_base.py b/test/db_test_base.py index 356fb7e..b245ef2 100644 --- a/test/db_test_base.py +++ b/test/db_test_base.py @@ -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 diff --git a/test/memorydb.py b/test/memorydb.py index ce10086..ea76be7 100644 --- a/test/memorydb.py +++ b/test/memorydb.py @@ -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): -- 2.30.2