conduit r1231 - in trunk: . test/python-tests



Author: jstowers
Date: Wed Jan 16 11:08:27 2008
New Revision: 1231
URL: http://svn.gnome.org/viewvc/conduit?rev=1231&view=rev

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

	* test/python-tests/TestDataProviderFlickr.py:
	* test/python-tests/TestDataProviderPicasa.py:
	* test/python-tests/TestDataProviderShutterfly.py:
	* test/python-tests/TestDataProviderSmugMug.py:
	* test/python-tests/common.py: Move functions to ImageDataProvider specific 
	functions into SimpleTest.do_image_dataprovider_tests(). Connect this up to
	test the image DPs.



Modified:
   trunk/ChangeLog
   trunk/test/python-tests/TestDataProviderFlickr.py
   trunk/test/python-tests/TestDataProviderPicasa.py
   trunk/test/python-tests/TestDataProviderShutterfly.py
   trunk/test/python-tests/TestDataProviderSmugMug.py
   trunk/test/python-tests/common.py

Modified: trunk/test/python-tests/TestDataProviderFlickr.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderFlickr.py	(original)
+++ trunk/test/python-tests/TestDataProviderFlickr.py	Wed Jan 16 11:08:27 2008
@@ -2,13 +2,9 @@
 from common import *
 
 import traceback
-import gnomevfs
 
-from conduit.Module import ModuleManager
-from conduit.TypeConverter import TypeConverter
-import conduit.datatypes.Email as Email
 import conduit.datatypes.File as File
-import conduit.Utils as Utils
+import conduit.Vfs as Vfs
 
 if not is_online() or not is_interactive():
     skip()
@@ -19,7 +15,7 @@
 #setup the test
 test = SimpleTest(sinkName="FlickrTwoWay")
 config = {
-    "username":     os.environ['TEST_USERNAME'],
+    "username":     os.environ.get("TEST_USERNAME","conduitproject"),
     "photoSetName": "Conduit",
     "showPublic":   False
 }
@@ -40,19 +36,11 @@
 p = (float(used)/float(tot))*100.0
 ok("Used %2.1f%% of monthly badwidth quota (%skb/%skb)" % (p,used,tot) , used != -1 and tot != -1)
 
-#Test getting the info and URL of a photo
-info = flickr._get_photo_info(SAFE_PHOTO_ID)
-ok("Got photo info", info != None)
-url = flickr._get_raw_photo_url(info)
-ok("Got photo url (%s)" % url, url != None)
-ok("Photo url is correct", gnomevfs.exists(gnomevfs.URI(url)))
-
-#Send a remote file
-f = File.File("http://files.conduit-project.org/screenshot.png";)
-try:
-    uid = flickr.put(f, True)
-    ok("Upload a photo (UID:%s) " % uid, True)
-except Exception, err:
-    ok("Upload a photo (%s)" % err, False)
+#Perform image tests
+test.do_image_dataprovider_tests(
+        supportsGet=True,
+        supportsDelete=True,
+        safePhotoLUID=SAFE_PHOTO_ID
+        )
 
 finished()

Modified: trunk/test/python-tests/TestDataProviderPicasa.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderPicasa.py	(original)
+++ trunk/test/python-tests/TestDataProviderPicasa.py	Wed Jan 16 11:08:27 2008
@@ -2,12 +2,9 @@
 from common import *
 
 import traceback
-import gnomevfs
 
-from conduit.Module import ModuleManager
-from conduit.TypeConverter import TypeConverter
 import conduit.datatypes.File as File
-import conduit.Utils as Utils
+import conduit.Vfs as Vfs
 
 if not is_online():
     skip()
@@ -22,8 +19,8 @@
 #setup the test
 test = SimpleTest(sinkName="PicasaTwoWay")
 config = {
-    "username":     os.environ['TEST_USERNAME'],
-    "password":     os.environ['TEST_PASSWORD'],
+    "username":     os.environ.get("TEST_USERNAME","conduitproject"),
+    "password":     os.environ["TEST_PASSWORD"],
     "album"   :     SAFE_ALBUM_NAME
 }
 test.configure(sink=config)
@@ -54,28 +51,11 @@
 else:
     ok("Album has an unexpected id: %s instead of %s" % (picasa.galbum.id, SAFE_ALBUM_ID), False)
 
