Skip to content

Commit 690b5e6

Browse files
author
Richard Jones
committed
fix unstable ordering of detectors [SF#1585378]
1 parent b3a7b74 commit 690b5e6

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed:
1616
- fix email change note rendering of multiline properties (sf patch 1575223)
1717
- fix sidebar search links (sf patch 1574467)
1818
- nicer "permission required" messages (sf patch 1558183)
19+
- fix unstable ordering of detectors (sf bug 1585378)
1920

2021

2122
2006-10-07 1.2.1

roundup/hyperdb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.127 2006-08-30 09:35:31 schlatterbeck Exp $
18+
# $Id: hyperdb.py,v 1.128 2006-11-09 03:08:22 richard Exp $
1919

2020
"""Hyperdatabase implementation, especially field types.
2121
"""
@@ -1196,20 +1196,20 @@ def index(self, nodeid):
11961196
#
11971197
def audit(self, event, detector, priority = 100):
11981198
"""Register an auditor detector"""
1199-
self.auditors[event].append((priority, detector))
1199+
self.auditors[event].append((priority, detector.__name__, detector))
12001200

12011201
def fireAuditors(self, event, nodeid, newvalues):
12021202
"""Fire all registered auditors"""
1203-
for prio, audit in self.auditors[event]:
1203+
for prio, name, audit in self.auditors[event]:
12041204
audit(self.db, self, nodeid, newvalues)
12051205

12061206
def react(self, event, detector, priority = 100):
12071207
"""Register a reactor detector"""
1208-
self.reactors[event].append((priority, detector))
1208+
self.reactors[event].append((priority, detector.__name__, detector))
12091209

12101210
def fireReactors(self, event, nodeid, oldvalues):
12111211
"""Fire all registered reactors"""
1212-
for prio, react in self.reactors[event]:
1212+
for prio, name, react in self.reactors[event]:
12131213
react(self.db, self, nodeid, oldvalues)
12141214

12151215
#

test/db_test_base.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.78 2006-08-30 08:50:44 schlatterbeck Exp $
18+
# $Id: db_test_base.py,v 1.79 2006-11-09 03:08:22 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint, sets
2121

@@ -626,6 +626,41 @@ def testExceptions(self):
626626
# invalid boolean value
627627
ar(TypeError, self.db.user.set, nid, assignable='true')
628628

629+
def testAuditors(self):
630+
class test:
631+
called = False
632+
def call(self, *args): self.called = True
633+
create = test()
634+
635+
self.db.user.audit('create', create.call)
636+
self.db.user.create(username="mary")
637+
self.assertEqual(create.called, True)
638+
639+
set = test()
640+
self.db.user.audit('set', set.call)
641+
self.db.user.set('1', username="joe")
642+
self.assertEqual(set.called, True)
643+
644+
retire = test()
645+
self.db.user.audit('retire', retire.call)
646+
self.db.user.retire('1')
647+
self.assertEqual(retire.called, True)
648+
649+
def testAuditorTwo(self):
650+
class test:
651+
n = 0
652+
def a(self, *args): self.call_a = self.n; self.n += 1
653+
def b(self, *args): self.call_b = self.n; self.n += 1
654+
def c(self, *args): self.call_c = self.n; self.n += 1
655+
test = test()
656+
self.db.user.audit('create', test.b, 1)
657+
self.db.user.audit('create', test.a, 1)
658+
self.db.user.audit('create', test.c, 2)
659+
self.db.user.create(username="mary")
660+
self.assertEqual(test.call_a, 0)
661+
self.assertEqual(test.call_b, 1)
662+
self.assertEqual(test.call_c, 2)
663+
629664
def testJournals(self):
630665
muid = self.db.user.create(username="mary")
631666
self.db.user.create(username="pete")
@@ -1406,7 +1441,6 @@ def testFilteringSortId(self):
14061441
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'])
14071442

14081443
# XXX add sorting tests for other types
1409-
# XXX test auditors and reactors
14101444

14111445
def testImportExport(self):
14121446
# use the filtering setup to create a bunch of items

0 commit comments

Comments
 (0)