changeset 3743:e754cc14e76a

fix unstable ordering of detectors [SF#1585378]
author Richard Jones <richard@users.sourceforge.net>
date Thu, 09 Nov 2006 03:08:22 +0000
parents a9f6eb633452
children c07ae92cebbc
files CHANGES.txt roundup/hyperdb.py test/db_test_base.py
diffstat 3 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Thu Nov 09 01:26:29 2006 +0000
+++ b/CHANGES.txt	Thu Nov 09 03:08:22 2006 +0000
@@ -16,6 +16,7 @@
 - fix email change note rendering of multiline properties (sf patch 1575223)
 - fix sidebar search links (sf patch 1574467)
 - nicer "permission required" messages (sf patch 1558183)
+- fix unstable ordering of detectors (sf bug 1585378)
 
 
 2006-10-07 1.2.1
--- a/roundup/hyperdb.py	Thu Nov 09 01:26:29 2006 +0000
+++ b/roundup/hyperdb.py	Thu Nov 09 03:08:22 2006 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: hyperdb.py,v 1.127 2006-08-30 09:35:31 schlatterbeck Exp $
+# $Id: hyperdb.py,v 1.128 2006-11-09 03:08:22 richard Exp $
 
 """Hyperdatabase implementation, especially field types.
 """
@@ -1196,20 +1196,20 @@
     #
     def audit(self, event, detector, priority = 100):
         """Register an auditor detector"""
-        self.auditors[event].append((priority, detector))
+        self.auditors[event].append((priority, detector.__name__, detector))
 
     def fireAuditors(self, event, nodeid, newvalues):
         """Fire all registered auditors"""
-        for prio, audit in self.auditors[event]:
+        for prio, name, audit in self.auditors[event]:
             audit(self.db, self, nodeid, newvalues)
 
     def react(self, event, detector, priority = 100):
         """Register a reactor detector"""
-        self.reactors[event].append((priority, detector))
+        self.reactors[event].append((priority, detector.__name__, detector))
 
     def fireReactors(self, event, nodeid, oldvalues):
         """Fire all registered reactors"""
-        for prio, react in self.reactors[event]:
+        for prio, name, react in self.reactors[event]:
             react(self.db, self, nodeid, oldvalues)
 
     #
--- a/test/db_test_base.py	Thu Nov 09 01:26:29 2006 +0000
+++ b/test/db_test_base.py	Thu Nov 09 03:08:22 2006 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: db_test_base.py,v 1.78 2006-08-30 08:50:44 schlatterbeck Exp $
+# $Id: db_test_base.py,v 1.79 2006-11-09 03:08:22 richard Exp $
 
 import unittest, os, shutil, errno, imp, sys, time, pprint, sets
 
@@ -626,6 +626,41 @@
         # invalid boolean value
         ar(TypeError, self.db.user.set, nid, assignable='true')
 
+    def testAuditors(self):
+        class test:
+            called = False
+            def call(self, *args): self.called = True
+        create = test()
+
+        self.db.user.audit('create', create.call)
+        self.db.user.create(username="mary")
+        self.assertEqual(create.called, True)
+
+        set = test()
+        self.db.user.audit('set', set.call)
+        self.db.user.set('1', username="joe")
+        self.assertEqual(set.called, True)
+
+        retire = test()
+        self.db.user.audit('retire', retire.call)
+        self.db.user.retire('1')
+        self.assertEqual(retire.called, True)
+
+    def testAuditorTwo(self):
+        class test:
+            n = 0
+            def a(self, *args): self.call_a = self.n; self.n += 1
+            def b(self, *args): self.call_b = self.n; self.n += 1
+            def c(self, *args): self.call_c = self.n; self.n += 1
+        test = test()
+        self.db.user.audit('create', test.b, 1)
+        self.db.user.audit('create', test.a, 1)
+        self.db.user.audit('create', test.c, 2)
+        self.db.user.create(username="mary")
+        self.assertEqual(test.call_a, 0)
+        self.assertEqual(test.call_b, 1)
+        self.assertEqual(test.call_c, 2)
+
     def testJournals(self):
         muid = self.db.user.create(username="mary")
         self.db.user.create(username="pete")
@@ -1406,7 +1441,6 @@
             ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'])
 
 # XXX add sorting tests for other types
-# XXX test auditors and reactors
 
     def testImportExport(self):
         # use the filtering setup to create a bunch of items

Roundup Issue Tracker: http://roundup-tracker.org/