conduit r1255 - in trunk: . conduit/modules test/python-tests test/python-tests/data/resources-ipod test/python-tests/data/resources-ipod/Artwork test/python-tests/data/resources-ipod/iTunes



Author: jstowers
Date: Sun Jan 20 09:40:01 2008
New Revision: 1255
URL: http://svn.gnome.org/viewvc/conduit?rev=1255&view=rev

Log:
2008-01-20  John Stowers  <john stowers gmail com>

	* conduit/modules/iPodModule.py:
	* test/python-tests/TestDataProvideriPod.py:
	* test/python-tests/common.py:
	* test/python-tests/data/resources-ipod/iTunes/iTunesDB.ext: Fix ipod photos
	test (borrowed example test setup code from libgpod). Use the sample test
	functions for the ipod tests



Added:
   trunk/test/python-tests/data/resources-ipod/
   trunk/test/python-tests/data/resources-ipod/Artwork/
   trunk/test/python-tests/data/resources-ipod/Artwork/ArtworkDB   (contents, props changed)
   trunk/test/python-tests/data/resources-ipod/iTunes/
   trunk/test/python-tests/data/resources-ipod/iTunes/iTunesDB   (contents, props changed)
   trunk/test/python-tests/data/resources-ipod/iTunes/iTunesDB.ext
   trunk/test/python-tests/data/resources-ipod/tiny.mp3   (contents, props changed)
   trunk/test/python-tests/data/resources-ipod/tiny.png   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/conduit/modules/iPodModule.py
   trunk/test/python-tests/TestDataProvideriPod.py
   trunk/test/python-tests/common.py

Modified: trunk/conduit/modules/iPodModule.py
==============================================================================
--- trunk/conduit/modules/iPodModule.py	(original)
+++ trunk/conduit/modules/iPodModule.py	Sun Jan 20 09:40:01 2008
@@ -323,6 +323,9 @@
         self.albumName = "Conduit"
         self.album = None
         
+    def _set_sysinfo(self, modelnumstr, model):
+        gpod.itdb_device_set_sysinfo(self.db._itdb.device, modelnumstr, model)
+        
     def _get_photo_album(self):
         for album in self.db.PhotoAlbums:
             if album.name == self.albumName:
@@ -352,10 +355,11 @@
                 log.debug("Creating album %s" % self.albumName)
                 self.album = self.db.new_PhotoAlbum(title=self.albumName)
 
-#        self.uids = []
-#        for photo in self.db.PhotoAlbums[0]:
-#            self.uids.append(str(photo['id']))
-
+    def get_all(self):
+        uids = []
+        for photo in self._get_photo_album():
+            uids.append(str(photo['id']))
+        return uids
 
     def put(self, f, overwrite, LUID=None):
         photo = self.db.new_Photo(filename=f.get_local_uri())

Modified: trunk/test/python-tests/TestDataProvideriPod.py
==============================================================================
--- trunk/test/python-tests/TestDataProvideriPod.py	(original)
+++ trunk/test/python-tests/TestDataProvideriPod.py	Sun Jan 20 09:40:01 2008
@@ -1,14 +1,16 @@
 #common sets up the conduit environment
 from common import *
 
+import os.path
+import shutil
 import traceback
 
 import conduit.modules.iPodModule as iPodModule
+import conduit.Utils as Utils
+
 
 #simulate an ipod
-fakeIpodDir = os.path.join(os.environ['TEST_DIRECTORY'],"iPod")
-if not os.path.exists(fakeIpodDir):
-    os.mkdir(fakeIpodDir)
+fakeIpodDir = Utils.new_tempdir()
 ok("Created fake ipod at %s" % fakeIpodDir, os.path.exists(fakeIpodDir))
 
 ipodNoteDp = iPodModule.IPodNoteTwoWay(fakeIpodDir,"")
@@ -16,50 +18,39 @@
 ipodCalendarDp = iPodModule.IPodCalendarTwoWay(fakeIpodDir,"")
 ipodPhotoDp = iPodModule.IPodPhotoSink(fakeIpodDir,"")
 
+#The ipod photo (and music AFAICT) require some initialization of 
+#a skeleton database file. 
+#This code, and example resources are taken from libgpod test suite
+control_dir = os.path.join(fakeIpodDir,'iPod_Control')
+photo_dir = os.path.join(control_dir, 'Photos')
+shutil.copytree(
+            os.path.join(get_data_dir(),'resources-ipod'),
+            control_dir
+            )
+os.mkdir(photo_dir)
+ipodPhotoDp._set_sysinfo("ModelNumStr", "MA450")
+
 TESTS = (
-#dpinstance,        #newdata_func,          #name
-(ipodNoteDp,        new_note,               "IPodNoteTwoWay"),
-(ipodContactsDp,    new_contact,            "IPodContactsTwoWay"),
-(ipodCalendarDp,    new_event,              "IPodCalendarTwoWay"),
-(ipodPhotoDp,       new_photo,              "IPodPhotoSink"),
+#dpinstance,        #newdata_func,          #name                   #twoway
+(ipodNoteDp,        new_note,               "IPodNoteTwoWay",       True),
+(ipodContactsDp,    new_contact,            "IPodContactsTwoWay",   True),
+(ipodCalendarDp,    new_event,              "IPodCalendarTwoWay",   True),
+(ipodPhotoDp,       new_photo,              "IPodPhotoSink",        False),
 )
 
