[conduit: 23/138] Move over dataprovider wrapping machinery from old soup code



commit 57ed4ac2c72b166db897baa87001ae936f91d7b0
Author: John Carr <john carr unrouted co uk>
Date:   Tue Apr 21 01:30:56 2009 -0700

    Move over dataprovider wrapping machinery from old soup code
---
 test/soup/__init__.py     |   37 +++++++++++++++++++++++++++++++++++++
 test/soup/modules/ipod.py |   14 +++++++++-----
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/test/soup/__init__.py b/test/soup/__init__.py
index 8d3f0b2..9ee7a8a 100644
--- a/test/soup/__init__.py
+++ b/test/soup/__init__.py
@@ -15,6 +15,7 @@ import conduit.MappingDB as MappingDB
 import conduit.Module as Module
 import conduit.TypeConverter as TypeConverter
 import conduit.Synchronization as Synchronization
+import conduit.ModuleWrapper as ModuleWrapper
 
 conduit.SHARED_MODULE_DIR = os.path.join(root,"conduit","modules")
 
@@ -55,6 +56,42 @@ class TestCase(unittest.TestCase):
         assert wrapper != None
         return wrapper
 
+    def get_dataprovider_factory(self, className, die=True):
+        factory = None
+        for f in self.model.dataproviderFactories:
+            if f.__class__.__name__ == className:
+                factory = f
+        assert factory != None
+        return factory
+
+    def wrap_dataprovider(self, dp):
+        wrapper = ModuleWrapper.ModuleWrapper(
+                         klass=dp.__class__,
+                         initargs=(),
+                         category=None
+                         )
+        wrapper.module = dp
+        return wrapper
+
+    def networked_dataprovider(self, dp):
+        """
+        Dirty evil cludge so we can test networked sync...
+        """
+        factory = self.get_dataprovider_factory("NetworkServerFactory")
+        server = factory.share_dataprovider(dp)
+        assert server != None
+
+        conduit = Conduit.Conduit(self.sync_manager)
+        time.sleep(1)
+
+        factory = self.get_dataprovider_factory("NetworkClientFactory")
+        newdp = factory.dataprovider_create("http://localhost";, conduit.uid, server.get_info())
+        assert newdp != None
+        return self.wrap_dataprovider( newdp() )
+
+    def create_conduit(self):
+        return Conduit.Conduit(self.sync_manager)
+
     def create_syncset(self):
         return SyncSet.SyncSet(
             moduleManager=self.modules,
diff --git a/test/soup/modules/ipod.py b/test/soup/modules/ipod.py
index 4e2831f..a149cac 100644
--- a/test/soup/modules/ipod.py
+++ b/test/soup/modules/ipod.py
@@ -14,21 +14,24 @@ class iPodNote(soup.modules.ModuleWrapper):
 
     def create_dataprovider(self):
         self.folder = create_fake_ipod()
-        return iPodModule.IPodNoteTwoWay(self.folder, "")
+        ipod = iPodModule.IPodNoteTwoWay(self.folder, "")
+        return self.conduit.wrap_dataprovider(ipod)
 
 
 class iPodContacts(soup.modules.ModuleWrapper):
 
     def create_dataprovider(self):
         self.folder = create_fake_ipod()
-        return iPodModule.IPodContactsTwoWay(self.folder, "")
+        ipod = iPodModule.IPodContactsTwoWay(self.folder, "")
+        return self.conduit.wrap_dataprovider(ipod)
 
 
 class iPodCalendar(soup.modules.ModuleWrapper):
 
     def create_dataprovider(self):
         self.folder = create_fake_ipod()
-        return iPodModule.IPodCalendarTwoWay(self.folder, "")
+        ipod = iPodModule.IPodCalendarTwoWay(self.folder, "")
+        return self.conduit.wrap_dataprovider(ipod)
 
 
 class iPodPhoto(soup.modules.ModuleWrapper):
@@ -37,12 +40,13 @@ class iPodPhoto(soup.modules.ModuleWrapper):
         self.folder = create_fake_ipod()
         photodp = iPodModule.IPodPhotoSink(self.folder, "")
         photodp._set_sysinfo("ModelNumStr", "MA450")
-        return photodp
+        return self.conduit.wrap_dataprovider(photodp)
 
 
 class iPodMusic(soup.modules.ModuleWrapper):
 
     def create_dataprovider(self):
         self.folder = create_fake_ipod()
-        return iPodModule.IPodMusicTwoWay(self.folder, "")
+        ipod = iPodModule.IPodMusicTwoWay(self.folder, "")
+        return self.conduit.wrap_dataprovider(photodp)
 



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