[conduit: 30/138] Test adding data, generate test data for contacts and events, add utility functions



commit 300b2ddd80ebeb4c50539d2fda86fab18b0d7448
Author: John Carr <john carr unrouted co uk>
Date:   Tue Apr 28 01:34:56 2009 -0700

    Test adding data, generate test data for contacts and events, add utility functions
---
 test/soup/data/__init__.py     |   11 ++++++++++-
 test/soup/data/contact.py      |   17 +++++++++++++++++
 test/soup/data/event.py        |   18 ++++++++++++++++++
 test/soup/data/file.py         |    2 +-
 test/soup/data/music.py        |   10 ++++++++++
 test/soup/data/note.py         |   10 ++++++++++
 test/soup/data/photo.py        |   10 ++++++++++
 test/soup/test_dataprovider.py |    9 ++++++---
 8 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/test/soup/data/__init__.py b/test/soup/data/__init__.py
index 604a472..3f2ac98 100644
--- a/test/soup/data/__init__.py
+++ b/test/soup/data/__init__.py
@@ -1,10 +1,19 @@
-import os, sys
+import os, sys, glob
 
 class DataWrapper(object):
     """
     This class provides a wrapper around some test data.
     """
 
+    def get_data_dir(self):
+        return os.path.join(os.path.dirname(__file__),"..","..","python-tests","data")
+
+    def get_files_from_data_dir(self, glob_str):
+        """ Yields files that match the glob in the data dir """
+        files = []
+        for i in glob.glob(os.path.join(self.get_data_dir(),glob_str)):
+            yield os.path.abspath(i)
+
     def get_all(self):
         raise NotImplementedError
 
diff --git a/test/soup/data/contact.py b/test/soup/data/contact.py
new file mode 100644
index 0000000..225979e
--- /dev/null
+++ b/test/soup/data/contact.py
@@ -0,0 +1,17 @@
+import soup
+
+import conduit.utils as Utils
+from conduit.datatypes import Contact
+
+class ContactWrapper(soup.data.DataWrapper):
+
+    def iter_samples(self):
+        for f in self.get_files_from_data_dir("*.vcard"):
+            txt = open(f).read()
+            c = Contact.Contact()
+            c.set_from_vcard_string(txt)
+            c.set_UID(Utils.random_string())
+            yield c
+
+    def generate_sample(self):
+        pass
diff --git a/test/soup/data/event.py b/test/soup/data/event.py
new file mode 100644
index 0000000..a104f70
--- /dev/null
+++ b/test/soup/data/event.py
@@ -0,0 +1,18 @@
+import soup
+
+import conduit.utils as Utils
+from conduit.datatypes import Event
+
+class EventWrapper(soup.data.DataWrapper):
+
+    def iter_samples(self):
+        for f in self.get_files_from_data_dir("*.ical"):
+            txt = open(f).read()
+            e = Event.Event()
+            e.set_from_ical_string(txt)
+            e.set_UID(Utils.random_string())
+            yield e
+
+    def generate_sample(self):
+        pass
+
diff --git a/test/soup/data/file.py b/test/soup/data/file.py
index 0b6d429..12c6693 100644
--- a/test/soup/data/file.py
+++ b/test/soup/data/file.py
@@ -2,7 +2,7 @@ import soup
 import soup.data
 
 import conduit.utils as Utils
-
+from conduit.datatypes import File
 
 class FileWrapper(soup.data.DataWrapper):
     """ Provides access to sample files and generated files """
diff --git a/test/soup/data/music.py b/test/soup/data/music.py
new file mode 100644
index 0000000..61d8ab3
--- /dev/null
+++ b/test/soup/data/music.py
@@ -0,0 +1,10 @@
+import soup
+
+class MusicWrapper(soup.data.DataWrapper):
+
+    def iter_samples(self):
+        pass
+
+    def generate_sample(self):
+        pass
+
diff --git a/test/soup/data/note.py b/test/soup/data/note.py
new file mode 100644
index 0000000..155c711
--- /dev/null
+++ b/test/soup/data/note.py
@@ -0,0 +1,10 @@
+import soup
+
+class NoteWrapper(soup.data.DataWrapper):
+
+    def iter_samples(self):
+        pass
+
+    def generate_sample(self):
+        pass
+
diff --git a/test/soup/data/photo.py b/test/soup/data/photo.py
new file mode 100644
index 0000000..b46efe4
--- /dev/null
+++ b/test/soup/data/photo.py
@@ -0,0 +1,10 @@
+import soup
+
+class PhotoWrapper(soup.data.DataWrapper):
+
+    def iter_samples(self):
+        pass
+
+    def generate_sample(self):
+        pass
+
diff --git a/test/soup/test_dataprovider.py b/test/soup/test_dataprovider.py
index 1851f43..13018bf 100644
--- a/test/soup/test_dataprovider.py
+++ b/test/soup/test_dataprovider.py
@@ -12,14 +12,17 @@ def make_testcase(wrp):
             super(TestDataprovider, self).setUp()
             self.wrapper = self.wrapperclass(self)
             self.dp = self.wrapper.dp
+            self.data = self.wrapper.dataclass()
 
         def tearDown(self):
             self.dp = None
 
         def test_add(self):
             """ Should be able to add items """
-            testdata = self.wrapper.dataclass()
-            testdata.iter_samples()
+            self.dp.module.refresh()
+            for obj in self.data.iter_samples():
+                self.dp.module.put(obj, False, None)
+            self.dp.module.finish(False, False, False)
 
         def test_replace(self):
             """ Should be able to replace items """
@@ -35,7 +38,7 @@ def make_testcase(wrp):
 
         def test_finish(self):
             """ Should be able to call finish on cold """
-            self.dp.module.finish(None, None, None)
+            self.dp.module.finish(False, False, False)
 
         def test_get_num_items(self):
             """ Number of items in a fresh dataprovider should be 0 """



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