[conduit: 49/138] Some simple sync tests



commit bcfd5e92c3e4d09402a89269215d6c03a28b941a
Author: John Carr <john carr unrouted co uk>
Date:   Wed Apr 29 15:49:46 2009 -0700

    Some simple sync tests
---
 test/soup/modules/__init__.py     |   16 +++++++++-------
 test/soup/test_synchronization.py |   28 +++++++++++++++++++++++-----
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/test/soup/modules/__init__.py b/test/soup/modules/__init__.py
index f665d4b..1462bcc 100644
--- a/test/soup/modules/__init__.py
+++ b/test/soup/modules/__init__.py
@@ -14,23 +14,23 @@ class ModuleWrapper(object):
     def get_num_items(self):
         count = 0
         try:
-            self.dp.module.refresh()
-            count = self.dp.module.get_num_items()
+            self.dp.refresh()
+            count = self.dp.get_num_items()
         finally:
-            self.dp.module.finish()
+            self.dp.finish()
         return count
 
     def get(self, uid):
-        return self.dp.module.get(uid)
+        return self.dp.get(uid)
 
     def add(self, obj):
-        self.dp.module.put(obj, False)
+        self.dp.put(obj, False)
 
     def update(self, uid, obj):
-        self.dp.module.put(obj, True, LUID=uid)
+        self.dp.put(obj, True, LUID=uid)
 
     def delete(self, uid):
-        self.dp.module.delete(uid)
+        self.dp.delete(uid)
 
     def apply_changes(self, uid):
         for t, uid, obj in changes:
@@ -41,6 +41,8 @@ class ModuleWrapper(object):
             elif t == CHANGE_DELETE:
                 self.delete(uid)
 
+    def get_wrapped(self):
+        return self.conduit.wrap_dataprovider(self.dp)
 
 def load_modules():
     basepath = os.path.dirname(__file__)
diff --git a/test/soup/test_synchronization.py b/test/soup/test_synchronization.py
index 2cbf731..031b21e 100644
--- a/test/soup/test_synchronization.py
+++ b/test/soup/test_synchronization.py
@@ -1,9 +1,10 @@
 import soup
 
-def make_testcase(src, snk):
+def make_testcase(src, snk, dcls):
     class TestSynchronization(soup.TestCase):
         source_klass = src
         sink_klass = snk
+        dataclass = dcls
 
         @classmethod
         def name(self):
@@ -12,13 +13,30 @@ def make_testcase(src, snk):
         def setUp(self):
             self.setUpSync()
 
+            self.data = self.dataclass()
+
             self.source = self.source_klass(self)
             self.sink = self.sink_klass(self)
+
             self.pair = self.create_conduit()
+            self.pair.add_dataprovider(self.source.get_wrapped())
+            self.pair.add_dataprovider(self.sink.get_wrapped())
+
+        def test_empty_sync(self):
+            """ test empty synchronisation """
+            self.pair.sync(block=True)
+
+        def test_add_to_source(self):
+            """ testing adding data to source """
+            for data in self.data.iter_samples():
+                self.source.add(data)
+            self.pair.sync(block=True)
 
-        def testDoNothing(self):
-            """ Test doing nothing """
-            pass
+        def test_add_to_sink(self):
+            """ test adding data to sink """
+            for data in self.data.iter_samples():
+                self.sink.add(data)
+            self.pair.sync(block=True)
 
     return TestSynchronization
 
@@ -33,7 +51,7 @@ for i in range(len(mods)):
         if sink.dataclass != source.dataclass:
             # FIXME: Need a generic way to say, hey you can sync contacts to folders
             continue
-        testklass = make_testcase(source, sink)
+        testklass = make_testcase(source, sink, sink.dataclass)
         setattr(self, testklass.name(), testklass)
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]