-# Photo tests:
-# Loaded?
-ok("Loaded photos", picasa.gphotos != None)
-
-# Expected photo available?
-ok("Expected image available", picasa.gphotos.has_key (SAFE_PHOTO_ID))
-
-# Get info
-info = picasa._get_photo_info (SAFE_PHOTO_ID)
-ok("Got photo info", info != None)
-
-# Get url
-url = picasa._get_raw_photo_url (info)
-ok ("Got photo url %s" % url, url != None)
-ok ("Photo url is correct", gnomevfs.exists (gnomevfs.URI(url)))
-
-#Send a remote file
-f = File.File("http://files.conduit-project.org/screenshot.jpg";)
-try:
-    uid = picasa.put(f, True)
-    ok("Upload a photo (UID:%s) " % uid, True)
-except Exception, err:
-    ok("Upload a photo (%s)" % err, False)
+#Perform image tests
+test.do_image_dataprovider_tests(
+        supportsGet=True,
+        supportsDelete=True,
+        safePhotoLUID=SAFE_PHOTO_ID
+        )
 
 finished()

Modified: trunk/test/python-tests/TestDataProviderShutterfly.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderShutterfly.py	(original)
+++ trunk/test/python-tests/TestDataProviderShutterfly.py	Wed Jan 16 11:08:27 2008
@@ -22,8 +22,8 @@
 #setup the test
 test = SimpleTest(sinkName="ShutterflySink")
 config = {
-    "username":     os.environ['TEST_USERNAME'],
-    "password":     os.environ['TEST_PASSWORD'],
+    "username":     os.environ.get("TEST_USERNAME","conduitproject gmail com"),
+    "password":     os.environ["TEST_PASSWORD"],
     "album"   :     SAFE_ALBUM_NAME
 }
 test.configure(sink=config)
@@ -46,24 +46,24 @@
 
 if album_id:
     ok("Got album id %s for album %s" % (album_id, SAFE_ALBUM_NAME), True)
-
     if album_id == SAFE_ALBUM_ID:
        ok("Album id %s equals the one we're expecting %s" % (album_id, SAFE_ALBUM_ID), True)
     else:
        ok("Album id %s does not equal the one we're expecting %s" % (album_id, SAFE_ALBUM_ID), False) 
 
-# Test getting photo info and url
 info = shutter._get_photo_info (SAFE_PHOTO_ID)
 ok("Got photo info", info != None)
- 
-#Send a remote file
-f = File.File("http://files.conduit-project.org/screenshot.jpg";)
-uid = None
-try:
-    uid = shutter.put(f, True)
-    ok("Upload a photo (UID:%s) " % uid, True)
-except Exception, err:
-    ok("Upload a photo (%s)" % err, False)
+
+url = shutter._get_raw_photo_url(info)
+ok("Got photo url (%s)" % url, url != None) 
+
+#Perform image tests
+test.do_image_dataprovider_tests(
+        supportsGet=False,
+        supportsDelete=True,
+        safePhotoLUID=SAFE_PHOTO_ID,
+        ext="jpg"
+        )
 
 finished()
 

Modified: trunk/test/python-tests/TestDataProviderSmugMug.py
==============================================================================
--- trunk/test/python-tests/TestDataProviderSmugMug.py	(original)
+++ trunk/test/python-tests/TestDataProviderSmugMug.py	Wed Jan 16 11:08:27 2008
@@ -2,12 +2,10 @@
 from common import *
 
 import traceback
-import gnomevfs
 
-from conduit.Module import ModuleManager
-from conduit.TypeConverter import TypeConverter
 import conduit.datatypes.File as File
 import conduit.Utils as Utils
+import conduit.Vfs as Vfs
 
 if not is_online():
     skip()
@@ -15,15 +13,15 @@
 #A Reliable album name
 SAFE_ALBUM_NAME = "Conduit Test"
 # Album id of the Conduit test album
-SAFE_ALBUM_ID = '2944161'
+SAFE_ALBUM_ID = "2944161"
 # Image id of photo in test album
-SAFE_IMAGE_ID = '158962651'
+SAFE_IMAGE_ID = "158962651"
 
 #setup the test
 test = SimpleTest(sinkName="SmugMugTwoWay")
 config = {
-    "username":     os.environ['TEST_USERNAME'],
-    "password":     os.environ['TEST_PASSWORD'],
+    "username":     os.environ.get("TEST_USERNAME","conduitproject"),
+    "password":     os.environ["TEST_PASSWORD"],
     "album"   :     SAFE_ALBUM_NAME
 }
 test.configure(sink=config)