-for dp, newdata_func, name in TESTS:
-    try:
-        dp.refresh()
-        ok("%s: Refresh" % name, True)
-    except Exception, err:
-        ok("%s: Refresh (%s)" % (name,err), False) 
-
-    #Make data and put it
+for dp, newdata_func, name, istwoway in TESTS:
+    test = SimpleTest()
+    test.set_sink(
+            test.wrap_dataprovider(dp)
+            )
+    
     newdata = newdata_func(None)
-    newtitle = newdata.get_UID()
-        
-    try:
-        rid = dp.put(newdata,False)
-        ok("%s: Put %s" % (name, newtitle), rid.get_UID() != None)
-    except Exception, err:
-        traceback.print_exc()
-        ok("%s: Put %s" % (name, err), False)
-
-    #Check that we saved the note back
-    dp.refresh()
-    ok("%s: Got all" % name, rid.get_UID() in dp.get_all())
-
-    data = dp.get(rid.get_UID())
-    comp = data.compare(newdata)
-    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
-
-    #check we overwrite the data ok
-    try:
-        newrid = dp.put(newdata,True,rid.get_UID())
-        ok("%s: Overwrite %s" % (name, newtitle), newrid.get_UID() == rid.get_UID())
-    except Exception, err:
-        ok("%s: Overwrite %s" % (name, err), False)
-
-    #Check that we saved the data back
-    newdata = dp.get(newrid.get_UID())
-    comp = data.compare(newdata)
-    ok("%s: Got back idenitcal. Comparison %s" % (name, comp), comp == conduit.datatypes.COMPARISON_EQUAL, False)
+    test.do_dataprovider_tests(
+        supportsGet=istwoway,
+        supportsDelete=True,
+        safeLUID=None,
+        data=newdata,
+        name="%s:%s" % (name,dp._in_type_)
+        )
 
 finished()

Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py	(original)
+++ trunk/test/python-tests/common.py	Sun Jan 20 09:40:01 2008
@@ -353,9 +353,15 @@
 
     def get_source(self):
         return self.source
+        
+    def set_source(self, source):
+        self.source = source
 
     def get_sink(self):
         return self.sink
+        
+    def set_sink(self, sink):
+        self.sink = sink
 
     def print_mapping_db(self):
         print conduit.GLOBALS.mappingDB.debug()
@@ -370,10 +376,10 @@
         try:
             rid = self.sink.module.put(data, True)
             uid = rid.get_UID()
-            ok("Upload a %s (%s) " % (name,rid), True)
+            ok("Put a %s (%s) " % (name,rid), True)
         except Exception, err:
             traceback.print_exc()        
-            ok("Upload a %s (%s)" % (name,err), False)
+            ok("Put a %s (%s)" % (name,err), False)
             
         #Test get()
         if supportsGet:
@@ -388,18 +394,18 @@
             try:
                 self.sink.module.refresh()
                 f = self.sink.module.get(LUID)
-                ok("Got %s %s" % (desc,LUID), f != None)
+                ok("Get %s %s" % (desc,LUID), f != None)
             except Exception, err:
                 traceback.print_exc()
-                ok("Got %s (%s)" % (desc,err), False)
+                ok("Get %s (%s)" % (desc,err), False)
 
         #Test put() to replace
         try:
             rid = self.sink.module.put(data, True, uid)
-            ok("Update a %s (%s)" % (name,rid), True)
+            ok("Update %s (%s)" % (name,rid), True)
         except Exception, err:
             traceback.print_exc()
-            ok("Update a %s (%s)" % (name,err), False)
+            ok("Update %s (%s)" % (name,err), False)
 
         #Test delete()
         if supportsDelete:
@@ -407,10 +413,10 @@
                 self.sink.module.refresh()
                 self.sink.module.delete(uid)
                 self.sink.module.refresh()
-                ok("Delete a %s (%s)" % (name,rid), uid not in self.sink.module.get_all())
+                ok("Delete %s (%s)" % (name,rid), uid not in self.sink.module.get_all())
             except Exception, err:
                 traceback.print_exc()
-                ok("Delete a %s (%s)" % (name,err), False)
+                ok("Delete %s (%s)" % (name,err), False)
 
     def do_image_dataprovider_tests(self, supportsGet, supportsDelete, safePhotoLUID, ext="png"):
         """

Added: trunk/test/python-tests/data/resources-ipod/Artwork/ArtworkDB
==============================================================================
Binary file. No diff available.

Added: trunk/test/python-tests/data/resources-ipod/iTunes/iTunesDB
==============================================================================
Binary file. No diff available.

Added: trunk/test/python-tests/data/resources-ipod/iTunes/iTunesDB.ext
==============================================================================
--- (empty file)
+++ trunk/test/python-tests/data/resources-ipod/iTunes/iTunesDB.ext	Sun Jan 20 09:40:01 2008
@@ -0,0 +1,3 @@
+itunesdb_hash=1d28bd4e9ec0980d34f36f9d39cdafd163e5cd36
+version=0.99.6DEV
+id=xxx

Added: trunk/test/python-tests/data/resources-ipod/tiny.mp3
==============================================================================
Binary file. No diff available.

Added: trunk/test/python-tests/data/resources-ipod/tiny.png
==============================================================================
Binary file. No diff available.



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