summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-28 23:43:17 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-28 23:43:17 +0100
commitfff814d60954eacc42403e3799c030660c1ba4da (patch)
treed67d997238c9be4ae8e5ba8bfe4b8db7c013ea54
parent821e6de04a968f98363503f83705bf350a41a3bd (diff)
downloadpykolab-fff814d60954eacc42403e3799c030660c1ba4da.tar.gz
Improve proplist ordering routine
-rw-r--r--pykolab/xml/utils.py12
-rw-r--r--tests/unit/test-017-diff.py8
2 files changed, 18 insertions, 2 deletions
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index 9d80f9c..d98575e 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -318,7 +318,7 @@ def order_proplists(a, b):
# find a matching entry in base
for j, aa in enumerate(base):
- if compare_values(aa, bb):
+ if compare_values(aa, bb, True):
index = j
break
@@ -335,7 +335,7 @@ def order_proplists(a, b):
return (comp, base) if flip else (base, comp)
-def compare_values(aa, bb):
+def compare_values(aa, bb, partial=False):
ignore_keys = ['rsvp']
if not aa.__class__ == bb.__class__:
return False
@@ -348,6 +348,14 @@ def compare_values(aa, bb):
aa.pop(k, None)
bb.pop(k, None)
+ # accept partial match
+ if partial:
+ for k,v in aa.iteritems():
+ if bb.has_key(k) and bb[k] == v:
+ return True
+
+ return False
+
return aa == bb
diff --git a/tests/unit/test-017-diff.py b/tests/unit/test-017-diff.py
index 6c0a585..4b0c72c 100644
--- a/tests/unit/test-017-diff.py
+++ b/tests/unit/test-017-diff.py
@@ -170,6 +170,14 @@ class TestComputeDiff(unittest.TestCase):
self.assertEqual(aa[0], bb[0])
self.assertEqual(aa[1], bb[1])
+ def test_000_order_proplists2(self):
+ a1 = {'code': '4567', 'locality': 'Worktown', 'country': 'Switzerland', 'region': '', 'label': '', 'street': 'Workstreet 22', 'type': 'work'}
+ a2 = {'code': '55550', 'locality': 'San Francisco', 'country': 'USA', 'region': 'CA', 'label': '', 'street': 'O-steet', 'type': 'office'}
+ a3 = {'code': '6666', 'locality': 'Workcity', 'country': 'Switzerland', 'region': 'ZH', 'label': '', 'street': 'Workstreet 22', 'type': 'work'}
+ a4 = dict(a2)
+
+ (aa, bb) = order_proplists([a1, a2], [a3, a4])
+ self.assertEqual(aa[1], bb[1])
def test_001_attachments(self):
old = Todo(from_string=xml_todo_01)