@@ -43,7 +41,6 @@
 
 if album_id:
     ok("Got album id %s for album %s" % (album_id, SAFE_ALBUM_NAME), True)
-
     if album_id == SAFE_ALBUM_ID:
        ok("Album id %s equals the one we're expecting %s" % (album_id, SAFE_ALBUM_ID), True)
     else:
@@ -51,30 +48,11 @@
 else:
     ok("Didn't succeed in getting an album id...", False)
 
-# Test getting photo info and url
-info = smugmug._get_photo_info (SAFE_IMAGE_ID)
-ok("Got photo info", info != None)
-
-url = smugmug._get_raw_photo_url (info)
-ok ("Got photo url %s" % url, url != None)
-ok ("Photo url is correct", gnomevfs.exists (gnomevfs.URI(url)))
-   
-#Send a remote file
-f = File.File("http://files.conduit-project.org/screenshot.png";)
-uid = None
-try:
-    rid = smugmug.put(f, True)
-    uid = rid.get_UID()
-    ok("Upload a photo (UID:%s) " % uid, True)
-except Exception, err:
-    ok("Upload a photo (%s)" % err, False)
-
-# try delete if upload succeeded
-if uid:
-    try:
-        smugmug.delete(uid)
-        ok("Delete succeeded", True)
-    except Exception, err:
-        ok("Delete failed %s" % err, False)
+#Perform image tests
+test.do_image_dataprovider_tests(
+        supportsGet=True,
+        supportsDelete=True,
+        safePhotoLUID=SAFE_IMAGE_ID
+        )
 
 finished()

Modified: trunk/test/python-tests/common.py
==============================================================================
--- trunk/test/python-tests/common.py	(original)
+++ trunk/test/python-tests/common.py	Wed Jan 16 11:08:27 2008
@@ -4,6 +4,7 @@
 import glob
 import time
 import datetime
+import traceback
 
 # make sure we have conduit folder in path!
 my_path = os.path.dirname(__file__)
@@ -14,6 +15,7 @@
 import conduit
 import conduit.Logging as Logging
 import conduit.Utils as Utils
+import conduit.Vfs as Vfs
 import conduit.Module as Module
 import conduit.TypeConverter as TypeConverter
 import conduit.Synchronization as Synchronization
@@ -327,7 +329,55 @@
 
     def print_mapping_db(self):
         print conduit.GLOBALS.mappingDB.debug()
+        
+    def do_image_dataprovider_tests(self, supportsGet, supportsDelete, safePhotoLUID, ext="png"):
+        """
+        Tests get(), put(), delete() and Image dataprovider specific
+        functions
+        """
+        #Test get() and image specific friends
+        if supportsGet:
+            try:
+                info = self.sink.module._get_photo_info(safePhotoLUID)
+                ok("Got photo info", info != None)
+                url = self.sink.module._get_raw_photo_url(info)
+                ok("Got photo url (%s)" % url, url != None)
+                ok("Photo url is correct", Vfs.uri_exists(url))
+                f = self.sink.module.get(safePhotoLUID)
+                ok ("Got photo %s" % url, f.exists())
+            except Exception, err:
+                traceback.print_exc()
+                ok("Got photo (%s)" % err, False)
+
+        #Test put()
+        f = File.File("http://files.conduit-project.org/screenshot.%s"; % ext)
+        try:
+            rid = self.sink.module.put(f, True)
+            uid = rid.get_UID()
+            ok("Upload a photo (%s) " % rid, True)
+        except Exception, err:
+            traceback.print_exc()        
+            ok("Upload a photo (%s)" % err, False)
+
+        #Test put() to replace a photo
+        try:
+            rid = self.sink.module.put(f, True, uid)
+            ok("Update a photo (%s)" % rid, True)
+        except Exception, err:
+            traceback.print_exc()
+            ok("Update a photo (%s)" % err, False)
 
+        #Test delete()
+        if supportsDelete:
+            try:
+                self.sink.module.refresh()
+                self.sink.module.delete(uid)
+                self.sink.module.refresh()
+                ok("Delete a photo (%s)" % rid, uid not in self.sink.module.get_all())
+            except Exception, err:
+                traceback.print_exc()
+                ok("Delete a photo (%s)" % err, False)
+        
 class SimpleSyncTest(SimpleTest):
     """
     Helper class to make setting up test-pairs as easy as possible



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